lttng: Drop the current node arrays in the the event handler
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Wed, 18 Jul 2012 18:52:30 +0000 (14:52 -0400)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Wed, 18 Jul 2012 19:01:19 +0000 (15:01 -0400)
Since we now use "common locations" shortcuts for commonly used
attributes in the tree, we don't really save much by caching
the quarks for all CPUs and all current running threads. This
was initally done as a performance optimization.

This commit drops the current*Nodes arrays that were populated
as new CPUs were seen while reading the trace. We will now get
the "current" pointers by doing standard state system queries.

If there is a performance impact, it's unnoticeable. I think it's
worth keeping this file as easy to understand as possible, since
it's often used as example for building an event handler.

Change-Id: Iedb3a13da837f3676c72f3c91edbd2e6960879a1
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
org.eclipse.linuxtools.lttng2.kernel.core/src/org/eclipse/linuxtools/internal/lttng2/kernel/core/stateprovider/CtfKernelHandler.java

index 453b7f1f68a81a0a23a40b676d57c48b83206e1c..157014140f968b6dd3b9e84d19b582d29f7b8504 100644 (file)
@@ -2,19 +2,17 @@
  * Copyright (c) 2012 Ericsson
  * Copyright (c) 2010, 2011 École Polytechnique de Montréal
  * Copyright (c) 2010, 2011 Alexandre Montplaisir <alexandre.montplaisir@gmail.com>
- * 
+ *
  * 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
- * 
+ *
  *******************************************************************************/
 
 package org.eclipse.linuxtools.internal.lttng2.kernel.core.stateprovider;
 
-import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.List;
 import java.util.concurrent.BlockingQueue;
 
 import org.eclipse.linuxtools.internal.lttng2.kernel.core.Attributes;
@@ -31,9 +29,9 @@ import org.eclipse.linuxtools.tmf.core.statevalue.TmfStateValue;
 
 /**
  * This is the reference "state provider" for LTTng 2.0 kernel traces.
- * 
+ *
  * @author alexmont
- * 
+ *
  */
 class CtfKernelHandler implements Runnable {
 
@@ -42,13 +40,6 @@ class CtfKernelHandler implements Runnable {
 
     private CtfTmfEvent currentEvent;
 
-    /*
-     * We can keep handles to some Attribute Nodes so these don't need to be
-     * re-found (re-hashed Strings etc.) every new event
-     */
-    List<Integer> currentCPUNodes;
-    List<Integer> currentThreadNodes;
-
     /* Event names HashMap. TODO: This can be discarded once we move to Java 7 */
     private final HashMap<String, Integer> knownEventNames;
 
@@ -61,8 +52,6 @@ class CtfKernelHandler implements Runnable {
     CtfKernelHandler(BlockingQueue<CtfTmfEvent> eventsQueue) {
         assert (eventsQueue != null);
         this.inQueue = eventsQueue;
-        currentCPUNodes = new ArrayList<Integer>();
-        currentThreadNodes = new ArrayList<Integer>();
 
         knownEventNames = fillEventNames();
     }
@@ -113,34 +102,28 @@ class CtfKernelHandler implements Runnable {
     }
 
     private void processEvent(CtfTmfEvent event) {
-        currentEvent = event;
-        ITmfEventField content = event.getContent();
-        String eventName = event.getEventName();
-
-        long ts = event.getTimestamp().getValue();
         int quark;
         ITmfStateValue value;
-        Integer eventCpu = event.getCPU();
-        Integer currentCPUNode, currentThreadNode;
-
-        /* Adjust the current nodes Vectors if we see a new CPU in an event */
-        if (eventCpu >= currentCPUNodes.size()) {
-            /* We need to add this node to the vector */
-            for (Integer i = currentCPUNodes.size(); i < eventCpu + 1; i++) {
-                quark = ss.getQuarkRelativeAndAdd(cpusNode, i.toString());
-                currentCPUNodes.add(quark);
-
-                quark = ss.getQuarkRelativeAndAdd(threadsNode, Attributes.UNKNOWN);
-                currentThreadNodes.add(quark);
-            }
-        }
 
-        currentCPUNode = currentCPUNodes.get(eventCpu);
-        currentThreadNode = currentThreadNodes.get(eventCpu);
-        assert (currentCPUNode != null);
-        assert (currentThreadNode != null);
+        currentEvent = event;
+
+        final ITmfEventField content = event.getContent();
+        final String eventName = event.getEventName();
+        final long ts = event.getTimestamp().getValue();
 
         try {
+            /* Shortcut for the "current CPU" attribute node */
+            final Integer currentCPUNode = ss.getQuarkRelativeAndAdd(cpusNode, String.valueOf(event.getCPU()));
+
+            /*
+             * Shortcut for the "current thread" attribute node. It requires
+             * querying the current CPU's current thread.
+             */
+            quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.CURRENT_THREAD);
+            value = ss.queryOngoingState(quark);
+            int thread = value.unboxInt();
+            final Integer currentThreadNode = ss.getQuarkRelativeAndAdd(threadsNode, String.valueOf(thread));
+
             /*
              * Feed event to the history system if it's known to cause a state
              * transition.
@@ -276,9 +259,6 @@ class CtfKernelHandler implements Runnable {
                 Integer formerThreadNode = ss.getQuarkRelativeAndAdd(threadsNode, prevTid.toString());
                 Integer newCurrentThreadNode = ss.getQuarkRelativeAndAdd(threadsNode, nextTid.toString());
 
-                /* Update the currentThreadNodes pointer */
-                currentThreadNodes.set(eventCpu, newCurrentThreadNode);
-
                 /* Set the status of the process that got scheduled out. */
                 quark = ss.getQuarkRelativeAndAdd(formerThreadNode, Attributes.STATUS);
                 value = TmfStateValue.newValueInt(StateValues.PROCESS_STATUS_WAIT);
@@ -531,9 +511,9 @@ class CtfKernelHandler implements Runnable {
     /**\r
      * Similar logic as above, but to set the CPU's status when it's coming out\r
      * of an interruption.\r
-     * @throws AttributeNotFoundException \r
-     * @throws StateValueTypeException \r
-     * @throws TimeRangeException \r
+     * @throws AttributeNotFoundException\r
+     * @throws StateValueTypeException\r
+     * @throws TimeRangeException\r
      */\r
     private void cpuExitInterrupt(long ts, int currentCpuNode, int currentThreadNode)\r
             throws StateValueTypeException, AttributeNotFoundException,\r
This page took 0.035056 seconds and 5 git commands to generate.