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