1 /*******************************************************************************
2 * Copyright (c) 2013, 2015 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 * Patrick Tasse - Add support for thread id
12 *******************************************************************************/
14 package org
.eclipse
.tracecompass
.internal
.lttng2
.ust
.core
.trace
.callstack
;
16 import java
.util
.HashSet
;
19 import org
.eclipse
.jdt
.annotation
.NonNull
;
20 import org
.eclipse
.tracecompass
.tmf
.core
.callstack
.CallStackStateProvider
;
21 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
22 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEventField
;
23 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
24 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.event
.CtfTmfEvent
;
27 * Callstack provider for LTTng-UST traces.
29 * If the traces contains 'func_entry' and 'func_exit' event (see the
30 * lttng-ust-cyg-profile manpage), AND contains vtid and procname contexts, we
31 * can use this information to populate the TMF Callstack View.
33 * Granted, most UST traces will not contain this information. In this case,
34 * this will simply build an empty state system, and the view will remain
37 * @author Alexandre Montplaisir
39 public class LttngUstCallStackProvider
extends CallStackStateProvider
{
41 // ------------------------------------------------------------------------
43 // ------------------------------------------------------------------------
45 /** Name of the fake field for the vtid contexts */
46 private static final String CONTEXT_VTID
= "context._vtid"; //$NON-NLS-1$
48 /** Name of the fake field for the procname context */
49 private static final String CONTEXT_PROCNAME
= "context._procname"; //$NON-NLS-1$
51 /** Field name for the target function address */
52 private static final String FIELD_ADDR
= "addr"; //$NON-NLS-1$
54 /** Event names indicating function entry */
55 private static final Set
<String
> FUNC_ENTRY_EVENTS
= new HashSet
<>();
57 /** Event names indicating function exit */
58 private static final Set
<String
> FUNC_EXIT_EVENTS
= new HashSet
<>();
61 /* This seems overkill, but it will be checked every event. Gotta go FAST! */
62 FUNC_ENTRY_EVENTS
.add("lttng_ust_cyg_profile:func_entry"); //$NON-NLS-1$
63 FUNC_ENTRY_EVENTS
.add("lttng_ust_cyg_profile_fast:func_entry"); //$NON-NLS-1$
65 FUNC_EXIT_EVENTS
.add("lttng_ust_cyg_profile:func_exit"); //$NON-NLS-1$
66 FUNC_EXIT_EVENTS
.add("lttng_ust_cyg_profile_fast:func_exit"); //$NON-NLS-1$
70 * Version number of this state provider. Please bump this if you modify
71 * the contents of the generated state history in some way.
73 private static final int VERSION
= 2;
75 // ------------------------------------------------------------------------
77 // ------------------------------------------------------------------------
85 public LttngUstCallStackProvider(@NonNull ITmfTrace trace
) {
89 // ------------------------------------------------------------------------
90 // Methods from AbstractTmfStateProvider
91 // ------------------------------------------------------------------------
94 public LttngUstCallStackProvider
getNewInstance() {
95 return new LttngUstCallStackProvider(getTrace());
99 public int getVersion() {
103 // ------------------------------------------------------------------------
104 // Methods from CallStackStateProvider
105 // ------------------------------------------------------------------------
108 * Check that this event contains the required information we need to be
109 * used in the call stack view. We need at least the "procname" and "vtid"
113 protected boolean considerEvent(ITmfEvent event
) {
114 if (!(event
instanceof CtfTmfEvent
)) {
117 ITmfEventField content
= ((CtfTmfEvent
) event
).getContent();
118 if (content
.getField(CONTEXT_VTID
) == null ||
119 content
.getField(CONTEXT_PROCNAME
) == null) {
126 public String
functionEntry(ITmfEvent event
) {
127 String eventName
= event
.getName();
128 if (!FUNC_ENTRY_EVENTS
.contains(eventName
)) {
131 Long address
= (Long
) event
.getContent().getField(FIELD_ADDR
).getValue();
132 return Long
.toHexString(address
);
136 public String
functionExit(ITmfEvent event
) {
137 String eventName
= event
.getName();
138 if (!FUNC_EXIT_EVENTS
.contains(eventName
)) {
142 * The 'addr' field may or may not be present in func_exit events,
143 * depending on if cyg-profile.so or cyg-profile-fast.so was used.
145 ITmfEventField field
= event
.getContent().getField(FIELD_ADDR
);
147 return CallStackStateProvider
.UNDEFINED
;
149 Long address
= (Long
) field
.getValue();
150 return Long
.toHexString(address
);
154 public String
getThreadName(ITmfEvent event
) {
155 /* Class type and content was already checked if we get called here */
156 ITmfEventField content
= ((CtfTmfEvent
) event
).getContent();
157 String procName
= (String
) content
.getField(CONTEXT_PROCNAME
).getValue();
158 Long vtid
= (Long
) content
.getField(CONTEXT_VTID
).getValue();
160 if (procName
== null || vtid
== null) {
161 throw new IllegalStateException();
164 return new String(procName
+ '-' + vtid
.toString());
168 protected Long
getThreadId(ITmfEvent event
) {
169 ITmfEventField content
= ((CtfTmfEvent
) event
).getContent();
170 return (Long
) content
.getField(CONTEXT_VTID
).getValue();