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
.callstack
;
18 import org
.eclipse
.jdt
.annotation
.NonNull
;
19 import org
.eclipse
.jdt
.annotation
.NonNullByDefault
;
20 import org
.eclipse
.jdt
.annotation
.Nullable
;
21 import org
.eclipse
.tracecompass
.internal
.lttng2
.ust
.core
.trace
.layout
.LttngUst20EventLayout
;
22 import org
.eclipse
.tracecompass
.lttng2
.ust
.core
.trace
.LttngUstTrace
;
23 import org
.eclipse
.tracecompass
.lttng2
.ust
.core
.trace
.layout
.ILttngUstEventLayout
;
24 import org
.eclipse
.tracecompass
.tmf
.core
.callstack
.CallStackStateProvider
;
25 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
26 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEventField
;
27 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
28 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.event
.CtfTmfEvent
;
30 import com
.google
.common
.collect
.ImmutableSet
;
33 * Callstack provider for LTTng-UST traces.
35 * If the traces contains 'func_entry' and 'func_exit' event (see the
36 * lttng-ust-cyg-profile manpage), AND contains vtid and procname contexts, we
37 * can use this information to populate the TMF Callstack View.
39 * Granted, most UST traces will not contain this information. In this case,
40 * this will simply build an empty state system, and the view will remain
43 * @author Alexandre Montplaisir
46 public class LttngUstCallStackProvider
extends CallStackStateProvider
{
49 * Version number of this state provider. Please bump this if you modify
50 * the contents of the generated state history in some way.
52 private static final int VERSION
= 3;
54 /** Event names indicating function entry */
55 private final Set
<String
> funcEntryEvents
;
57 /** Event names indicating function exit */
58 private final Set
<String
> funcExitEvents
;
60 private final ILttngUstEventLayout fLayout
;
62 // ------------------------------------------------------------------------
64 // ------------------------------------------------------------------------
72 public LttngUstCallStackProvider(ITmfTrace trace
) {
75 if (trace
instanceof LttngUstTrace
) {
76 fLayout
= ((LttngUstTrace
) trace
).getEventLayout();
78 /* For impostor trace types, assume they use the LTTng 2.0 layout */
79 fLayout
= LttngUst20EventLayout
.getInstance();
82 funcEntryEvents
= ImmutableSet
.of(
83 fLayout
.eventCygProfileFuncEntry(),
84 fLayout
.eventCygProfileFastFuncEntry());
86 funcExitEvents
= ImmutableSet
.of(
87 fLayout
.eventCygProfileFuncExit(),
88 fLayout
.eventCygProfileFastFuncExit());
91 // ------------------------------------------------------------------------
92 // Methods from AbstractTmfStateProvider
93 // ------------------------------------------------------------------------
96 public LttngUstCallStackProvider
getNewInstance() {
97 return new LttngUstCallStackProvider(getTrace());
101 public int getVersion() {
105 // ------------------------------------------------------------------------
106 // Methods from CallStackStateProvider
107 // ------------------------------------------------------------------------
110 * Check that this event contains the required information we need to be
111 * used in the call stack view. We need at least the "procname" and "vtid"
114 * The "vpid" is useful too, but optional.
117 protected boolean considerEvent(ITmfEvent event
) {
118 if (!(event
instanceof CtfTmfEvent
)) {
121 ITmfEventField content
= ((CtfTmfEvent
) event
).getContent();
122 if (content
.getField(fLayout
.contextVtid()) == null ||
123 content
.getField(fLayout
.contextProcname()) == null) {
130 public @Nullable String
functionEntry(ITmfEvent event
) {
131 String eventName
= event
.getName();
132 if (!funcEntryEvents
.contains(eventName
)) {
135 Long address
= (Long
) event
.getContent().getField(fLayout
.fieldAddr()).getValue();
136 return Long
.toHexString(address
);
140 public @Nullable String
functionExit(ITmfEvent event
) {
141 String eventName
= event
.getName();
142 if (!funcExitEvents
.contains(eventName
)) {
146 * The 'addr' field may or may not be present in func_exit events,
147 * depending on if cyg-profile.so or cyg-profile-fast.so was used.
149 ITmfEventField field
= event
.getContent().getField(fLayout
.fieldAddr());
151 return CallStackStateProvider
.UNDEFINED
;
153 Long address
= (Long
) field
.getValue();
154 return Long
.toHexString(address
);
158 protected int getProcessId(@NonNull ITmfEvent event
) {
159 /* The "vpid" context may not be present! We need to check */
160 ITmfEventField content
= event
.getContent();
161 ITmfEventField vpidContextField
= content
.getField(fLayout
.contextVpid());
162 if (vpidContextField
== null) {
163 return UNDEFINED_PID
;
165 return ((Long
) vpidContextField
.getValue()).intValue();
169 protected long getThreadId(ITmfEvent event
) {
170 /* We checked earlier that the "vtid" context is present */
171 ITmfEventField content
= event
.getContent();
172 return ((Long
) content
.getField(fLayout
.contextVtid()).getValue()).longValue();
176 public String
getThreadName(ITmfEvent event
) {
177 /* We checked earlier that the "procname" context is present */
178 ITmfEventField content
= event
.getContent();
179 String procName
= (String
) content
.getField(fLayout
.contextProcname()).getValue();
180 long vtid
= getThreadId(event
);
181 return (procName
+ '-' + Long
.toString(vtid
));