Commit | Line | Data |
---|---|---|
8192f2c6 | 1 | /******************************************************************************* |
60ae41e1 | 2 | * Copyright (c) 2013, 2014 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 | |
11 | ******************************************************************************/ | |
12 | ||
2bdf0193 | 13 | package org.eclipse.tracecompass.tmf.core.statistics; |
8192f2c6 | 14 | |
d0c7e4ba AM |
15 | import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull; |
16 | ||
55954069 | 17 | import org.eclipse.jdt.annotation.NonNull; |
d0c7e4ba | 18 | import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder; |
e894a508 AM |
19 | import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException; |
20 | import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException; | |
21 | import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException; | |
22 | import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue; | |
2bdf0193 AM |
23 | import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; |
24 | import org.eclipse.tracecompass.tmf.core.event.ITmfLostEvent; | |
25 | import org.eclipse.tracecompass.tmf.core.statesystem.AbstractTmfStateProvider; | |
26 | import org.eclipse.tracecompass.tmf.core.statesystem.ITmfStateProvider; | |
27 | import org.eclipse.tracecompass.tmf.core.statesystem.TmfStateSystemAnalysisModule; | |
28 | import org.eclipse.tracecompass.tmf.core.statistics.TmfStateStatistics.Attributes; | |
29 | import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp; | |
30 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; | |
8192f2c6 AM |
31 | |
32 | /** | |
33 | * The analysis module building the "event types" statistics state system. | |
34 | * | |
35 | * It is not in the extension point (and as such, not registered in the | |
36 | * TmfAnalysisManager), as it is being handled by the TmfStatisticsModule. | |
37 | * | |
38 | * @author Alexandre Montplaisir | |
39 | * @since 3.0 | |
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 | * | |
74 | * It will store number of events seen, per event types. The resulting attribute | |
75 | * tree will look like this: | |
76 | * | |
77 | * <pre> | |
78 | * (root) | |
79 | * \-- event_types | |
80 | * |-- (event name 1) | |
81 | * |-- (event name 2) | |
82 | * |-- (event name 3) | |
83 | * ... | |
84 | * </pre> | |
85 | * | |
86 | * And each (event name)'s value will be an integer, representing how many times | |
87 | * this particular event type has been seen in the trace so far. | |
88 | * | |
89 | * @author Alexandre Montplaisir | |
90 | * @version 1.0 | |
91 | */ | |
92 | class StatsProviderEventTypes extends AbstractTmfStateProvider { | |
93 | ||
94 | /** | |
95 | * Version number of this input handler. Please bump this if you modify the | |
96 | * contents of the generated state history in some way. | |
97 | */ | |
98 | private static final int VERSION = 2; | |
99 | ||
100 | /** | |
101 | * Constructor | |
102 | * | |
103 | * @param trace | |
104 | * The trace for which we build this state system | |
105 | */ | |
d0c7e4ba | 106 | public StatsProviderEventTypes(@NonNull ITmfTrace trace) { |
8192f2c6 AM |
107 | super(trace, ITmfEvent.class ,"TMF Statistics, events per type"); //$NON-NLS-1$ |
108 | } | |
109 | ||
110 | @Override | |
111 | public int getVersion() { | |
112 | return VERSION; | |
113 | } | |
114 | ||
115 | @Override | |
116 | public StatsProviderEventTypes getNewInstance() { | |
117 | return new StatsProviderEventTypes(this.getTrace()); | |
118 | } | |
119 | ||
120 | @Override | |
121 | protected void eventHandle(ITmfEvent event) { | |
d0c7e4ba | 122 | ITmfStateSystemBuilder ss = checkNotNull(getStateSystemBuilder()); |
8192f2c6 AM |
123 | int quark; |
124 | ||
125 | /* Since this can be used for any trace types, normalize all the | |
126 | * timestamp values to nanoseconds. */ | |
127 | final long ts = event.getTimestamp().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); | |
128 | ||
129 | final String eventName = event.getType().getName(); | |
130 | ||
131 | try { | |
132 | /* Special handling for lost events */ | |
133 | if (event instanceof ITmfLostEvent) { | |
134 | ITmfLostEvent le = (ITmfLostEvent) event; | |
135 | quark = ss.getQuarkAbsoluteAndAdd(Attributes.EVENT_TYPES, eventName); | |
136 | ||
137 | int curVal = ss.queryOngoingState(quark).unboxInt(); | |
138 | if (curVal == -1) { | |
139 | curVal = 0; | |
140 | } | |
141 | ||
142 | TmfStateValue value = TmfStateValue.newValueInt((int) (curVal + le.getNbLostEvents())); | |
143 | ss.modifyAttribute(ts, value, quark); | |
144 | return; | |
145 | } | |
146 | ||
147 | /* Number of events of each type, globally */ | |
148 | quark = ss.getQuarkAbsoluteAndAdd(Attributes.EVENT_TYPES, eventName); | |
149 | ss.incrementAttribute(ts, quark); | |
150 | ||
151 | // /* Number of events per CPU */ | |
152 | // quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.STATISTICS, Attributes.EVENT_TYPES, eventName); | |
153 | // ss.incrementAttribute(ts, quark); | |
154 | // | |
155 | // /* Number of events per process */ | |
156 | // quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.STATISTICS, Attributes.EVENT_TYPES, eventName); | |
157 | // ss.incrementAttribute(ts, quark); | |
158 | ||
159 | } catch (StateValueTypeException | TimeRangeException | AttributeNotFoundException e) { | |
160 | e.printStackTrace(); | |
161 | } | |
162 | } | |
163 | } | |
164 | } |