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