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
;
237 public void setItemizedEntry(TimeChartAnalysisEntry timeAnalysisEntry
) {
238 fItemizedEntry
= timeAnalysisEntry
;
241 public TimeChartAnalysisEntry
getItemizedEntry() {
242 return fItemizedEntry
;
245 public boolean isItemizing() {
249 public void setItemizing(boolean itemizing
) {
250 fItemizing
= itemizing
;
253 public class RankRange
{
254 private long firstRank
;
255 private long lastRank
;
257 public RankRange(long firstRank
, long lastRank
) {
258 this.firstRank
= firstRank
;
259 this.lastRank
= lastRank
;
262 public long getFirstRank() {
266 public long getLastRank() {
270 public long distanceFrom(RankRange range
) {
271 if (range
.lastRank
< fFirstRank
) {
272 return fFirstRank
- range
.lastRank
;
273 } else if (range
.firstRank
> fLastRank
) {
274 return range
.firstRank
- fLastRank
;
281 public String
toString() {
282 return "["+firstRank
+","+lastRank
+"]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
286 private class RankRangeList
extends ArrayList
<RankRange
> {
288 private static final long serialVersionUID
= 6060485531208535986L;
290 public RankRangeList(long rank
) {
292 add(new RankRange(rank
, rank
));
295 public void merge(RankRangeList rankRangeList
) {
296 long threshold
= fParentEntry
.getTrace().getCacheSize();
297 for (RankRange newRange
: rankRangeList
) {
298 boolean merged
= false;
299 for (RankRange oldRange
: fRankRangeList
) {
300 if (newRange
.distanceFrom(oldRange
) <= threshold
) {
301 oldRange
.firstRank
= Math
.min(oldRange
.firstRank
, newRange
.firstRank
);
302 oldRange
.lastRank
= Math
.max(oldRange
.lastRank
, newRange
.lastRank
);
311 Iterator
<RankRange
> iterator
= fRankRangeList
.iterator();
312 RankRange previous
= null;
313 while (iterator
.hasNext()) {
314 RankRange range
= iterator
.next();
315 if (previous
!= null && range
.distanceFrom(previous
) <= threshold
) {
316 previous
.firstRank
= Math
.min(previous
.firstRank
, range
.firstRank
);
317 previous
.lastRank
= Math
.max(previous
.lastRank
, range
.lastRank
);