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 * Alexandre Montplaisir - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.internal
.lttng2
.ust
.core
.trace
.callstack
;
15 import java
.util
.HashSet
;
18 import org
.eclipse
.linuxtools
.lttng2
.ust
.core
.trace
.LttngUstTrace
;
19 import org
.eclipse
.linuxtools
.tmf
.core
.callstack
.CallStackStateProvider
;
20 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfEvent
;
21 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEventField
;
25 * Callstack provider for LTTng-UST traces.
27 * If the traces contains 'func_entry' and 'func_exit' event (see the
28 * lttng-ust-cyg-profile manpage), AND contains vtid and procname contexts, we
29 * can use this information to populate the TMF Callstack View.
31 * Granted, most UST traces will not contain this information. In this case,
32 * this will simply build an empty state system, and the view will remain
35 * @author Alexandre Montplaisir
37 public class LttngUstCallStackProvider
extends CallStackStateProvider
{
39 // ------------------------------------------------------------------------
41 // ------------------------------------------------------------------------
43 /** Name of the fake field for the vtid contexts */
44 private static final String CONTEXT_VTID
= "context._vtid"; //$NON-NLS-1$
46 /** Name of the fake field for the procname context */
47 private static final String CONTEXT_PROCNAME
= "context._procname"; //$NON-NLS-1$
49 /** Field name for the target function address */
50 private static final String FIELD_ADDR
= "addr"; //$NON-NLS-1$
52 /** Event names indicating function entry */
53 private static final Set
<String
> FUNC_ENTRY_EVENTS
= new HashSet
<String
>();
55 /** Event names indicating function exit */
56 private static final Set
<String
> FUNC_EXIT_EVENTS
= new HashSet
<String
>();
59 /* This seems overkill, but it will be checked every event. Gotta go FAST! */
60 FUNC_ENTRY_EVENTS
.add("lttng_ust_cyg_profile:func_entry"); //$NON-NLS-1$
61 FUNC_ENTRY_EVENTS
.add("lttng_ust_cyg_profile_fast:func_entry"); //$NON-NLS-1$
63 FUNC_EXIT_EVENTS
.add("lttng_ust_cyg_profile:func_exit"); //$NON-NLS-1$
64 FUNC_EXIT_EVENTS
.add("lttng_ust_cyg_profile_fast:func_exit"); //$NON-NLS-1$
67 // ------------------------------------------------------------------------
69 // ------------------------------------------------------------------------
77 public LttngUstCallStackProvider(LttngUstTrace trace
) {
81 // ------------------------------------------------------------------------
82 // Methods from AbstractTmfStateProvider
83 // ------------------------------------------------------------------------
86 public LttngUstTrace
getTrace() {
87 /* Type is enforced by the constructor */
88 return (LttngUstTrace
) super.getTrace();
92 public LttngUstCallStackProvider
getNewInstance() {
93 return new LttngUstCallStackProvider(getTrace());
96 // ------------------------------------------------------------------------
97 // Methods from CallStackStateProvider
98 // ------------------------------------------------------------------------
101 * Check that this event contains the required information we need to be
102 * used in the call stack view. We need at least the "procname" and "vtid"
106 protected boolean considerEvent(ITmfEvent event
) {
107 if (!(event
instanceof CtfTmfEvent
)) {
110 ITmfEventField content
= ((CtfTmfEvent
) event
).getContent();
111 if (content
.getField(CONTEXT_VTID
) == null ||
112 content
.getField(CONTEXT_PROCNAME
) == null) {
119 public String
functionEntry(ITmfEvent event
) {
120 String eventName
= ((CtfTmfEvent
) event
).getEventName();
121 if (!FUNC_ENTRY_EVENTS
.contains(eventName
)) {
124 Long address
= (Long
) event
.getContent().getField(FIELD_ADDR
).getValue();
125 return getFunctionNameFromAddress(address
.longValue());
129 public String
functionExit(ITmfEvent event
) {
130 String eventName
= ((CtfTmfEvent
) event
).getEventName();
131 if (!FUNC_EXIT_EVENTS
.contains(eventName
)) {
135 * The 'addr' field may or may not be present in func_exit events,
136 * depending on if cyg-profile.so or cyg-profile-fast.so was used.
138 ITmfEventField field
= event
.getContent().getField(FIELD_ADDR
);
140 return CallStackStateProvider
.UNDEFINED
;
142 Long address
= (Long
) field
.getValue();
143 return getFunctionNameFromAddress(address
.longValue());
147 public String
getThreadName(ITmfEvent event
) {
148 /* Class type and content was already checked if we get called here */
149 ITmfEventField content
= ((CtfTmfEvent
) event
).getContent();
150 String procName
= (String
) content
.getField(CONTEXT_PROCNAME
).getValue();
151 Long vtid
= (Long
) content
.getField(CONTEXT_VTID
).getValue();
153 if (procName
== null || vtid
== null) {
154 throw new IllegalStateException();
157 return new String(procName
+ '-' + vtid
.toString());
160 // ------------------------------------------------------------------------
161 // Internal helper methods
162 // ------------------------------------------------------------------------
164 private static String
getFunctionNameFromAddress(long address
) {
166 * We do not support getting the real function name yet, just print the
169 return new String("0x" + Long
.toHexString(address
)); //$NON-NLS-1$