Commit | Line | Data |
---|---|---|
8192f2c6 | 1 | /******************************************************************************* |
ed902a2b | 2 | * Copyright (c) 2013, 2015 Ericsson |
8192f2c6 AM |
3 | * |
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 | |
8 | * | |
9 | * Contributors: | |
10 | * Alexandre Montplaisir - Initial API and implementation | |
c53cebea | 11 | * Patrick Tasse - Added lost events attribute |
8192f2c6 AM |
12 | ******************************************************************************/ |
13 | ||
2bdf0193 | 14 | package org.eclipse.tracecompass.tmf.core.statistics; |
8192f2c6 | 15 | |
d0c7e4ba AM |
16 | import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull; |
17 | ||
55954069 | 18 | import org.eclipse.jdt.annotation.NonNull; |
d0c7e4ba | 19 | import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder; |
e894a508 AM |
20 | import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException; |
21 | import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException; | |
22 | import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException; | |
c53cebea | 23 | import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue; |
e894a508 | 24 | import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue; |
2bdf0193 AM |
25 | import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; |
26 | import org.eclipse.tracecompass.tmf.core.event.ITmfLostEvent; | |
27 | import org.eclipse.tracecompass.tmf.core.statesystem.AbstractTmfStateProvider; | |
28 | import org.eclipse.tracecompass.tmf.core.statesystem.ITmfStateProvider; | |
29 | import org.eclipse.tracecompass.tmf.core.statesystem.TmfStateSystemAnalysisModule; | |
30 | import org.eclipse.tracecompass.tmf.core.statistics.TmfStateStatistics.Attributes; | |
2bdf0193 | 31 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; |
8192f2c6 AM |
32 | |
33 | /** | |
34 | * The analysis module building the "event types" statistics state system. | |
35 | * | |
36 | * It is not in the extension point (and as such, not registered in the | |
37 | * TmfAnalysisManager), as it is being handled by the TmfStatisticsModule. | |
38 | * | |
39 | * @author Alexandre Montplaisir | |
8192f2c6 AM |
40 | */ |
41 | public class TmfStatisticsEventTypesModule extends TmfStateSystemAnalysisModule { | |
42 | ||
43 | /** | |
44 | * The ID of this analysis module (which is also the ID of the state system) | |
45 | */ | |
6d8922ce | 46 | public static final @NonNull String ID = "org.eclipse.linuxtools.tmf.statistics.types"; //$NON-NLS-1$ |
8192f2c6 | 47 | |
6d8922ce | 48 | private static final @NonNull String NAME = "TMF Statistics, events per type"; //$NON-NLS-1$ |
8192f2c6 AM |
49 | |
50 | /** | |
51 | * Constructor | |
52 | */ | |
53 | public TmfStatisticsEventTypesModule() { | |
d4c4fe14 | 54 | super(); |
8192f2c6 AM |
55 | setId(ID); |
56 | setName(NAME); | |
57 | } | |
58 | ||
59 | @Override | |
60 | protected ITmfStateProvider createStateProvider() { | |
d0c7e4ba | 61 | return new StatsProviderEventTypes(checkNotNull(getTrace())); |
8192f2c6 AM |
62 | } |
63 | ||
8192f2c6 AM |
64 | @Override |
65 | protected String getSsFileName() { | |
66 | return "statistics-types.ht"; //$NON-NLS-1$ | |
67 | } | |
68 | ||
69 | ||
70 | /** | |
71 | * The state provider for traces statistics that use TmfStateStatistics. It | |
72 | * should work with any trace type for which we can use the state system. | |
73 | * | |
c53cebea PT |
74 | * It will store number of events seen, per event types. The resulting |
75 | * attribute tree will look like this: | |
8192f2c6 AM |
76 | * |
77 | * <pre> | |
78 | * (root) | |
c53cebea PT |
79 | * |-- event_types |
80 | * | |-- (event name 1) | |
81 | * | |-- (event name 2) | |
82 | * | |-- (event name 3) | |
83 | * | ... | |
84 | * \-- lost_events | |
8192f2c6 AM |
85 | * </pre> |
86 | * | |
c53cebea | 87 | * Each (event name)'s value will be an integer, representing how many times |
8192f2c6 AM |
88 | * this particular event type has been seen in the trace so far. |
89 | * | |
c53cebea PT |
90 | * The value of the lost_events attribute will be a long, representing the |
91 | * latest end time of any current or previous lost event time range, in | |
92 | * nanoseconds. If the value at a specific time 't' is greater than 't', | |
93 | * then there is at least one lost event time range that overlaps time 't'. | |
94 | * | |
8192f2c6 AM |
95 | * @author Alexandre Montplaisir |
96 | * @version 1.0 | |
97 | */ | |
98 | class StatsProviderEventTypes extends AbstractTmfStateProvider { | |
99 | ||
100 | /** | |
101 | * Version number of this input handler. Please bump this if you modify the | |
102 | * contents of the generated state history in some way. | |
103 | */ | |
c53cebea | 104 | private static final int VERSION = 3; |
8192f2c6 AM |
105 | |
106 | /** | |
107 | * Constructor | |
108 | * | |
109 | * @param trace | |
110 | * The trace for which we build this state system | |
111 | */ | |
d0c7e4ba | 112 | public StatsProviderEventTypes(@NonNull ITmfTrace trace) { |
e2bcc8a5 | 113 | super(trace ,"TMF Statistics, events per type"); //$NON-NLS-1$ |
8192f2c6 AM |
114 | } |
115 | ||
116 | @Override | |
117 | public int getVersion() { | |
118 | return VERSION; | |
119 | } | |
120 | ||
121 | @Override | |
122 | public StatsProviderEventTypes getNewInstance() { | |
123 | return new StatsProviderEventTypes(this.getTrace()); | |
124 | } | |
125 | ||
126 | @Override | |
127 | protected void eventHandle(ITmfEvent event) { | |
d0c7e4ba | 128 | ITmfStateSystemBuilder ss = checkNotNull(getStateSystemBuilder()); |
8192f2c6 AM |
129 | int quark; |
130 | ||
131 | /* Since this can be used for any trace types, normalize all the | |
132 | * timestamp values to nanoseconds. */ | |
16801c72 | 133 | final long ts = event.getTimestamp().toNanos(); |
8192f2c6 | 134 | |
578716e6 | 135 | final String eventName = event.getName(); |
8192f2c6 AM |
136 | |
137 | try { | |
138 | /* Special handling for lost events */ | |
139 | if (event instanceof ITmfLostEvent) { | |
140 | ITmfLostEvent le = (ITmfLostEvent) event; | |
141 | quark = ss.getQuarkAbsoluteAndAdd(Attributes.EVENT_TYPES, eventName); | |
142 | ||
143 | int curVal = ss.queryOngoingState(quark).unboxInt(); | |
144 | if (curVal == -1) { | |
145 | curVal = 0; | |
146 | } | |
147 | ||
c53cebea PT |
148 | ITmfStateValue value1 = TmfStateValue.newValueInt((int) (curVal + le.getNbLostEvents())); |
149 | ss.modifyAttribute(ts, value1, quark); | |
150 | ||
16801c72 MK |
151 | long lostEventsStartTime = le.getTimeRange().getStartTime().toNanos(); |
152 | long lostEventsEndTime = le.getTimeRange().getEndTime().toNanos(); | |
c53cebea PT |
153 | int lostEventsQuark = ss.getQuarkAbsoluteAndAdd(Attributes.LOST_EVENTS); |
154 | ITmfStateValue currentLostEventsEndTime = ss.queryOngoingState(lostEventsQuark); | |
155 | if (currentLostEventsEndTime.isNull() || currentLostEventsEndTime.unboxLong() < lostEventsStartTime) { | |
156 | ss.modifyAttribute(lostEventsStartTime, TmfStateValue.newValueLong(lostEventsEndTime), lostEventsQuark); | |
157 | } else if (currentLostEventsEndTime.unboxLong() < lostEventsEndTime) { | |
158 | ss.updateOngoingState(TmfStateValue.newValueLong(lostEventsEndTime), lostEventsQuark); | |
159 | } | |
8192f2c6 AM |
160 | return; |
161 | } | |
162 | ||
163 | /* Number of events of each type, globally */ | |
164 | quark = ss.getQuarkAbsoluteAndAdd(Attributes.EVENT_TYPES, eventName); | |
165 | ss.incrementAttribute(ts, quark); | |
166 | ||
167 | // /* Number of events per CPU */ | |
168 | // quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.STATISTICS, Attributes.EVENT_TYPES, eventName); | |
169 | // ss.incrementAttribute(ts, quark); | |
170 | // | |
171 | // /* Number of events per process */ | |
172 | // quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.STATISTICS, Attributes.EVENT_TYPES, eventName); | |
173 | // ss.incrementAttribute(ts, quark); | |
174 | ||
175 | } catch (StateValueTypeException | TimeRangeException | AttributeNotFoundException e) { | |
176 | e.printStackTrace(); | |
177 | } | |
178 | } | |
179 | } | |
180 | } |