tmf: Introduce the ITmfStatistics interface
[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.TmfStatistics.Attributes;
22 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
23
24 /**
25 * The state provider for traces statistics. It should work with any type of
26 * trace TMF can handle.
27 *
28 * The resulting attribute tree will look like this:
29 *
30 * <root>
31 * \-- event_types
32 * |-- <event name 1>
33 * |-- <event name 2>
34 * |-- <event name 3>
35 * ...
36 *
37 * And each <event name>'s value will be an integer, representing how many times
38 * this particular event type has been seen in the trace so far.
39 *
40 * @author Alexandre Montplaisir
41 * @version 1.0
42 */
43 class StatsStateProvider extends AbstractStateChangeInput {
44
45 /* Commonly-used attributes */
46 private int typeAttribute = -1;
47
48 /**
49 * Constructor
50 *
51 * @param trace
52 * The trace for which we build this state system
53 */
54 public StatsStateProvider(ITmfTrace trace) {
55 super(trace, ITmfEvent.class ,"TMF Statistics"); //$NON-NLS-1$
56 }
57
58 @Override
59 public void assignTargetStateSystem(ITmfStateSystemBuilder ssb) {
60 super.assignTargetStateSystem(ssb);
61
62 /* Setup common locations */
63 typeAttribute = ss.getQuarkAbsoluteAndAdd(Attributes.EVENT_TYPES);
64 }
65
66 @Override
67 protected void eventHandle(ITmfEvent event) {
68 int quark;
69
70 final long ts = event.getTimestamp().getValue();
71 final String eventName = event.getType().getName();
72
73 try {
74
75 /* Number of events of each type, globally */
76 quark = ss.getQuarkRelativeAndAdd(typeAttribute, eventName);
77 ss.incrementAttribute(ts, quark);
78
79 // /* Number of events per CPU */
80 // quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.STATISTICS, Attributes.EVENT_TYPES, eventName);
81 // ss.incrementAttribute(ts, quark);
82 //
83 // /* Number of events per process */
84 // quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.STATISTICS, Attributes.EVENT_TYPES, eventName);
85 // ss.incrementAttribute(ts, quark);
86
87 } catch (StateValueTypeException e) {
88 e.printStackTrace();
89 } catch (TimeRangeException e) {
90 e.printStackTrace();
91 } catch (AttributeNotFoundException e) {
92 e.printStackTrace();
93 }
94 }
95 }
This page took 0.032404 seconds and 5 git commands to generate.