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