1 /*******************************************************************************
2 * Copyright (c) 2013 Ericsson
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
10 * Alexandre Montplaisir - Initial API and implementation
11 ******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.core
.statistics
;
15 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
16 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfLostEvent
;
17 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.AttributeNotFoundException
;
18 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.StateValueTypeException
;
19 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TimeRangeException
;
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
;
28 * The analysis module building the "totals" statistics state system.
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.
33 * @author Alexandre Montplaisir
36 public class TmfStatisticsTotalsModule
extends TmfStateSystemAnalysisModule
{
39 * The ID of this analysis module (which is also the ID of the state system)
41 public static final String ID
= "org.eclipse.linuxtools.tmf.statistics.totals"; //$NON-NLS-1$
43 private static final String NAME
= "TMF Statistics, event totals"; //$NON-NLS-1$
48 public TmfStatisticsTotalsModule() {
54 protected ITmfStateProvider
createStateProvider() {
55 return new StatsProviderTotals(getTrace());
59 protected String
getSsFileName() {
60 return "statistics-totals.ht"; //$NON-NLS-1$
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.
68 * Only one attribute will be stored, containing the total of events seen so
69 * far. The resulting attribute tree will look like this:
76 * @author Alexandre Montplaisir
79 class StatsProviderTotals
extends AbstractTmfStateProvider
{
82 * Version number of this input handler. Please bump this if you modify the
83 * contents of the generated state history in some way.
85 private static final int VERSION
= 2;
91 * The trace for which we build this state system
93 public StatsProviderTotals(ITmfTrace trace
) {
94 super(trace
, ITmfEvent
.class , NAME
);
98 public int getVersion() {
103 public StatsProviderTotals
getNewInstance() {
104 return new StatsProviderTotals(this.getTrace());
108 protected void eventHandle(ITmfEvent event
) {
109 /* Do not count lost events in the total */
110 if (event
instanceof ITmfLostEvent
) {
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();
119 /* Total number of events */
120 int quark
= ss
.getQuarkAbsoluteAndAdd(Attributes
.TOTAL
);
121 ss
.incrementAttribute(ts
, quark
);
123 } catch (StateValueTypeException
| TimeRangeException
| AttributeNotFoundException e
) {