1 /*******************************************************************************
2 * Copyright (c) 2013, 2015 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 static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
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
;
33 * The analysis module building the "event types" statistics state system.
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.
38 * @author Alexandre Montplaisir
41 public class TmfStatisticsEventTypesModule
extends TmfStateSystemAnalysisModule
{
44 * The ID of this analysis module (which is also the ID of the state system)
46 public static final @NonNull String ID
= "org.eclipse.linuxtools.tmf.statistics.types"; //$NON-NLS-1$
48 private static final @NonNull String NAME
= "TMF Statistics, events per type"; //$NON-NLS-1$
53 public TmfStatisticsEventTypesModule() {
60 protected ITmfStateProvider
createStateProvider() {
61 return new StatsProviderEventTypes(checkNotNull(getTrace()));
65 protected String
getSsFileName() {
66 return "statistics-types.ht"; //$NON-NLS-1$
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.
74 * It will store number of events seen, per event types. The resulting attribute
75 * tree will look like this:
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.
89 * @author Alexandre Montplaisir
92 class StatsProviderEventTypes
extends AbstractTmfStateProvider
{
95 * Version number of this input handler. Please bump this if you modify the
96 * contents of the generated state history in some way.
98 private static final int VERSION
= 2;
104 * The trace for which we build this state system
106 public StatsProviderEventTypes(@NonNull ITmfTrace trace
) {
107 super(trace
, ITmfEvent
.class ,"TMF Statistics, events per type"); //$NON-NLS-1$
111 public int getVersion() {
116 public StatsProviderEventTypes
getNewInstance() {
117 return new StatsProviderEventTypes(this.getTrace());
121 protected void eventHandle(ITmfEvent event
) {
122 ITmfStateSystemBuilder ss
= checkNotNull(getStateSystemBuilder());
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();
129 final String eventName
= event
.getType().getName();
132 /* Special handling for lost events */
133 if (event
instanceof ITmfLostEvent
) {
134 ITmfLostEvent le
= (ITmfLostEvent
) event
;
135 quark
= ss
.getQuarkAbsoluteAndAdd(Attributes
.EVENT_TYPES
, eventName
);
137 int curVal
= ss
.queryOngoingState(quark
).unboxInt();
142 TmfStateValue value
= TmfStateValue
.newValueInt((int) (curVal
+ le
.getNbLostEvents()));
143 ss
.modifyAttribute(ts
, value
, quark
);
147 /* Number of events of each type, globally */
148 quark
= ss
.getQuarkAbsoluteAndAdd(Attributes
.EVENT_TYPES
, eventName
);
149 ss
.incrementAttribute(ts
, quark
);
151 // /* Number of events per CPU */
152 // quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.STATISTICS, Attributes.EVENT_TYPES, eventName);
153 // ss.incrementAttribute(ts, quark);
155 // /* Number of events per process */
156 // quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.STATISTICS, Attributes.EVENT_TYPES, eventName);
157 // ss.incrementAttribute(ts, quark);
159 } catch (StateValueTypeException
| TimeRangeException
| AttributeNotFoundException e
) {