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