Fix left-over merge conflicts
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / callstack / CallStackStateProvider.java
CommitLineData
e8251298
PT
1/*******************************************************************************
2 * Copyright (c) 2013 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
12
13package org.eclipse.linuxtools.tmf.core.callstack;
14
15import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
16import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException;
17import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException;
18import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException;
0fe46f2a 19import org.eclipse.linuxtools.tmf.core.statesystem.AbstractTmfStateProvider;
e8251298
PT
20import org.eclipse.linuxtools.tmf.core.statevalue.ITmfStateValue;
21import org.eclipse.linuxtools.tmf.core.statevalue.TmfStateValue;
22import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
23import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
24
25/**
26 * The state provider for traces that support the Call Stack view.
27 *
28 * The attribute tree should have the following structure:
29 *<pre>
30 * (root)
31 * \-- Threads
32 * |-- (Thread 1)
33 * | \-- CallStack (stack-attribute)
34 * | |-- 1
35 * | |-- 2
36 * | ...
37 * | \-- n
38 * |-- (Thread 2)
39 * | \-- CallStack (stack-attribute)
40 * | |-- 1
41 * | |-- 2
42 * | ...
43 * | \-- n
44 * ...
45 * \-- (Thread n)
46 * \-- CallStack (stack-attribute)
47 * |-- 1
48 * |-- 2
49 * ...
50 * \-- n
51 *</pre>
52 * where:
53 * <br>
54 * (Thread n) is an attribute whose name is the name of the thread
55 * <br>
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.
59 *
60 * @author Patrick Tasse
61 * @since 2.0
62 */
0fe46f2a 63public abstract class CallStackStateProvider extends AbstractTmfStateProvider {
e8251298
PT
64
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$
73
74 /**
75 * Version number of this state provider. Please bump this if you modify
76 * the contents of the generated state history in some way.
77 */
78 private static final int VERSION = 0;
79
80 /**
81 * Default constructor
82 *
83 * @param trace
84 * The trace for which we build this state system
85 */
86 public CallStackStateProvider(ITmfTrace trace) {
87 super(trace, ITmfEvent.class, ID);
88 }
89
90 @Override
91 public int getVersion() {
92 return VERSION;
93 }
94
95 @Override
96 protected void eventHandle(ITmfEvent event) {
97 String functionEntryName = functionEntry(event);
98 try {
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);
110 }
111 } catch (TimeRangeException e) {
112 e.printStackTrace();
113 } catch (AttributeNotFoundException e) {
114 e.printStackTrace();
115 } catch (StateValueTypeException e) {
116 e.printStackTrace();
117 }
118 }
119
120 /**
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.
124 */
125 public abstract String functionEntry(ITmfEvent event);
126
127 /**
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.
131 */
132 public abstract String functionExit(ITmfEvent event);
133
134 /**
135 * Return the thread name for a function entry or exit event
136 * @param event an event
137 * @return the thread name
138 */
139 public abstract String threadName(ITmfEvent event);
140}
This page took 0.029939 seconds and 5 git commands to generate.