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