Commit | Line | Data |
---|---|---|
ce62370f FC |
1 | /*******************************************************************************\r |
2 | * Copyright (c) 2010 Ericsson\r | |
013a5f1c | 3 | *\r |
ce62370f FC |
4 | * All rights reserved. This program and the accompanying materials are\r |
5 | * made available under the terms of the Eclipse Public License v1.0 which\r | |
6 | * accompanies this distribution, and is available at\r | |
7 | * http://www.eclipse.org/legal/epl-v10.html\r | |
013a5f1c | 8 | *\r |
ce62370f FC |
9 | * Contributors:\r |
10 | * Patrick Tasse - Initial API and implementation\r | |
11 | *******************************************************************************/\r | |
12 | \r | |
13 | package org.eclipse.linuxtools.tmf.ui.views.timechart;\r | |
14 | \r | |
15 | import java.util.ArrayList;\r | |
16 | import java.util.Iterator;\r | |
17 | \r | |
72f1e62a | 18 | import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;\r |
ce62370f | 19 | import org.eclipse.linuxtools.tmf.ui.views.colors.ColorSettingsManager;\r |
2fa130b8 | 20 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;\r |
fb5cad3d | 21 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;\r |
ce62370f | 22 | \r |
013a5f1c AM |
23 | /**\r |
24 | * Event in the time chart view\r | |
25 | *\r | |
26 | * @version 1.0\r | |
27 | * @author Patrick Tasse\r | |
28 | */\r | |
ce62370f FC |
29 | public class TimeChartEvent implements ITimeEvent {\r |
30 | \r | |
31 | private static final byte TIMESTAMP_SCALE = -9;\r | |
013a5f1c AM |
32 | \r |
33 | private final TimeChartAnalysisEntry fParentEntry;\r | |
ce62370f FC |
34 | private long fTime;\r |
35 | private long fDuration;\r | |
36 | private long fFirstRank;\r | |
37 | private long fLastRank;\r | |
013a5f1c | 38 | private final RankRangeList fRankRangeList;\r |
ce62370f FC |
39 | private long fNbEvents;\r |
40 | private int fColorSettingPriority;\r | |
41 | private boolean fIsBookmark;\r | |
42 | private boolean fIsVisible;\r | |
43 | private boolean fIsSearchMatch;\r | |
44 | private TimeChartAnalysisEntry fItemizedEntry;\r | |
45 | private boolean fItemizing;\r | |
46 | \r | |
20ff3b75 AM |
47 | /**\r |
48 | * Standard constructor\r | |
49 | *\r | |
50 | * @param parentEntry\r | |
51 | * The parent entry\r | |
52 | * @param event\r | |
53 | * The event from which this time chart event originates\r | |
54 | * @param rank\r | |
55 | * The rank of the event in the trace\r | |
56 | * @param decorationProvider\r | |
57 | * The decoration provider to use\r | |
58 | */\r | |
59 | public TimeChartEvent(TimeChartAnalysisEntry parentEntry, ITmfEvent event,\r | |
60 | long rank, TimeChartDecorationProvider decorationProvider) {\r | |
ce62370f | 61 | fParentEntry = parentEntry;\r |
5179fc01 | 62 | fTime = event.getTimestamp().normalize(0, TIMESTAMP_SCALE).getValue();\r |
ce62370f FC |
63 | fDuration = 0;\r |
64 | fFirstRank = fLastRank = rank;\r | |
65 | fRankRangeList = new RankRangeList(rank);\r | |
66 | fNbEvents = 1;\r | |
67 | fColorSettingPriority = ColorSettingsManager.getColorSettingPriority(event);\r | |
68 | fIsBookmark = decorationProvider.isBookmark(rank);\r | |
69 | fIsVisible = decorationProvider.isVisible(event);\r | |
70 | fIsSearchMatch = decorationProvider.isSearchMatch(event);\r | |
71 | }\r | |
72 | \r | |
73 | @Override\r | |
fb5cad3d | 74 | public ITimeGraphEntry getEntry() {\r |
ce62370f FC |
75 | return fParentEntry;\r |
76 | }\r | |
77 | \r | |
78 | @Override\r | |
79 | public long getTime() {\r | |
80 | return fTime;\r | |
81 | }\r | |
82 | \r | |
83 | @Override\r | |
84 | public long getDuration() {\r | |
85 | return fDuration;\r | |
86 | }\r | |
87 | \r | |
20ff3b75 AM |
88 | /**\r |
89 | * Retrieve the rank of the trace event which started this time event.\r | |
90 | *\r | |
91 | * @return The rank of the beginning\r | |
92 | */\r | |
ce62370f FC |
93 | public long getFirstRank() {\r |
94 | return fFirstRank;\r | |
95 | }\r | |
013a5f1c | 96 | \r |
20ff3b75 AM |
97 | /**\r |
98 | * Retrieve the rank of the trace event which *finished* this time event.\r | |
99 | *\r | |
100 | * @return The rank of the end\r | |
101 | */\r | |
ce62370f FC |
102 | public long getLastRank() {\r |
103 | return fLastRank;\r | |
104 | }\r | |
013a5f1c | 105 | \r |
20ff3b75 AM |
106 | /**\r |
107 | * Get the list of rank ranges corresponding to this time event.\r | |
108 | *\r | |
109 | * @return The rank range list\r | |
110 | */\r | |
ce62370f FC |
111 | public RankRangeList getRankRangeList() {\r |
112 | return fRankRangeList;\r | |
113 | }\r | |
013a5f1c | 114 | \r |
20ff3b75 AM |
115 | /**\r |
116 | * Merge another time event with this one.\r | |
117 | *\r | |
118 | * @param event\r | |
119 | * The other event\r | |
120 | */\r | |
ce62370f FC |
121 | public void merge(TimeChartEvent event) {\r |
122 | mergeDecorations(event);\r | |
013a5f1c AM |
123 | if (fTime == event.getTime() && fDuration == event.getDuration()) {\r |
124 | return;\r | |
125 | }\r | |
ce62370f FC |
126 | long endTime = Math.max(fTime + fDuration, event.getTime() + event.getDuration());\r |
127 | fTime = Math.min(fTime, event.getTime());\r | |
128 | fDuration = endTime - fTime;\r | |
129 | fFirstRank = Math.min(fFirstRank, event.fFirstRank);\r | |
130 | fLastRank = Math.max(fLastRank, event.fLastRank);\r | |
131 | fNbEvents += event.fNbEvents;\r | |
132 | fItemizedEntry = null;\r | |
133 | synchronized (fRankRangeList) {\r | |
134 | fRankRangeList.merge(event.getRankRangeList());\r | |
135 | }\r | |
136 | }\r | |
137 | \r | |
20ff3b75 AM |
138 | /**\r |
139 | * Merge the decorations of another time event with the decorations of this\r | |
140 | * one.\r | |
141 | *\r | |
142 | * @param event\r | |
143 | * The other event\r | |
144 | */\r | |
ce62370f FC |
145 | public void mergeDecorations(TimeChartEvent event) {\r |
146 | fColorSettingPriority = Math.min(fColorSettingPriority, event.getColorSettingPriority());\r | |
147 | fIsBookmark |= event.fIsBookmark;\r | |
148 | fIsVisible |= event.fIsVisible;\r | |
149 | fIsSearchMatch |= event.fIsSearchMatch;\r | |
150 | }\r | |
013a5f1c | 151 | \r |
20ff3b75 AM |
152 | /**\r |
153 | * Get the number of time events that have been merged with this one (starts\r | |
154 | * counting at 1 if no merge happened).\r | |
155 | *\r | |
156 | * @return The current number of events in the bath\r | |
157 | */\r | |
ce62370f FC |
158 | public long getNbEvents() {\r |
159 | return fNbEvents;\r | |
160 | }\r | |
161 | \r | |
20ff3b75 AM |
162 | /**\r |
163 | * Retrieve the color setting priority.\r | |
164 | *\r | |
165 | * @return The priority\r | |
166 | */\r | |
ce62370f FC |
167 | public int getColorSettingPriority() {\r |
168 | return fColorSettingPriority;\r | |
169 | }\r | |
013a5f1c | 170 | \r |
20ff3b75 AM |
171 | /**\r |
172 | * Set the color setting priority.\r | |
173 | *\r | |
174 | * @param priority\r | |
175 | * The priority to set\r | |
176 | */\r | |
ce62370f FC |
177 | public void setColorSettingPriority(int priority) {\r |
178 | fColorSettingPriority = priority;\r | |
179 | }\r | |
013a5f1c | 180 | \r |
20ff3b75 AM |
181 | /**\r |
182 | * Check if this time event is bookmarked\r | |
183 | *\r | |
184 | * @return Y/N\r | |
185 | */\r | |
ce62370f FC |
186 | public boolean isBookmarked() {\r |
187 | return fIsBookmark;\r | |
188 | }\r | |
189 | \r | |
20ff3b75 AM |
190 | /**\r |
191 | * Set this time event to be bookmarked or not.\r | |
192 | *\r | |
193 | * @param isBookmarked\r | |
194 | * Should time time event become a bookmark, or not\r | |
195 | */\r | |
ce62370f FC |
196 | public void setIsBookmarked(boolean isBookmarked) {\r |
197 | fIsBookmark = isBookmarked;\r | |
198 | }\r | |
013a5f1c | 199 | \r |
20ff3b75 AM |
200 | /**\r |
201 | * Check if this time is currently visible or not.\r | |
202 | *\r | |
203 | * @return If the event is visible\r | |
204 | */\r | |
ce62370f FC |
205 | public boolean isVisible() {\r |
206 | return fIsVisible;\r | |
207 | }\r | |
208 | \r | |
20ff3b75 AM |
209 | /**\r |
210 | * Set this time event to visible (or to non-visible).\r | |
211 | *\r | |
212 | * @param isVisible The new status\r | |
213 | */\r | |
ce62370f FC |
214 | public void setIsVisible(boolean isVisible) {\r |
215 | fIsVisible = isVisible;\r | |
216 | }\r | |
013a5f1c | 217 | \r |
20ff3b75 AM |
218 | /**\r |
219 | * Check if the time event matches the current search.\r | |
220 | *\r | |
221 | * @return If it matches, Y/N\r | |
222 | */\r | |
ce62370f FC |
223 | public boolean isSearchMatch() {\r |
224 | return fIsSearchMatch;\r | |
225 | }\r | |
226 | \r | |
20ff3b75 AM |
227 | /**\r |
228 | * Mark this event as matching (or non-matching) the current search.\r | |
229 | *\r | |
230 | * @param isSearchMatch\r | |
231 | * The new matching status\r | |
232 | */\r | |
ce62370f FC |
233 | public void setIsSearchMatch(boolean isSearchMatch) {\r |
234 | fIsSearchMatch = isSearchMatch;\r | |
235 | }\r | |
013a5f1c | 236 | \r |
a55887ca AM |
237 | /**\r |
238 | * Set this event's itemized entry.\r | |
239 | *\r | |
240 | * @param timeAnalysisEntry\r | |
241 | * The entry to set\r | |
242 | */\r | |
ce62370f FC |
243 | public void setItemizedEntry(TimeChartAnalysisEntry timeAnalysisEntry) {\r |
244 | fItemizedEntry = timeAnalysisEntry;\r | |
245 | }\r | |
246 | \r | |
a55887ca AM |
247 | /**\r |
248 | * Retrieve this event's itemized entry.\r | |
249 | *\r | |
250 | * @return The itemized entry that was previously set\r | |
251 | */\r | |
ce62370f FC |
252 | public TimeChartAnalysisEntry getItemizedEntry() {\r |
253 | return fItemizedEntry;\r | |
254 | }\r | |
255 | \r | |
a55887ca AM |
256 | /**\r |
257 | * @return Has this time event been set to itemizing?\r | |
258 | */\r | |
ce62370f FC |
259 | public boolean isItemizing() {\r |
260 | return fItemizing;\r | |
261 | }\r | |
262 | \r | |
a55887ca AM |
263 | /**\r |
264 | * Set this event's itemizing flag to true or false.\r | |
265 | *\r | |
266 | * @param itemizing\r | |
267 | * The new value\r | |
268 | */\r | |
ce62370f FC |
269 | public void setItemizing(boolean itemizing) {\r |
270 | fItemizing = itemizing;\r | |
271 | }\r | |
272 | \r | |
a55887ca AM |
273 | /**\r |
274 | * Inner class to define a range in terms of ranks in the trace.\r | |
275 | *\r | |
276 | * @version 1.0\r | |
277 | * @author Patrick Tasse\r | |
278 | */\r | |
ce62370f FC |
279 | public class RankRange {\r |
280 | private long firstRank;\r | |
281 | private long lastRank;\r | |
013a5f1c | 282 | \r |
a55887ca AM |
283 | /**\r |
284 | * Standard constructor\r | |
285 | *\r | |
286 | * @param firstRank\r | |
287 | * The first (earliest) rank of the range\r | |
288 | * @param lastRank\r | |
289 | * The last (latest) rank of the range\r | |
290 | */\r | |
ce62370f FC |
291 | public RankRange(long firstRank, long lastRank) {\r |
292 | this.firstRank = firstRank;\r | |
293 | this.lastRank = lastRank;\r | |
294 | }\r | |
295 | \r | |
a55887ca AM |
296 | /**\r |
297 | * Retrieve the start rank of this range.\r | |
298 | *\r | |
299 | * @return The first rank\r | |
300 | */\r | |
ce62370f FC |
301 | public long getFirstRank() {\r |
302 | return firstRank;\r | |
303 | }\r | |
304 | \r | |
a55887ca AM |
305 | /**\r |
306 | * Retrieve the end rank of this range\r | |
307 | *\r | |
308 | * @return The end rank\r | |
309 | */\r | |
ce62370f FC |
310 | public long getLastRank() {\r |
311 | return lastRank;\r | |
312 | }\r | |
313 | \r | |
a55887ca AM |
314 | /**\r |
315 | * Calculate the minimal distance between two RankRange's\r | |
316 | *\r | |
317 | * @param range\r | |
318 | * The other range\r | |
319 | * @return The distance, in "number of events" between the two ranges\r | |
320 | */\r | |
ce62370f FC |
321 | public long distanceFrom(RankRange range) {\r |
322 | if (range.lastRank < fFirstRank) {\r | |
323 | return fFirstRank - range.lastRank;\r | |
324 | } else if (range.firstRank > fLastRank) {\r | |
325 | return range.firstRank - fLastRank;\r | |
326 | } else {\r | |
327 | return 0;\r | |
328 | }\r | |
329 | }\r | |
013a5f1c | 330 | \r |
ce62370f FC |
331 | @Override\r |
332 | public String toString() {\r | |
333 | return "["+firstRank+","+lastRank+"]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r | |
334 | }\r | |
335 | }\r | |
013a5f1c | 336 | \r |
ce62370f | 337 | private class RankRangeList extends ArrayList<RankRange> {\r |
013a5f1c | 338 | \r |
ce62370f FC |
339 | private static final long serialVersionUID = 6060485531208535986L;\r |
340 | \r | |
341 | public RankRangeList(long rank) {\r | |
342 | super(1);\r | |
343 | add(new RankRange(rank, rank));\r | |
344 | }\r | |
013a5f1c | 345 | \r |
ce62370f | 346 | public void merge(RankRangeList rankRangeList) {\r |
20658947 | 347 | long threshold = fParentEntry.getTrace().getCacheSize();\r |
ce62370f FC |
348 | for (RankRange newRange : rankRangeList) {\r |
349 | boolean merged = false;\r | |
350 | for (RankRange oldRange : fRankRangeList) {\r | |
351 | if (newRange.distanceFrom(oldRange) <= threshold) {\r | |
352 | oldRange.firstRank = Math.min(oldRange.firstRank, newRange.firstRank);\r | |
353 | oldRange.lastRank = Math.max(oldRange.lastRank, newRange.lastRank);\r | |
354 | merged = true;\r | |
355 | break;\r | |
356 | }\r | |
357 | }\r | |
358 | if (!merged) {\r | |
359 | add(newRange);\r | |
360 | }\r | |
361 | }\r | |
362 | Iterator<RankRange> iterator = fRankRangeList.iterator();\r | |
363 | RankRange previous = null;\r | |
364 | while (iterator.hasNext()) {\r | |
365 | RankRange range = iterator.next();\r | |
366 | if (previous != null && range.distanceFrom(previous) <= threshold) {\r | |
367 | previous.firstRank = Math.min(previous.firstRank, range.firstRank);\r | |
368 | previous.lastRank = Math.max(previous.lastRank, range.lastRank);\r | |
369 | iterator.remove();\r | |
370 | }\r | |
371 | previous = range;\r | |
372 | }\r | |
373 | }\r | |
374 | }\r | |
375 | }\r |