analysis: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / statistics / TmfStatisticsEventTypesModule.java
CommitLineData
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
11 ******************************************************************************/
12
2bdf0193 13package org.eclipse.tracecompass.tmf.core.statistics;
8192f2c6 14
d0c7e4ba
AM
15import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
16
55954069 17import org.eclipse.jdt.annotation.NonNull;
d0c7e4ba 18import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder;
e894a508
AM
19import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
20import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException;
21import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException;
22import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue;
2bdf0193
AM
23import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
24import org.eclipse.tracecompass.tmf.core.event.ITmfLostEvent;
25import org.eclipse.tracecompass.tmf.core.statesystem.AbstractTmfStateProvider;
26import org.eclipse.tracecompass.tmf.core.statesystem.ITmfStateProvider;
27import org.eclipse.tracecompass.tmf.core.statesystem.TmfStateSystemAnalysisModule;
28import org.eclipse.tracecompass.tmf.core.statistics.TmfStateStatistics.Attributes;
29import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
30import 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
8192f2c6
AM
39 */
40public class TmfStatisticsEventTypesModule extends TmfStateSystemAnalysisModule {
41
42 /**
43 * The ID of this analysis module (which is also the ID of the state system)
44 */
6d8922ce 45 public static final @NonNull String ID = "org.eclipse.linuxtools.tmf.statistics.types"; //$NON-NLS-1$
8192f2c6 46
6d8922ce 47 private static final @NonNull String NAME = "TMF Statistics, events per type"; //$NON-NLS-1$
8192f2c6
AM
48
49 /**
50 * Constructor
51 */
52 public TmfStatisticsEventTypesModule() {
d4c4fe14 53 super();
8192f2c6
AM
54 setId(ID);
55 setName(NAME);
56 }
57
58 @Override
59 protected ITmfStateProvider createStateProvider() {
d0c7e4ba 60 return new StatsProviderEventTypes(checkNotNull(getTrace()));
8192f2c6
AM
61 }
62
8192f2c6
AM
63 @Override
64 protected String getSsFileName() {
65 return "statistics-types.ht"; //$NON-NLS-1$
66 }
67
68
69 /**
70 * The state provider for traces statistics that use TmfStateStatistics. It
71 * should work with any trace type for which we can use the state system.
72 *
73 * It will store number of events seen, per event types. The resulting attribute
74 * tree will look like this:
75 *
76 * <pre>
77 * (root)
78 * \-- event_types
79 * |-- (event name 1)
80 * |-- (event name 2)
81 * |-- (event name 3)
82 * ...
83 * </pre>
84 *
85 * And each (event name)'s value will be an integer, representing how many times
86 * this particular event type has been seen in the trace so far.
87 *
88 * @author Alexandre Montplaisir
89 * @version 1.0
90 */
91 class StatsProviderEventTypes extends AbstractTmfStateProvider {
92
93 /**
94 * Version number of this input handler. Please bump this if you modify the
95 * contents of the generated state history in some way.
96 */
97 private static final int VERSION = 2;
98
99 /**
100 * Constructor
101 *
102 * @param trace
103 * The trace for which we build this state system
104 */
d0c7e4ba 105 public StatsProviderEventTypes(@NonNull ITmfTrace trace) {
e2bcc8a5 106 super(trace ,"TMF Statistics, events per type"); //$NON-NLS-1$
8192f2c6
AM
107 }
108
109 @Override
110 public int getVersion() {
111 return VERSION;
112 }
113
114 @Override
115 public StatsProviderEventTypes getNewInstance() {
116 return new StatsProviderEventTypes(this.getTrace());
117 }
118
119 @Override
120 protected void eventHandle(ITmfEvent event) {
d0c7e4ba 121 ITmfStateSystemBuilder ss = checkNotNull(getStateSystemBuilder());
8192f2c6
AM
122 int quark;
123
124 /* Since this can be used for any trace types, normalize all the
125 * timestamp values to nanoseconds. */
126 final long ts = event.getTimestamp().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
127
578716e6 128 final String eventName = event.getName();
8192f2c6
AM
129
130 try {
131 /* Special handling for lost events */
132 if (event instanceof ITmfLostEvent) {
133 ITmfLostEvent le = (ITmfLostEvent) event;
134 quark = ss.getQuarkAbsoluteAndAdd(Attributes.EVENT_TYPES, eventName);
135
136 int curVal = ss.queryOngoingState(quark).unboxInt();
137 if (curVal == -1) {
138 curVal = 0;
139 }
140
141 TmfStateValue value = TmfStateValue.newValueInt((int) (curVal + le.getNbLostEvents()));
142 ss.modifyAttribute(ts, value, quark);
143 return;
144 }
145
146 /* Number of events of each type, globally */
147 quark = ss.getQuarkAbsoluteAndAdd(Attributes.EVENT_TYPES, eventName);
148 ss.incrementAttribute(ts, quark);
149
150// /* Number of events per CPU */
151// quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.STATISTICS, Attributes.EVENT_TYPES, eventName);
152// ss.incrementAttribute(ts, quark);
153 //
154// /* Number of events per process */
155// quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.STATISTICS, Attributes.EVENT_TYPES, eventName);
156// ss.incrementAttribute(ts, quark);
157
158 } catch (StateValueTypeException | TimeRangeException | AttributeNotFoundException e) {
159 e.printStackTrace();
160 }
161 }
162 }
163}
This page took 0.062831 seconds and 5 git commands to generate.