894e9f500db546d3a5b5b28f347d2ae53e240a40
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / statistics / StatsProviderTotals.java
1 /*******************************************************************************
2 * Copyright (c) 2012, 2013 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 * Patrick Tasse - Fix javadoc
12 ******************************************************************************/
13
14 package org.eclipse.linuxtools.tmf.core.statistics;
15
16 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
17 import org.eclipse.linuxtools.tmf.core.event.ITmfLostEvent;
18 import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException;
19 import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException;
20 import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException;
21 import org.eclipse.linuxtools.tmf.core.statesystem.AbstractTmfStateProvider;
22 import org.eclipse.linuxtools.tmf.core.statistics.TmfStateStatistics.Attributes;
23 import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
24 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
25
26 /**
27 * The state provider for traces statistics that use TmfStateStatistics. It
28 * should work with any trace type for which we can use the state system.
29 *
30 * Only one attribute will be stored, containing the total of events seen so
31 * far. The resulting attribute tree will look like this:
32 *
33 * <pre>
34 * (root)
35 * \-- total
36 * </pre>
37 *
38 * @author Alexandre Montplaisir
39 * @version 1.0
40 */
41 class StatsProviderTotals extends AbstractTmfStateProvider {
42
43 /**
44 * Version number of this input handler. Please bump this if you modify the
45 * contents of the generated state history in some way.
46 */
47 private static final int VERSION = 2;
48
49 /**
50 * Constructor
51 *
52 * @param trace
53 * The trace for which we build this state system
54 */
55 public StatsProviderTotals(ITmfTrace trace) {
56 super(trace, ITmfEvent.class ,"TMF Statistics, event totals"); //$NON-NLS-1$
57 }
58
59 @Override
60 public int getVersion() {
61 return VERSION;
62 }
63
64 @Override
65 public StatsProviderTotals getNewInstance() {
66 return new StatsProviderTotals(this.getTrace());
67 }
68
69 @Override
70 protected void eventHandle(ITmfEvent event) {
71 /* Do not count lost events in the total */
72 if (event instanceof ITmfLostEvent) {
73 return;
74 }
75
76 /* Since this can be used for any trace types, normalize all the
77 * timestamp values to nanoseconds. */
78 final long ts = event.getTimestamp().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
79
80 try {
81 /* Total number of events */
82 int quark = ss.getQuarkAbsoluteAndAdd(Attributes.TOTAL);
83 ss.incrementAttribute(ts, quark);
84
85 } catch (StateValueTypeException e) {
86 e.printStackTrace();
87 } catch (TimeRangeException e) {
88 e.printStackTrace();
89 } catch (AttributeNotFoundException e) {
90 e.printStackTrace();
91 }
92 }
93 }
This page took 0.041754 seconds and 4 git commands to generate.