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
;
16 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
20 import org
.eclipse
.jdt
.annotation
.NonNull
;
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
45 public class LttngUstCallStackProvider
extends CallStackStateProvider
{
48 * Version number of this state provider. Please bump this if you modify
49 * the contents of the generated state history in some way.
51 private static final int VERSION
= 2;
53 /** Event names indicating function entry */
54 private final @NonNull Set
<String
> funcEntryEvents
;
56 /** Event names indicating function exit */
57 private final @NonNull Set
<String
> funcExitEvents
;
59 private final @NonNull ILttngUstEventLayout fLayout
;
61 // ------------------------------------------------------------------------
63 // ------------------------------------------------------------------------
71 public LttngUstCallStackProvider(@NonNull ITmfTrace trace
) {
74 if (trace
instanceof LttngUstTrace
) {
75 fLayout
= ((LttngUstTrace
) trace
).getEventLayout();
77 /* For impostor trace types, assume they use the LTTng 2.0 layout */
78 fLayout
= LttngUst20EventLayout
.getInstance();
81 funcEntryEvents
= checkNotNull(ImmutableSet
.of(
82 fLayout
.eventCygProfileFuncEntry(),
83 fLayout
.eventCygProfileFastFuncEntry()));
85 funcExitEvents
= checkNotNull(ImmutableSet
.of(
86 fLayout
.eventCygProfileFuncExit(),
87 fLayout
.eventCygProfileFastFuncExit()));
90 // ------------------------------------------------------------------------
91 // Methods from AbstractTmfStateProvider
92 // ------------------------------------------------------------------------
95 public LttngUstCallStackProvider
getNewInstance() {
96 return new LttngUstCallStackProvider(getTrace());
100 public int getVersion() {
104 // ------------------------------------------------------------------------
105 // Methods from CallStackStateProvider
106 // ------------------------------------------------------------------------
109 * Check that this event contains the required information we need to be
110 * used in the call stack view. We need at least the "procname" and "vtid"
114 protected boolean considerEvent(ITmfEvent event
) {
115 if (!(event
instanceof CtfTmfEvent
)) {
118 ITmfEventField content
= ((CtfTmfEvent
) event
).getContent();
119 if (content
.getField(fLayout
.contextVtid()) == null ||
120 content
.getField(fLayout
.contextProcname()) == null) {
127 public String
functionEntry(ITmfEvent event
) {
128 String eventName
= event
.getName();
129 if (!funcEntryEvents
.contains(eventName
)) {
132 Long address
= (Long
) event
.getContent().getField(fLayout
.fieldAddr()).getValue();
133 return Long
.toHexString(address
);
137 public String
functionExit(ITmfEvent event
) {
138 String eventName
= event
.getName();
139 if (!funcExitEvents
.contains(eventName
)) {
143 * The 'addr' field may or may not be present in func_exit events,
144 * depending on if cyg-profile.so or cyg-profile-fast.so was used.
146 ITmfEventField field
= event
.getContent().getField(fLayout
.fieldAddr());
148 return CallStackStateProvider
.UNDEFINED
;
150 Long address
= (Long
) field
.getValue();
151 return Long
.toHexString(address
);
155 public String
getThreadName(ITmfEvent event
) {
156 /* Class type and content was already checked if we get called here */
157 ITmfEventField content
= ((CtfTmfEvent
) event
).getContent();
158 String procName
= (String
) content
.getField(fLayout
.contextProcname()).getValue();
159 Long vtid
= (Long
) content
.getField(fLayout
.contextVtid()).getValue();
161 if (procName
== null || vtid
== null) {
162 throw new IllegalStateException();
165 return new String(procName
+ '-' + vtid
.toString());
169 protected Long
getThreadId(ITmfEvent event
) {
170 ITmfEventField content
= ((CtfTmfEvent
) event
).getContent();
171 return (Long
) content
.getField(fLayout
.contextVtid()).getValue();