tmf: Update statistics providers to handle TmfLostEvents
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Tue, 9 Jul 2013 22:40:43 +0000 (18:40 -0400)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Tue, 3 Sep 2013 17:51:39 +0000 (13:51 -0400)
We do not want to count the "lost" events in the events total,
but it's interesting to show them like any other event type.

refs bug #408373.

Change-Id: I70956a78a2fb150fe47f259b4136332f705ef147
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/14519
Tested-by: Hudson CI
IP-Clean: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/Messages.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/StatsStateProvider.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfEventsStatistics.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/messages.properties [new file with mode: 0644]

diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/Messages.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/Messages.java
new file mode 100644 (file)
index 0000000..dd629f5
--- /dev/null
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Alexandre Montplaisir - Initial API and Implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.statistics;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ * Messages file for statistics view strings.
+ *
+ * @author Alexandre Montplaisir
+ * @since 2.1
+ */
+public class Messages extends NLS {
+
+    private static final String BUNDLE_NAME = "org.eclipse.linuxtools.tmf.core.statistics.messages"; //$NON-NLS-1$
+
+    static {
+        NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+    }
+
+    private Messages() {}
+
+    /** String for the name "Lost events" (displayed in the Statistics View) */
+    public static String LostEventsName;
+}
index b7d0eb32ee9fb29a7a8fd89ed297d8e92ffea043..33aeba117f466dd10ae9b24cdfcde60b70ef90fa 100644 (file)
 package org.eclipse.linuxtools.tmf.core.statistics;
 
 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.core.event.ITmfLostEvent;
 import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException;
 import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException;
 import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException;
 import org.eclipse.linuxtools.tmf.core.statesystem.AbstractTmfStateProvider;
+import org.eclipse.linuxtools.tmf.core.statevalue.TmfStateValue;
 import org.eclipse.linuxtools.tmf.core.statistics.TmfStateStatistics.Attributes;
 import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
@@ -48,7 +50,7 @@ class StatsStateProvider extends AbstractTmfStateProvider {
      * Version number of this input handler. Please bump this if you modify the
      * contents of the generated state history in some way.
      */
-    private static final int VERSION = 0;
+    private static final int VERSION = 1;
 
     /**
      * Constructor
@@ -81,6 +83,18 @@ class StatsStateProvider extends AbstractTmfStateProvider {
         final String eventName = event.getType().getName();
 
         try {
+            /* Special handling for lost events */
+            if (event instanceof ITmfLostEvent) {
+                ITmfLostEvent le = (ITmfLostEvent) event;
+                quark = ss.getQuarkAbsoluteAndAdd(Attributes.EVENT_TYPES, Messages.LostEventsName);
+
+                int curVal = ss.queryOngoingState(quark).unboxInt();
+                if (curVal == -1) { curVal = 0; }
+
+                TmfStateValue value = TmfStateValue.newValueInt((int) (curVal + le.getNbLostEvents()));
+                ss.modifyAttribute(ts, value, quark);
+                return;
+            }
 
             /* Total number of events */
             quark = ss.getQuarkAbsoluteAndAdd(Attributes.TOTAL);
index b47a6a9c8cd90a505fb2d656ce585032a47013fa..87a817d273f7802286eb99f6332aafda96da15a3 100644 (file)
@@ -20,6 +20,7 @@ import java.util.Map;
 import java.util.TreeMap;
 
 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.core.event.ITmfLostEvent;
 import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest;
 import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest;
 import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest;
@@ -235,10 +236,8 @@ public class TmfEventsStatistics implements ITmfStatistics {
         @Override
         public void handleData(final ITmfEvent event) {
             super.handleData(event);
-            if (event != null) {
-                if (event.getTrace() == trace) {
-                    total += 1;
-                }
+            if (!(event instanceof ITmfLostEvent) && event.getTrace() == trace) {
+                total += 1;
             }
         }
     }
@@ -265,20 +264,29 @@ public class TmfEventsStatistics implements ITmfStatistics {
         @Override
         public void handleData(final ITmfEvent event) {
             super.handleData(event);
-            if (event != null) {
-                if (event.getTrace() == trace) {
-                    processEvent(event);
+            if (event != null && event.getTrace() == trace) {
+                /*
+                 * Special handling for lost events: instead of counting just
+                 * one, we will count how many actual events it represents.
+                 */
+                if (event instanceof ITmfLostEvent) {
+                    ITmfLostEvent le = (ITmfLostEvent) event;
+                    incrementStats(Messages.LostEventsName, le.getNbLostEvents());
+                    return;
                 }
+
+                /* For standard event types, just increment by one */
+                String eventType = event.getType().getName();
+                incrementStats(eventType, 1L);
             }
         }
 
-        private void processEvent(ITmfEvent event) {
-            String eventType = event.getType().getName();
-            if (stats.containsKey(eventType)) {
-                long curValue = stats.get(eventType);
-                stats.put(eventType, curValue + 1L);
+        private void incrementStats(String key, long count) {
+            if (stats.containsKey(key)) {
+                long curValue = stats.get(key);
+                stats.put(key, curValue + count);
             } else {
-                stats.put(eventType, 1L);
+                stats.put(key, count);
             }
         }
     }
diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/messages.properties b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/messages.properties
new file mode 100644 (file)
index 0000000..263172a
--- /dev/null
@@ -0,0 +1,13 @@
+###############################################################################
+# Copyright (c) 2013 Ericsson
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+#     Alexandre Montplaisir - Initial API and implementation
+###############################################################################
+
+LostEventsName = Lost events
This page took 0.029505 seconds and 5 git commands to generate.