ss: Move plugins to Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / callstack / CallStackStateProvider.java
index 9341b6953e6e548a71db96b42e4e3bc3a8ad39cc..54f02e3eac2c112fcf6b2cd80a6f95c9e79ba6be 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2013 Ericsson
+ * Copyright (c) 2013, 2014 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
 package org.eclipse.linuxtools.tmf.core.callstack;
 
 import org.eclipse.linuxtools.internal.tmf.core.Activator;
+import org.eclipse.linuxtools.statesystem.core.exceptions.AttributeNotFoundException;
+import org.eclipse.linuxtools.statesystem.core.exceptions.StateValueTypeException;
+import org.eclipse.linuxtools.statesystem.core.exceptions.TimeRangeException;
+import org.eclipse.linuxtools.statesystem.core.statevalue.ITmfStateValue;
+import org.eclipse.linuxtools.statesystem.core.statevalue.TmfStateValue;
 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
-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.ITmfStateValue;
-import org.eclipse.linuxtools.tmf.core.statevalue.TmfStateValue;
 import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
 import org.eclipse.osgi.util.NLS;
@@ -53,7 +53,8 @@ import org.eclipse.osgi.util.NLS;
  *</pre>
  * where:
  * <br>
- * (Thread n) is an attribute whose name is the name of the thread
+ * (Thread n) is an attribute whose name is the display name of the thread.
+ * Optionally, its value is a long representing the thread id, used for sorting.
  * <br>
  * CallStack is a stack-attribute whose pushed values are either a string,
  * int or long representing the function name or address in the call stack.
@@ -64,8 +65,6 @@ import org.eclipse.osgi.util.NLS;
  */
 public abstract class CallStackStateProvider extends AbstractTmfStateProvider {
 
-    /** CallStack state system ID */
-    public static final String ID = "org.eclipse.linuxtools.tmf.callstack"; //$NON-NLS-1$
     /** Thread attribute */
     public static final String THREADS = "Threads"; //$NON-NLS-1$
     /** CallStack stack-attribute */
@@ -73,6 +72,8 @@ public abstract class CallStackStateProvider extends AbstractTmfStateProvider {
     /** Undefined function exit name */
     public static final String UNDEFINED = "UNDEFINED"; //$NON-NLS-1$
 
+    /** CallStack state system ID */
+    private static final String ID = "org.eclipse.linuxtools.tmf.callstack"; //$NON-NLS-1$
     /** Dummy function name for when no function is expected */
     private static final String NO_FUNCTION = "no function"; //$NON-NLS-1$
 
@@ -97,9 +98,14 @@ public abstract class CallStackStateProvider extends AbstractTmfStateProvider {
             if (functionEntryName != null) {
                 long timestamp = event.getTimestamp().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
                 String thread = getThreadName(event);
-                int quark = ss.getQuarkAbsoluteAndAdd(THREADS, thread, CALL_STACK);
+                int threadQuark = ss.getQuarkAbsoluteAndAdd(THREADS, thread);
+                Long threadId = getThreadId(event);
+                if (threadId != null) {
+                    ss.updateOngoingState(TmfStateValue.newValueLong(threadId), threadQuark);
+                }
+                int callStackQuark = ss.getQuarkRelativeAndAdd(threadQuark, CALL_STACK);
                 ITmfStateValue value = TmfStateValue.newValueString(functionEntryName);
-                ss.pushAttribute(timestamp, value, quark);
+                ss.pushAttribute(timestamp, value, callStackQuark);
                 return;
             }
 
@@ -144,6 +150,7 @@ public abstract class CallStackStateProvider extends AbstractTmfStateProvider {
      *            The event to check
      * @return If false, the event will be ignored by the state provider. If
      *         true processing will continue.
+     * @since 3.0
      */
     protected abstract boolean considerEvent(ITmfEvent event);
 
@@ -173,6 +180,19 @@ public abstract class CallStackStateProvider extends AbstractTmfStateProvider {
      * @param event
      *            The event
      * @return The thread name (as will be shown in the view)
+     * @since 3.0
      */
     protected abstract String getThreadName(ITmfEvent event);
+
+    /**
+     * Return the thread id of a function entry event.
+     *
+     * @param event
+     *            The event
+     * @return The thread id, or null if undefined
+     * @since 3.1
+     */
+    protected Long getThreadId(ITmfEvent event) {
+        return null;
+    }
 }
This page took 0.026624 seconds and 5 git commands to generate.