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