Copyright header update, 2015 edition
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / statistics / TmfStatisticsEventTypesModule.java
1 /*******************************************************************************
2 * Copyright (c) 2013, 2015 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
13 package org.eclipse.tracecompass.tmf.core.statistics;
14
15 import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
16
17 import org.eclipse.jdt.annotation.NonNull;
18 import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder;
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;
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;
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 */
46 public static final @NonNull String ID = "org.eclipse.linuxtools.tmf.statistics.types"; //$NON-NLS-1$
47
48 private static final @NonNull String NAME = "TMF Statistics, events per type"; //$NON-NLS-1$
49
50 /**
51 * Constructor
52 */
53 public TmfStatisticsEventTypesModule() {
54 super();
55 setId(ID);
56 setName(NAME);
57 }
58
59 @Override
60 protected ITmfStateProvider createStateProvider() {
61 return new StatsProviderEventTypes(checkNotNull(getTrace()));
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(@NonNull 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 ITmfStateSystemBuilder ss = checkNotNull(getStateSystemBuilder());
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 }
This page took 0.036398 seconds and 6 git commands to generate.