From ad86291c91a5989781bb68582088535ed8433b98 Mon Sep 17 00:00:00 2001 From: Alexandre Montplaisir Date: Wed, 18 Jul 2012 14:52:30 -0400 Subject: [PATCH] lttng: Drop the current node arrays in the the event handler 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 --- .../core/stateprovider/CtfKernelHandler.java | 68 +++++++------------ 1 file changed, 24 insertions(+), 44 deletions(-) diff --git a/org.eclipse.linuxtools.lttng2.kernel.core/src/org/eclipse/linuxtools/internal/lttng2/kernel/core/stateprovider/CtfKernelHandler.java b/org.eclipse.linuxtools.lttng2.kernel.core/src/org/eclipse/linuxtools/internal/lttng2/kernel/core/stateprovider/CtfKernelHandler.java index 453b7f1f68..157014140f 100644 --- a/org.eclipse.linuxtools.lttng2.kernel.core/src/org/eclipse/linuxtools/internal/lttng2/kernel/core/stateprovider/CtfKernelHandler.java +++ b/org.eclipse.linuxtools.lttng2.kernel.core/src/org/eclipse/linuxtools/internal/lttng2/kernel/core/stateprovider/CtfKernelHandler.java @@ -2,19 +2,17 @@ * Copyright (c) 2012 Ericsson * Copyright (c) 2010, 2011 École Polytechnique de Montréal * Copyright (c) 2010, 2011 Alexandre Montplaisir - * + * * 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 currentCPUNodes; - List currentThreadNodes; - /* Event names HashMap. TODO: This can be discarded once we move to Java 7 */ private final HashMap knownEventNames; @@ -61,8 +52,6 @@ class CtfKernelHandler implements Runnable { CtfKernelHandler(BlockingQueue eventsQueue) { assert (eventsQueue != null); this.inQueue = eventsQueue; - currentCPUNodes = new ArrayList(); - currentThreadNodes = new ArrayList(); 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 { /** * Similar logic as above, but to set the CPU's status when it's coming out * of an interruption. - * @throws AttributeNotFoundException - * @throws StateValueTypeException - * @throws TimeRangeException + * @throws AttributeNotFoundException + * @throws StateValueTypeException + * @throws TimeRangeException */ private void cpuExitInterrupt(long ts, int currentCpuNode, int currentThreadNode) throws StateValueTypeException, AttributeNotFoundException, -- 2.34.1