tmf: Move the trace statistics to the analysis framework
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / statistics / TmfStatisticsEventTypesModule.java
CommitLineData
8192f2c6
AM
1/*******************************************************************************
2 * Copyright (c) 2013 Ericsson
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
13package org.eclipse.linuxtools.tmf.core.statistics;
14
15import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
16import org.eclipse.linuxtools.tmf.core.event.ITmfLostEvent;
17import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException;
18import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException;
19import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException;
20import org.eclipse.linuxtools.tmf.core.statesystem.AbstractTmfStateProvider;
21import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateProvider;
22import org.eclipse.linuxtools.tmf.core.statesystem.TmfStateSystemAnalysisModule;
23import org.eclipse.linuxtools.tmf.core.statevalue.TmfStateValue;
24import org.eclipse.linuxtools.tmf.core.statistics.TmfStateStatistics.Attributes;
25import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
26import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
27
28/**
29 * The analysis module building the "event types" statistics state system.
30 *
31 * It is not in the extension point (and as such, not registered in the
32 * TmfAnalysisManager), as it is being handled by the TmfStatisticsModule.
33 *
34 * @author Alexandre Montplaisir
35 * @since 3.0
36 */
37public class TmfStatisticsEventTypesModule extends TmfStateSystemAnalysisModule {
38
39 /**
40 * The ID of this analysis module (which is also the ID of the state system)
41 */
42 public static final String ID = "org.eclipse.linuxtools.tmf.statistics.types"; //$NON-NLS-1$
43
44 private static final String NAME = "TMF Statistics, events per type"; //$NON-NLS-1$
45
46 /**
47 * Constructor
48 */
49 public TmfStatisticsEventTypesModule() {
50 setId(ID);
51 setName(NAME);
52 }
53
54 @Override
55 protected ITmfStateProvider createStateProvider() {
56 return new StatsProviderEventTypes(getTrace());
57 }
58
59 @Override
60 protected StateSystemBackendType getBackendType() {
61 return StateSystemBackendType.FULL;
62 }
63
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 */
106 public StatsProviderEventTypes(ITmfTrace trace) {
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) {
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
128 final String eventName = event.getType().getName();
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.030309 seconds and 5 git commands to generate.