1 /*******************************************************************************
2 * Copyright (c) 2009 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Francois Chouinard (fchouinard@gmail.com) - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.eventlog
;
15 import java
.io
.IOException
;
16 import java
.util
.Vector
;
18 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEvent
;
19 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimeRange
;
20 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimestamp
;
23 * <b><u>TmfEventLog</u></b>
25 * TmfEventLog represents a time-ordered set of events tied to a single event
26 * stream. It keeps track of the global information about the event log:
28 * <li> the epoch, a reference timestamp for the whole log (t0)
29 * <li> the span of the log i.e. the timestamps range
30 * <li> the total number of events
32 * As an ITmfRequestHandler, it provides an implementation of process()
33 * which handles event requests.
35 * TODO: Handle concurrent and possibly overlapping requests in a way that
36 * optimizes the stream access and event parsing.
38 public class TmfTrace
implements ITmfRequestHandler
{
40 // ========================================================================
42 // ========================================================================
44 private final String fId
;
45 private final TmfEventStream fStream
;
46 private final TmfTimestamp fEpoch
;
48 // ========================================================================
50 // ========================================================================
52 public TmfTrace(String id
, TmfEventStream stream
) {
53 assert stream
!= null;
56 fEpoch
= TmfTimestamp
.BigBang
;
59 public TmfTrace(String id
, TmfEventStream stream
, TmfTimestamp epoch
) {
60 assert stream
!= null;
66 // ========================================================================
68 // ========================================================================
70 public String
getId() {
74 public TmfEventStream
getStream() {
78 public TmfTimestamp
getEpoch() {
82 public TmfTimeRange
getTimeRange() {
83 return fStream
.getTimeRange();
86 public int getNbEvents() {
87 return fStream
.getNbEvents();
90 // ========================================================================
92 // ========================================================================
95 * @see org.eclipse.linuxtools.tmf.eventlog.ITmfRequestExecutor#execute(org.eclipse.linuxtools.tmf.eventlog.TmfEventRequest, boolean)
97 public void process(final TmfEventRequest request
, boolean waitForCompletion
) {
98 serviceEventRequest(request
);
99 if (waitForCompletion
) {
100 request
.waitForCompletion();
104 // ========================================================================
106 // ========================================================================
112 private void serviceEventRequest(final TmfEventRequest request
) {
113 Thread thread
= new Thread() {
116 TmfTimestamp startTime
= request
.getRange().getStartTime();
117 TmfTimestamp endTime
= request
.getRange().getEndTime();
118 int blockSize
= request
.getBlockize();
120 int nbRequestedEvents
= request
.getNbRequestedEvents();
121 if (nbRequestedEvents
== -1) {
122 nbRequestedEvents
= Integer
.MAX_VALUE
;
125 Vector
<TmfEvent
> events
= new Vector
<TmfEvent
>();
128 TmfEvent event
= fStream
.seek(startTime
);
129 while (!request
.isCancelled() && nbEvents
< nbRequestedEvents
&& event
!= null &&
130 event
.getTimestamp().compareTo(endTime
, false) <= 0 )
133 if (++nbEvents
% blockSize
== 0) {
134 request
.newEvents(events
);
135 events
.removeAllElements();
137 event
= fStream
.getNextEvent();
139 request
.newEvents(events
);
141 } catch (IOException e
) {
142 // TODO Auto-generated catch block
This page took 0.03418 seconds and 5 git commands to generate.