tmf: Add support for versioning state input plugins
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / statistics / StatsStateProvider.java
1 /*******************************************************************************
2 * Copyright (c) 2012 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.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.timestamp.ITmfTimestamp;
23 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
24
25 /**
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.
28 *
29 * The resulting attribute tree will look like this:
30 *
31 * <root>
32 * |-- total
33 * \-- event_types
34 * |-- <event name 1>
35 * |-- <event name 2>
36 * |-- <event name 3>
37 * ...
38 *
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.
41 *
42 * @author Alexandre Montplaisir
43 * @version 1.0
44 */
45 class StatsStateProvider extends AbstractStateChangeInput {
46
47 /**
48 * Version number of this input handler. Please bump this if you modify the
49 * contents of the generated state history in some way.
50 */
51 private static final int VERSION = 0;
52
53 /* Commonly-used attributes */
54 private int typeAttribute = -1;
55
56 /**
57 * Constructor
58 *
59 * @param trace
60 * The trace for which we build this state system
61 */
62 public StatsStateProvider(ITmfTrace trace) {
63 super(trace, ITmfEvent.class ,"TMF Statistics"); //$NON-NLS-1$
64 }
65
66 @Override
67 public int getVersion() {
68 return VERSION;
69 }
70
71 @Override
72 public void assignTargetStateSystem(ITmfStateSystemBuilder ssb) {
73 super.assignTargetStateSystem(ssb);
74
75 /* Setup common locations */
76 typeAttribute = ss.getQuarkAbsoluteAndAdd(Attributes.EVENT_TYPES);
77 }
78
79 @Override
80 protected void eventHandle(ITmfEvent event) {
81 int quark;
82
83 /* Since this can be used for any trace types, normalize all the
84 * timestamp values to nanoseconds. */
85 final long ts = event.getTimestamp().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
86
87 final String eventName = event.getType().getName();
88
89 try {
90
91 /* Total number of events */
92 quark = ss.getQuarkAbsoluteAndAdd(Attributes.TOTAL);
93 ss.incrementAttribute(ts, quark);
94
95 /* Number of events of each type, globally */
96 quark = ss.getQuarkRelativeAndAdd(typeAttribute, eventName);
97 ss.incrementAttribute(ts, quark);
98
99 // /* Number of events per CPU */
100 // quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.STATISTICS, Attributes.EVENT_TYPES, eventName);
101 // ss.incrementAttribute(ts, quark);
102 //
103 // /* Number of events per process */
104 // quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.STATISTICS, Attributes.EVENT_TYPES, eventName);
105 // ss.incrementAttribute(ts, quark);
106
107 } catch (StateValueTypeException e) {
108 e.printStackTrace();
109 } catch (TimeRangeException e) {
110 e.printStackTrace();
111 } catch (AttributeNotFoundException e) {
112 e.printStackTrace();
113 }
114 }
115 }
This page took 0.0349 seconds and 6 git commands to generate.