1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 Ericsson
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
10 * Alexandre Montplaisir - Initial API and implementation
11 ******************************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.core
.statistics
;
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
;
30 * The analysis module building the "event types" statistics state system.
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.
35 * @author Alexandre Montplaisir
38 public class TmfStatisticsEventTypesModule
extends TmfStateSystemAnalysisModule
{
41 * The ID of this analysis module (which is also the ID of the state system)
43 public static final @NonNull String ID
= "org.eclipse.linuxtools.tmf.statistics.types"; //$NON-NLS-1$
45 private static final @NonNull String NAME
= "TMF Statistics, events per type"; //$NON-NLS-1$
50 public TmfStatisticsEventTypesModule() {
57 protected ITmfStateProvider
createStateProvider() {
58 return new StatsProviderEventTypes(getTrace());
62 protected String
getSsFileName() {
63 return "statistics-types.ht"; //$NON-NLS-1$
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.
71 * It will store number of events seen, per event types. The resulting attribute
72 * tree will look like this:
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.
86 * @author Alexandre Montplaisir
89 class StatsProviderEventTypes
extends AbstractTmfStateProvider
{
92 * Version number of this input handler. Please bump this if you modify the
93 * contents of the generated state history in some way.
95 private static final int VERSION
= 2;
101 * The trace for which we build this state system
103 public StatsProviderEventTypes(ITmfTrace trace
) {
104 super(trace
, ITmfEvent
.class ,"TMF Statistics, events per type"); //$NON-NLS-1$
108 public int getVersion() {
113 public StatsProviderEventTypes
getNewInstance() {
114 return new StatsProviderEventTypes(this.getTrace());
118 protected void eventHandle(ITmfEvent event
) {
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();
125 final String eventName
= event
.getType().getName();
128 /* Special handling for lost events */
129 if (event
instanceof ITmfLostEvent
) {
130 ITmfLostEvent le
= (ITmfLostEvent
) event
;
131 quark
= ss
.getQuarkAbsoluteAndAdd(Attributes
.EVENT_TYPES
, eventName
);
133 int curVal
= ss
.queryOngoingState(quark
).unboxInt();
138 TmfStateValue value
= TmfStateValue
.newValueInt((int) (curVal
+ le
.getNbLostEvents()));
139 ss
.modifyAttribute(ts
, value
, quark
);
143 /* Number of events of each type, globally */
144 quark
= ss
.getQuarkAbsoluteAndAdd(Attributes
.EVENT_TYPES
, eventName
);
145 ss
.incrementAttribute(ts
, quark
);
147 // /* Number of events per CPU */
148 // quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.STATISTICS, Attributes.EVENT_TYPES, eventName);
149 // ss.incrementAttribute(ts, quark);
151 // /* Number of events per process */
152 // quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.STATISTICS, Attributes.EVENT_TYPES, eventName);
153 // ss.incrementAttribute(ts, quark);
155 } catch (StateValueTypeException
| TimeRangeException
| AttributeNotFoundException e
) {