tmf: Statistics provider based on event requests
[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.trace.ITmfTrace;
23
24 /**
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.
27 *
28 * The resulting attribute tree will look like this:
29 *
30 * <root>
31 * |-- total
32 * \-- event_types
33 * |-- <event name 1>
34 * |-- <event name 2>
35 * |-- <event name 3>
36 * ...
37 *
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.
40 *
41 * @author Alexandre Montplaisir
42 * @version 1.0
43 */
44 class StatsStateProvider extends AbstractStateChangeInput {
45
46 /* Commonly-used attributes */
47 private int typeAttribute = -1;
48
49 /**
50 * Constructor
51 *
52 * @param trace
53 * The trace for which we build this state system
54 */
55 public StatsStateProvider(ITmfTrace trace) {
56 super(trace, ITmfEvent.class ,"TMF Statistics"); //$NON-NLS-1$
57 }
58
59 @Override
60 public void assignTargetStateSystem(ITmfStateSystemBuilder ssb) {
61 super.assignTargetStateSystem(ssb);
62
63 /* Setup common locations */
64 typeAttribute = ss.getQuarkAbsoluteAndAdd(Attributes.EVENT_TYPES);
65 }
66
67 @Override
68 protected void eventHandle(ITmfEvent event) {
69 int quark;
70
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();
74
75 final String eventName = event.getType().getName();
76
77 try {
78
79 /* Total number of events */
80 quark = ss.getQuarkAbsoluteAndAdd(Attributes.TOTAL);
81 ss.incrementAttribute(ts, quark);
82
83 /* Number of events of each type, globally */
84 quark = ss.getQuarkRelativeAndAdd(typeAttribute, eventName);
85 ss.incrementAttribute(ts, quark);
86
87 // /* Number of events per CPU */
88 // quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.STATISTICS, Attributes.EVENT_TYPES, eventName);
89 // ss.incrementAttribute(ts, quark);
90 //
91 // /* Number of events per process */
92 // quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.STATISTICS, Attributes.EVENT_TYPES, eventName);
93 // ss.incrementAttribute(ts, quark);
94
95 } catch (StateValueTypeException e) {
96 e.printStackTrace();
97 } catch (TimeRangeException e) {
98 e.printStackTrace();
99 } catch (AttributeNotFoundException e) {
100 e.printStackTrace();
101 }
102 }
103 }
This page took 0.032979 seconds and 5 git commands to generate.