1 /*******************************************************************************
2 * Copyright (c) 2010, 2014 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 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.ui
.views
.timechart
;
15 import java
.util
.ArrayList
;
16 import java
.util
.Iterator
;
18 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
19 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.colors
.ColorSettingsManager
;
20 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
21 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
22 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.TimeEvent
;
25 * Event in the time chart view
28 * @author Patrick Tasse
30 public class TimeChartEvent
implements ITimeEvent
{
32 private static final byte TIMESTAMP_SCALE
= -9;
34 private final TimeChartAnalysisEntry fParentEntry
;
36 private long fDuration
;
37 private long fFirstRank
;
38 private long fLastRank
;
39 private final RankRangeList fRankRangeList
;
40 private long fNbEvents
;
41 private int fColorSettingPriority
;
42 private boolean fIsBookmark
;
43 private boolean fIsVisible
;
44 private boolean fIsSearchMatch
;
45 private TimeChartAnalysisEntry fItemizedEntry
;
46 private boolean fItemizing
;
49 * Standard constructor
54 * The event from which this time chart event originates
56 * The rank of the event in the trace
57 * @param decorationProvider
58 * The decoration provider to use
60 public TimeChartEvent(TimeChartAnalysisEntry parentEntry
, ITmfEvent event
,
61 long rank
, TimeChartDecorationProvider decorationProvider
) {
62 fParentEntry
= parentEntry
;
63 fTime
= event
.getTimestamp().normalize(0, TIMESTAMP_SCALE
).getValue();
65 fFirstRank
= fLastRank
= rank
;
66 fRankRangeList
= new RankRangeList(rank
);
68 fColorSettingPriority
= ColorSettingsManager
.getColorSettingPriority(event
);
69 fIsBookmark
= decorationProvider
.isBookmark(rank
);
70 fIsVisible
= decorationProvider
.isVisible(event
);
71 fIsSearchMatch
= decorationProvider
.isSearchMatch(event
);
75 public ITimeGraphEntry
getEntry() {
80 public long getTime() {
85 public long getDuration() {
90 public ITimeEvent
splitBefore(long splitTime
) {
91 return (splitTime
> fTime ?
92 new TimeEvent(getEntry(), fTime
, Math
.min(fDuration
, splitTime
- fTime
)) :
97 public ITimeEvent
splitAfter(long splitTime
) {
98 return (splitTime
< fTime
+ fDuration ?
99 new TimeEvent(getEntry(), Math
.max(fTime
, splitTime
), fDuration
- Math
.max(0, splitTime
- fTime
)) :
104 * Retrieve the rank of the trace event which started this time event.
106 * @return The rank of the beginning
108 public long getFirstRank() {
113 * Retrieve the rank of the trace event which *finished* this time event.
115 * @return The rank of the end
117 public long getLastRank() {
122 * Get the list of rank ranges corresponding to this time event.
124 * @return The rank range list
126 public RankRangeList
getRankRangeList() {
127 return fRankRangeList
;
131 * Merge another time event with this one.
136 public void merge(TimeChartEvent event
) {
137 mergeDecorations(event
);
138 if (fTime
== event
.getTime() && fDuration
== event
.getDuration()) {
141 long endTime
= Math
.max(fTime
+ fDuration
, event
.getTime() + event
.getDuration());
142 fTime
= Math
.min(fTime
, event
.getTime());
143 fDuration
= endTime
- fTime
;
144 fFirstRank
= Math
.min(fFirstRank
, event
.fFirstRank
);
145 fLastRank
= Math
.max(fLastRank
, event
.fLastRank
);
146 fNbEvents
+= event
.fNbEvents
;
147 fItemizedEntry
= null;
148 synchronized (fRankRangeList
) {
149 fRankRangeList
.merge(event
.getRankRangeList());
154 * Merge the decorations of another time event with the decorations of this
160 public void mergeDecorations(TimeChartEvent event
) {
161 fColorSettingPriority
= Math
.min(fColorSettingPriority
, event
.getColorSettingPriority());
162 fIsBookmark
|= event
.fIsBookmark
;
163 fIsVisible
|= event
.fIsVisible
;
164 fIsSearchMatch
|= event
.fIsSearchMatch
;
168 * Get the number of time events that have been merged with this one (starts
169 * counting at 1 if no merge happened).
171 * @return The current number of events in the bath
173 public long getNbEvents() {
178 * Retrieve the color setting priority.
180 * @return The priority
182 public int getColorSettingPriority() {
183 return fColorSettingPriority
;
187 * Set the color setting priority.
190 * The priority to set
192 public void setColorSettingPriority(int priority
) {
193 fColorSettingPriority
= priority
;
197 * Check if this time event is bookmarked
201 public boolean isBookmarked() {
206 * Set this time event to be bookmarked or not.
208 * @param isBookmarked
209 * Should time time event become a bookmark, or not
211 public void setIsBookmarked(boolean isBookmarked
) {
212 fIsBookmark
= isBookmarked
;
216 * Check if this time is currently visible or not.
218 * @return If the event is visible
220 public boolean isVisible() {
225 * Set this time event to visible (or to non-visible).
227 * @param isVisible The new status
229 public void setIsVisible(boolean isVisible
) {
230 fIsVisible
= isVisible
;
234 * Check if the time event matches the current search.
236 * @return If it matches, Y/N
238 public boolean isSearchMatch() {
239 return fIsSearchMatch
;
243 * Mark this event as matching (or non-matching) the current search.
245 * @param isSearchMatch
246 * The new matching status
248 public void setIsSearchMatch(boolean isSearchMatch
) {
249 fIsSearchMatch
= isSearchMatch
;
253 * Set this event's itemized entry.
255 * @param timeAnalysisEntry
258 public void setItemizedEntry(TimeChartAnalysisEntry timeAnalysisEntry
) {
259 fItemizedEntry
= timeAnalysisEntry
;
263 * Retrieve this event's itemized entry.
265 * @return The itemized entry that was previously set
267 public TimeChartAnalysisEntry
getItemizedEntry() {
268 return fItemizedEntry
;
272 * @return Has this time event been set to itemizing?
274 public boolean isItemizing() {
279 * Set this event's itemizing flag to true or false.
284 public void setItemizing(boolean itemizing
) {
285 fItemizing
= itemizing
;
289 * Inner class to define a range in terms of ranks in the trace.
292 * @author Patrick Tasse
294 public class RankRange
{
295 private long firstRank
;
296 private long lastRank
;
299 * Standard constructor
302 * The first (earliest) rank of the range
304 * The last (latest) rank of the range
306 public RankRange(long firstRank
, long lastRank
) {
307 this.firstRank
= firstRank
;
308 this.lastRank
= lastRank
;
312 * Retrieve the start rank of this range.
314 * @return The first rank
316 public long getFirstRank() {
321 * Retrieve the end rank of this range
323 * @return The end rank
325 public long getLastRank() {
330 * Calculate the minimal distance between two RankRange's
334 * @return The distance, in "number of events" between the two ranges
336 public long distanceFrom(RankRange range
) {
337 if (range
.lastRank
< fFirstRank
) {
338 return fFirstRank
- range
.lastRank
;
339 } else if (range
.firstRank
> fLastRank
) {
340 return range
.firstRank
- fLastRank
;
347 public String
toString() {
348 return "["+firstRank
+","+lastRank
+"]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
352 private class RankRangeList
extends ArrayList
<RankRange
> {
354 private static final long serialVersionUID
= 6060485531208535986L;
356 public RankRangeList(long rank
) {
358 add(new RankRange(rank
, rank
));
361 public void merge(RankRangeList rankRangeList
) {
362 long threshold
= fParentEntry
.getTrace().getCacheSize();
363 for (RankRange newRange
: rankRangeList
) {
364 boolean merged
= false;
365 for (RankRange oldRange
: fRankRangeList
) {
366 if (newRange
.distanceFrom(oldRange
) <= threshold
) {
367 oldRange
.firstRank
= Math
.min(oldRange
.firstRank
, newRange
.firstRank
);
368 oldRange
.lastRank
= Math
.max(oldRange
.lastRank
, newRange
.lastRank
);
377 Iterator
<RankRange
> iterator
= fRankRangeList
.iterator();
378 RankRange previous
= null;
379 while (iterator
.hasNext()) {
380 RankRange range
= iterator
.next();
381 if (previous
!= null && range
.distanceFrom(previous
) <= threshold
) {
382 previous
.firstRank
= Math
.min(previous
.firstRank
, range
.firstRank
);
383 previous
.lastRank
= Math
.max(previous
.lastRank
, range
.lastRank
);