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
.event
.ITmfTimestamp
;
17 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.AttributeNotFoundException
;
18 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.StateValueTypeException
;
19 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TimeRangeException
;
20 import org
.eclipse
.linuxtools
.tmf
.core
.statesystem
.AbstractStateChangeInput
;
21 import org
.eclipse
.linuxtools
.tmf
.core
.statesystem
.ITmfStateSystemBuilder
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.statistics
.TmfStateStatistics
.Attributes
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
26 * The state provider for traces statistics that use TmfStateStatistics. It
27 * should work with any trace type for which we can use the state system.
29 * The resulting attribute tree will look like this:
39 * And each <event name>'s value will be an integer, representing how many times
40 * this particular event type has been seen in the trace so far.
42 * @author Alexandre Montplaisir
45 class StatsStateProvider
extends AbstractStateChangeInput
{
47 /* Commonly-used attributes */
48 private int typeAttribute
= -1;
54 * The trace for which we build this state system
56 public StatsStateProvider(ITmfTrace trace
) {
57 super(trace
, ITmfEvent
.class ,"TMF Statistics"); //$NON-NLS-1$
61 public void assignTargetStateSystem(ITmfStateSystemBuilder ssb
) {
62 super.assignTargetStateSystem(ssb
);
64 /* Setup common locations */
65 typeAttribute
= ss
.getQuarkAbsoluteAndAdd(Attributes
.EVENT_TYPES
);
69 protected void eventHandle(ITmfEvent event
) {
72 /* Since this can be used for any trace types, normalize all the
73 * timestamp values to nanoseconds. */
74 final long ts
= event
.getTimestamp().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
76 final String eventName
= event
.getType().getName();
80 /* Total number of events */
81 quark
= ss
.getQuarkAbsoluteAndAdd(Attributes
.TOTAL
);
82 ss
.incrementAttribute(ts
, quark
);
84 /* Number of events of each type, globally */
85 quark
= ss
.getQuarkRelativeAndAdd(typeAttribute
, eventName
);
86 ss
.incrementAttribute(ts
, quark
);
88 // /* Number of events per CPU */
89 // quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.STATISTICS, Attributes.EVENT_TYPES, eventName);
90 // ss.incrementAttribute(ts, quark);
92 // /* Number of events per process */
93 // quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.STATISTICS, Attributes.EVENT_TYPES, eventName);
94 // ss.incrementAttribute(ts, quark);
96 } catch (StateValueTypeException e
) {
98 } catch (TimeRangeException e
) {
100 } catch (AttributeNotFoundException e
) {