1 /*******************************************************************************
2 * Copyright (c) 2012 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
.linuxtools
.tmf
.core
.statistics
;
15 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
16 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.AttributeNotFoundException
;
17 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.StateValueTypeException
;
18 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TimeRangeException
;
19 import org
.eclipse
.linuxtools
.tmf
.core
.statesystem
.AbstractStateChangeInput
;
20 import org
.eclipse
.linuxtools
.tmf
.core
.statesystem
.ITmfStateSystemBuilder
;
21 import org
.eclipse
.linuxtools
.tmf
.core
.statistics
.TmfStateStatistics
.Attributes
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
25 * The state provider for traces statistics that use TmfStateStatistics. It
26 * should work with any trace type for which we can use the state system.
28 * The resulting attribute tree will look like this:
38 * And each <event name>'s value will be an integer, representing how many times
39 * this particular event type has been seen in the trace so far.
41 * @author Alexandre Montplaisir
44 class StatsStateProvider
extends AbstractStateChangeInput
{
46 /* Commonly-used attributes */
47 private int typeAttribute
= -1;
53 * The trace for which we build this state system
55 public StatsStateProvider(ITmfTrace trace
) {
56 super(trace
, ITmfEvent
.class ,"TMF Statistics"); //$NON-NLS-1$
60 public void assignTargetStateSystem(ITmfStateSystemBuilder ssb
) {
61 super.assignTargetStateSystem(ssb
);
63 /* Setup common locations */
64 typeAttribute
= ss
.getQuarkAbsoluteAndAdd(Attributes
.EVENT_TYPES
);
68 protected void eventHandle(ITmfEvent event
) {
71 /* Since this can be used for any trace types, normalize all the
72 * timestamp values to nanoseconds. */
73 final long ts
= event
.getTimestamp().normalize(0, -9).getValue();
75 final String eventName
= event
.getType().getName();
79 /* Total number of events */
80 quark
= ss
.getQuarkAbsoluteAndAdd(Attributes
.TOTAL
);
81 ss
.incrementAttribute(ts
, quark
);
83 /* Number of events of each type, globally */
84 quark
= ss
.getQuarkRelativeAndAdd(typeAttribute
, eventName
);
85 ss
.incrementAttribute(ts
, quark
);
87 // /* Number of events per CPU */
88 // quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.STATISTICS, Attributes.EVENT_TYPES, eventName);
89 // ss.incrementAttribute(ts, quark);
91 // /* Number of events per process */
92 // quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.STATISTICS, Attributes.EVENT_TYPES, eventName);
93 // ss.incrementAttribute(ts, quark);
95 } catch (StateValueTypeException e
) {
97 } catch (TimeRangeException e
) {
99 } catch (AttributeNotFoundException e
) {