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