1 /*******************************************************************************
2 * Copyright (c) 2015, 2016 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
.internal
.tmf
.ui
.markers
;
15 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
17 import java
.util
.ArrayList
;
18 import java
.util
.Arrays
;
19 import java
.util
.Collections
;
20 import java
.util
.List
;
22 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
23 import org
.eclipse
.jdt
.annotation
.NonNull
;
24 import org
.eclipse
.swt
.graphics
.RGBA
;
25 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Messages
;
26 import org
.eclipse
.tracecompass
.statesystem
.core
.ITmfStateSystem
;
27 import org
.eclipse
.tracecompass
.statesystem
.core
.StateSystemUtils
;
28 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.AttributeNotFoundException
;
29 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.StateSystemDisposedException
;
30 import org
.eclipse
.tracecompass
.statesystem
.core
.interval
.ITmfStateInterval
;
31 import org
.eclipse
.tracecompass
.tmf
.core
.statistics
.TmfStateStatistics
.Attributes
;
32 import org
.eclipse
.tracecompass
.tmf
.core
.statistics
.TmfStatisticsEventTypesModule
;
33 import org
.eclipse
.tracecompass
.tmf
.core
.statistics
.TmfStatisticsModule
;
34 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
35 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceUtils
;
36 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.IMarkerEvent
;
37 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.IMarkerEventSource
;
38 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.MarkerEvent
;
41 * Marker event source for lost events.
43 public class LostEventsMarkerEventSource
implements IMarkerEventSource
{
45 private static final @NonNull String LOST_EVENTS
= checkNotNull(Messages
.MarkerEvent_LostEvents
);
47 private static final RGBA COLOR
= new RGBA(255, 0, 0, 50);
49 private final @NonNull ITmfTrace fTrace
;
50 private long[] fLastRequest
;
51 private @NonNull List
<@NonNull IMarkerEvent
> fLastMarkers
= Collections
.emptyList();
59 public LostEventsMarkerEventSource(@NonNull ITmfTrace trace
) {
64 public @NonNull List
<@NonNull String
> getMarkerCategories() {
65 return Arrays
.asList(LOST_EVENTS
);
69 public synchronized @NonNull List
<@NonNull IMarkerEvent
> getMarkerList(@NonNull String category
, long startTime
, long endTime
, long resolution
, @NonNull IProgressMonitor monitor
) {
70 if (!category
.equals(LOST_EVENTS
)) {
71 return Collections
.emptyList();
73 ITmfStateSystem ss
= getStateSystem();
75 return Collections
.emptyList();
77 int lostEventsQuark
= getLostEventsQuark(ss
);
78 if (lostEventsQuark
== -1) {
79 return Collections
.emptyList();
81 long[] request
= new long[] { startTime
, endTime
, resolution
, ss
.getCurrentEndTime() };
82 if (Arrays
.equals(request
, fLastRequest
)) {
85 List
<@NonNull IMarkerEvent
> markers
= new ArrayList
<>();
87 long start
= Math
.max(startTime
, ss
.getStartTime());
88 long end
= Math
.min(endTime
, ss
.getCurrentEndTime());
90 /* Update start to ensure that the previous marker is included. */
91 start
= Math
.max(start
- 1, ss
.getStartTime());
92 /* Update end to ensure that the next marker is included. */
93 long nextStartTime
= ss
.querySingleState(end
, lostEventsQuark
).getEndTime() + 1;
94 end
= Math
.min(nextStartTime
, ss
.getCurrentEndTime());
95 List
<ITmfStateInterval
> intervals
= StateSystemUtils
.queryHistoryRange(ss
, lostEventsQuark
, start
, end
, resolution
, monitor
);
96 for (ITmfStateInterval interval
: intervals
) {
97 if (interval
.getStateValue().isNull()) {
100 long lostEventsStartTime
= interval
.getStartTime();
102 * The end time of the lost events range is the value of the
103 * attribute, not the end time of the interval.
105 long lostEventsEndTime
= interval
.getStateValue().unboxLong();
106 long duration
= lostEventsEndTime
- lostEventsStartTime
;
107 IMarkerEvent marker
= new MarkerEvent(null, lostEventsStartTime
, duration
, LOST_EVENTS
, COLOR
, null, false);
111 } catch (AttributeNotFoundException
| StateSystemDisposedException e
) {
114 fLastRequest
= request
;
115 fLastMarkers
= Collections
.unmodifiableList(markers
);
119 private ITmfStateSystem
getStateSystem() {
120 TmfStatisticsModule module
= TmfTraceUtils
.getAnalysisModuleOfClass(fTrace
, TmfStatisticsModule
.class, TmfStatisticsModule
.ID
);
121 if (module
== null) {
124 return module
.getStateSystem(TmfStatisticsEventTypesModule
.ID
);
127 private static int getLostEventsQuark(ITmfStateSystem ss
) {
129 return ss
.getQuarkAbsolute(Attributes
.LOST_EVENTS
);
130 } catch (AttributeNotFoundException e
) {