1 /*******************************************************************************
2 * Copyright (c) 2010 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
.linuxtools
.tmf
.ui
.views
.timechart
;
15 import java
.util
.ArrayList
;
16 import java
.util
.Iterator
;
18 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
19 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.colors
.ColorSettingsManager
;
20 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
21 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
24 * Event in the time chart view
27 * @author Patrick Tasse
29 public class TimeChartEvent
implements ITimeEvent
{
31 private static final byte TIMESTAMP_SCALE
= -9;
33 private final TimeChartAnalysisEntry fParentEntry
;
35 private long fDuration
;
36 private long fFirstRank
;
37 private long fLastRank
;
38 private final RankRangeList fRankRangeList
;
39 private long fNbEvents
;
40 private int fColorSettingPriority
;
41 private boolean fIsBookmark
;
42 private boolean fIsVisible
;
43 private boolean fIsSearchMatch
;
44 private TimeChartAnalysisEntry fItemizedEntry
;
45 private boolean fItemizing
;
48 * Standard constructor
53 * The event from which this time chart event originates
55 * The rank of the event in the trace
56 * @param decorationProvider
57 * The decoration provider to use
59 public TimeChartEvent(TimeChartAnalysisEntry parentEntry
, ITmfEvent event
,
60 long rank
, TimeChartDecorationProvider decorationProvider
) {
61 fParentEntry
= parentEntry
;
62 fTime
= event
.getTimestamp().normalize(0, TIMESTAMP_SCALE
).getValue();
64 fFirstRank
= fLastRank
= rank
;
65 fRankRangeList
= new RankRangeList(rank
);
67 fColorSettingPriority
= ColorSettingsManager
.getColorSettingPriority(event
);
68 fIsBookmark
= decorationProvider
.isBookmark(rank
);
69 fIsVisible
= decorationProvider
.isVisible(event
);
70 fIsSearchMatch
= decorationProvider
.isSearchMatch(event
);
74 public ITimeGraphEntry
getEntry() {
79 public long getTime() {
84 public long getDuration() {
89 * Retrieve the rank of the trace event which started this time event.
91 * @return The rank of the beginning
93 public long getFirstRank() {
98 * Retrieve the rank of the trace event which *finished* this time event.
100 * @return The rank of the end
102 public long getLastRank() {
107 * Get the list of rank ranges corresponding to this time event.
109 * @return The rank range list
111 public RankRangeList
getRankRangeList() {
112 return fRankRangeList
;
116 * Merge another time event with this one.
121 public void merge(TimeChartEvent event
) {
122 mergeDecorations(event
);
123 if (fTime
== event
.getTime() && fDuration
== event
.getDuration()) {
126 long endTime
= Math
.max(fTime
+ fDuration
, event
.getTime() + event
.getDuration());
127 fTime
= Math
.min(fTime
, event
.getTime());
128 fDuration
= endTime
- fTime
;
129 fFirstRank
= Math
.min(fFirstRank
, event
.fFirstRank
);
130 fLastRank
= Math
.max(fLastRank
, event
.fLastRank
);
131 fNbEvents
+= event
.fNbEvents
;
132 fItemizedEntry
= null;
133 synchronized (fRankRangeList
) {
134 fRankRangeList
.merge(event
.getRankRangeList());
139 * Merge the decorations of another time event with the decorations of this
145 public void mergeDecorations(TimeChartEvent event
) {
146 fColorSettingPriority
= Math
.min(fColorSettingPriority
, event
.getColorSettingPriority());
147 fIsBookmark
|= event
.fIsBookmark
;
148 fIsVisible
|= event
.fIsVisible
;
149 fIsSearchMatch
|= event
.fIsSearchMatch
;
153 * Get the number of time events that have been merged with this one (starts
154 * counting at 1 if no merge happened).
156 * @return The current number of events in the bath
158 public long getNbEvents() {
163 * Retrieve the color setting priority.
165 * @return The priority
167 public int getColorSettingPriority() {
168 return fColorSettingPriority
;
172 * Set the color setting priority.
175 * The priority to set
177 public void setColorSettingPriority(int priority
) {
178 fColorSettingPriority
= priority
;
182 * Check if this time event is bookmarked
186 public boolean isBookmarked() {
191 * Set this time event to be bookmarked or not.
193 * @param isBookmarked
194 * Should time time event become a bookmark, or not
196 public void setIsBookmarked(boolean isBookmarked
) {
197 fIsBookmark
= isBookmarked
;
201 * Check if this time is currently visible or not.
203 * @return If the event is visible
205 public boolean isVisible() {
210 * Set this time event to visible (or to non-visible).
212 * @param isVisible The new status
214 public void setIsVisible(boolean isVisible
) {
215 fIsVisible
= isVisible
;
219 * Check if the time event matches the current search.
221 * @return If it matches, Y/N
223 public boolean isSearchMatch() {
224 return fIsSearchMatch
;
228 * Mark this event as matching (or non-matching) the current search.
230 * @param isSearchMatch
231 * The new matching status
233 public void setIsSearchMatch(boolean isSearchMatch
) {
234 fIsSearchMatch
= isSearchMatch
;
238 * Set this event's itemized entry.
240 * @param timeAnalysisEntry
243 public void setItemizedEntry(TimeChartAnalysisEntry timeAnalysisEntry
) {
244 fItemizedEntry
= timeAnalysisEntry
;
248 * Retrieve this event's itemized entry.
250 * @return The itemized entry that was previously set
252 public TimeChartAnalysisEntry
getItemizedEntry() {
253 return fItemizedEntry
;
257 * @return Has this time event been set to itemizing?
259 public boolean isItemizing() {
264 * Set this event's itemizing flag to true or false.
269 public void setItemizing(boolean itemizing
) {
270 fItemizing
= itemizing
;
274 * Inner class to define a range in terms of ranks in the trace.
277 * @author Patrick Tasse
279 public class RankRange
{
280 private long firstRank
;
281 private long lastRank
;
284 * Standard constructor
287 * The first (earliest) rank of the range
289 * The last (latest) rank of the range
291 public RankRange(long firstRank
, long lastRank
) {
292 this.firstRank
= firstRank
;
293 this.lastRank
= lastRank
;
297 * Retrieve the start rank of this range.
299 * @return The first rank
301 public long getFirstRank() {
306 * Retrieve the end rank of this range
308 * @return The end rank
310 public long getLastRank() {
315 * Calculate the minimal distance between two RankRange's
319 * @return The distance, in "number of events" between the two ranges
321 public long distanceFrom(RankRange range
) {
322 if (range
.lastRank
< fFirstRank
) {
323 return fFirstRank
- range
.lastRank
;
324 } else if (range
.firstRank
> fLastRank
) {
325 return range
.firstRank
- fLastRank
;
332 public String
toString() {
333 return "["+firstRank
+","+lastRank
+"]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
337 private class RankRangeList
extends ArrayList
<RankRange
> {
339 private static final long serialVersionUID
= 6060485531208535986L;
341 public RankRangeList(long rank
) {
343 add(new RankRange(rank
, rank
));
346 public void merge(RankRangeList rankRangeList
) {
347 long threshold
= fParentEntry
.getTrace().getCacheSize();
348 for (RankRange newRange
: rankRangeList
) {
349 boolean merged
= false;
350 for (RankRange oldRange
: fRankRangeList
) {
351 if (newRange
.distanceFrom(oldRange
) <= threshold
) {
352 oldRange
.firstRank
= Math
.min(oldRange
.firstRank
, newRange
.firstRank
);
353 oldRange
.lastRank
= Math
.max(oldRange
.lastRank
, newRange
.lastRank
);
362 Iterator
<RankRange
> iterator
= fRankRangeList
.iterator();
363 RankRange previous
= null;
364 while (iterator
.hasNext()) {
365 RankRange range
= iterator
.next();
366 if (previous
!= null && range
.distanceFrom(previous
) <= threshold
) {
367 previous
.firstRank
= Math
.min(previous
.firstRank
, range
.firstRank
);
368 previous
.lastRank
= Math
.max(previous
.lastRank
, range
.lastRank
);