1 /*******************************************************************************
2 * Copyright (c) 2012, 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 * Patrick Tasse - Fix javadoc
12 ******************************************************************************/
14 package org
.eclipse
.linuxtools
.tmf
.core
.statistics
;
16 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
17 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfLostEvent
;
18 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.AttributeNotFoundException
;
19 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.StateValueTypeException
;
20 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TimeRangeException
;
21 import org
.eclipse
.linuxtools
.tmf
.core
.statesystem
.AbstractTmfStateProvider
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.statistics
.TmfStateStatistics
.Attributes
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.ITmfTimestamp
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
27 * The state provider for traces statistics that use TmfStateStatistics. It
28 * should work with any trace type for which we can use the state system.
30 * Only one attribute will be stored, containing the total of events seen so
31 * far. The resulting attribute tree will look like this:
38 * @author Alexandre Montplaisir
41 class StatsProviderTotals
extends AbstractTmfStateProvider
{
44 * Version number of this input handler. Please bump this if you modify the
45 * contents of the generated state history in some way.
47 private static final int VERSION
= 2;
53 * The trace for which we build this state system
55 public StatsProviderTotals(ITmfTrace trace
) {
56 super(trace
, ITmfEvent
.class ,"TMF Statistics, event totals"); //$NON-NLS-1$
60 public int getVersion() {
65 public StatsProviderTotals
getNewInstance() {
66 return new StatsProviderTotals(this.getTrace());
70 protected void eventHandle(ITmfEvent event
) {
71 /* Do not count lost events in the total */
72 if (event
instanceof ITmfLostEvent
) {
76 /* Since this can be used for any trace types, normalize all the
77 * timestamp values to nanoseconds. */
78 final long ts
= event
.getTimestamp().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
81 /* Total number of events */
82 int quark
= ss
.getQuarkAbsoluteAndAdd(Attributes
.TOTAL
);
83 ss
.incrementAttribute(ts
, quark
);
85 } catch (StateValueTypeException e
) {
87 } catch (TimeRangeException e
) {
89 } catch (AttributeNotFoundException e
) {