1 /*******************************************************************************
2 * Copyright (c) 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 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.core
.callstack
;
15 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
16 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.AttributeNotFoundException
;
17 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.StateValueTypeException
;
18 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TimeRangeException
;
19 import org
.eclipse
.linuxtools
.tmf
.core
.statesystem
.AbstractStateChangeInput
;
20 import org
.eclipse
.linuxtools
.tmf
.core
.statevalue
.ITmfStateValue
;
21 import org
.eclipse
.linuxtools
.tmf
.core
.statevalue
.TmfStateValue
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.ITmfTimestamp
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
26 * The state provider for traces that support the Call Stack view.
28 * The attribute tree should have the following structure:
33 * | \-- CallStack (stack-attribute)
39 * | \-- CallStack (stack-attribute)
46 * \-- CallStack (stack-attribute)
54 * (Thread n) is an attribute whose name is the name of the thread
56 * CallStack is a stack-attribute whose pushed values are either a string,
57 * int or long representing the function name or address in the call stack.
58 * The type of value used must be constant for a particular CallStack.
60 * @author Patrick Tasse
63 public abstract class CallStackStateProvider
extends AbstractStateChangeInput
{
65 /** CallStack state system ID */
66 public static final String ID
= "org.eclipse.linuxtools.tmf.callstack"; //$NON-NLS-1$
67 /** Thread attribute */
68 public static final String THREADS
= "Threads"; //$NON-NLS-1$
69 /** CallStack stack-attribute */
70 public static final String CALL_STACK
= "CallStack"; //$NON-NLS-1$
71 /** Undefined function exit name */
72 public static final String UNDEFINED
= "UNDEFINED"; //$NON-NLS-1$
75 * Version number of this state provider. Please bump this if you modify
76 * the contents of the generated state history in some way.
78 private static final int VERSION
= 0;
84 * The trace for which we build this state system
86 public CallStackStateProvider(ITmfTrace trace
) {
87 super(trace
, ITmfEvent
.class, ID
);
91 public int getVersion() {
96 protected void eventHandle(ITmfEvent event
) {
97 String functionEntryName
= functionEntry(event
);
99 if (functionEntryName
!= null) {
100 long timestamp
= event
.getTimestamp().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
101 String thread
= threadName(event
);
102 int quark
= ss
.getQuarkAbsoluteAndAdd(THREADS
, thread
, CALL_STACK
);
103 ITmfStateValue value
= TmfStateValue
.newValueString(functionEntryName
);
104 ss
.pushAttribute(timestamp
, value
, quark
);
105 } else if (functionExit(event
) != null) {
106 long timestamp
= event
.getTimestamp().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
107 String thread
= threadName(event
);
108 int quark
= ss
.getQuarkAbsoluteAndAdd(THREADS
, thread
, CALL_STACK
);
109 ss
.popAttribute(timestamp
, quark
);
111 } catch (TimeRangeException e
) {
113 } catch (AttributeNotFoundException e
) {
115 } catch (StateValueTypeException e
) {
121 * Check an event for function entry
122 * @param event an event to check for function entry
123 * @return the function name for a function entry, or null otherwise.
125 public abstract String
functionEntry(ITmfEvent event
);
128 * Check an event for function exit
129 * @param event an event to check for function exit
130 * @return the function name or UNDEFINED for a function exit, or null otherwise.
132 public abstract String
functionExit(ITmfEvent event
);
135 * Return the thread name for a function entry or exit event
136 * @param event an event
137 * @return the thread name
139 public abstract String
threadName(ITmfEvent event
);