tmf: Split the state system in a separate plugin
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / statistics / TmfStatisticsTotalsModule.java
CommitLineData
8192f2c6 1/*******************************************************************************
60ae41e1 2 * Copyright (c) 2013, 2014 Ericsson
8192f2c6
AM
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
13package org.eclipse.linuxtools.tmf.core.statistics;
14
bcec0116
AM
15import org.eclipse.linuxtools.statesystem.core.exceptions.AttributeNotFoundException;
16import org.eclipse.linuxtools.statesystem.core.exceptions.StateValueTypeException;
17import org.eclipse.linuxtools.statesystem.core.exceptions.TimeRangeException;
8192f2c6
AM
18import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
19import org.eclipse.linuxtools.tmf.core.event.ITmfLostEvent;
8192f2c6
AM
20import org.eclipse.linuxtools.tmf.core.statesystem.AbstractTmfStateProvider;
21import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateProvider;
22import org.eclipse.linuxtools.tmf.core.statesystem.TmfStateSystemAnalysisModule;
23import org.eclipse.linuxtools.tmf.core.statistics.TmfStateStatistics.Attributes;
24import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
25import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
26
27/**
28 * The analysis module building the "totals" statistics state system.
29 *
30 * It is not in the extension point (and as such, not registered in the
31 * TmfAnalysisManager), as it is being handled by the TmfStatisticsModule.
32 *
33 * @author Alexandre Montplaisir
34 * @since 3.0
35 */
36public class TmfStatisticsTotalsModule extends TmfStateSystemAnalysisModule {
37
38 /**
39 * The ID of this analysis module (which is also the ID of the state system)
40 */
41 public static final String ID = "org.eclipse.linuxtools.tmf.statistics.totals"; //$NON-NLS-1$
42
43 private static final String NAME = "TMF Statistics, event totals"; //$NON-NLS-1$
44
45 /**
46 * Constructor
47 */
48 public TmfStatisticsTotalsModule() {
49 setId(ID);
50 setName(NAME);
51 }
52
53 @Override
54 protected ITmfStateProvider createStateProvider() {
55 return new StatsProviderTotals(getTrace());
56 }
57
8192f2c6
AM
58 @Override
59 protected String getSsFileName() {
60 return "statistics-totals.ht"; //$NON-NLS-1$
61 }
62
63
64 /**
65 * The state provider for traces statistics that use TmfStateStatistics. It
66 * should work with any trace type for which we can use the state system.
67 *
68 * Only one attribute will be stored, containing the total of events seen so
69 * far. The resulting attribute tree will look like this:
70 *
71 * <pre>
72 * (root)
73 * \-- total
74 * </pre>
75 *
76 * @author Alexandre Montplaisir
77 * @version 1.0
78 */
79 class StatsProviderTotals extends AbstractTmfStateProvider {
80
81 /**
82 * Version number of this input handler. Please bump this if you modify the
83 * contents of the generated state history in some way.
84 */
85 private static final int VERSION = 2;
86
87 /**
88 * Constructor
89 *
90 * @param trace
91 * The trace for which we build this state system
92 */
93 public StatsProviderTotals(ITmfTrace trace) {
94 super(trace, ITmfEvent.class , NAME);
95 }
96
97 @Override
98 public int getVersion() {
99 return VERSION;
100 }
101
102 @Override
103 public StatsProviderTotals getNewInstance() {
104 return new StatsProviderTotals(this.getTrace());
105 }
106
107 @Override
108 protected void eventHandle(ITmfEvent event) {
109 /* Do not count lost events in the total */
110 if (event instanceof ITmfLostEvent) {
111 return;
112 }
113
114 /* Since this can be used for any trace types, normalize all the
115 * timestamp values to nanoseconds. */
116 final long ts = event.getTimestamp().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
117
118 try {
119 /* Total number of events */
120 int quark = ss.getQuarkAbsoluteAndAdd(Attributes.TOTAL);
121 ss.incrementAttribute(ts, quark);
122
123 } catch (StateValueTypeException | TimeRangeException | AttributeNotFoundException e) {
124 e.printStackTrace();
125 }
126 }
127 }
128
129}
This page took 0.035254 seconds and 5 git commands to generate.