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
.tracecompass
.internal
.lttng2
.ust
.core
.trace
.layout
.LttngUst20EventLayout
;
20 import org
.eclipse
.tracecompass
.lttng2
.ust
.core
.trace
.LttngUstTrace
;
21 import org
.eclipse
.tracecompass
.lttng2
.ust
.core
.trace
.layout
.ILttngUstEventLayout
;
22 import org
.eclipse
.tracecompass
.tmf
.core
.callstack
.CallStackStateProvider
;
23 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
24 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEventField
;
25 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
26 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.event
.CtfTmfEvent
;
28 import com
.google
.common
.collect
.ImmutableSet
;
31 * Callstack provider for LTTng-UST traces.
33 * If the traces contains 'func_entry' and 'func_exit' event (see the
34 * lttng-ust-cyg-profile manpage), AND contains vtid and procname contexts, we
35 * can use this information to populate the TMF Callstack View.
37 * Granted, most UST traces will not contain this information. In this case,
38 * this will simply build an empty state system, and the view will remain
41 * @author Alexandre Montplaisir
43 public class LttngUstCallStackProvider
extends CallStackStateProvider
{
46 * Version number of this state provider. Please bump this if you modify
47 * the contents of the generated state history in some way.
49 private static final int VERSION
= 2;
51 /** Event names indicating function entry */
52 private final @NonNull Set
<String
> funcEntryEvents
;
54 /** Event names indicating function exit */
55 private final @NonNull Set
<String
> funcExitEvents
;
57 private final @NonNull ILttngUstEventLayout fLayout
;
59 // ------------------------------------------------------------------------
61 // ------------------------------------------------------------------------
69 public LttngUstCallStackProvider(@NonNull ITmfTrace trace
) {
72 if (trace
instanceof LttngUstTrace
) {
73 fLayout
= ((LttngUstTrace
) trace
).getEventLayout();
75 /* For impostor trace types, assume they use the LTTng 2.0 layout */
76 fLayout
= LttngUst20EventLayout
.getInstance();
79 funcEntryEvents
= ImmutableSet
.of(
80 fLayout
.eventCygProfileFuncEntry(),
81 fLayout
.eventCygProfileFastFuncEntry());
83 funcExitEvents
= ImmutableSet
.of(
84 fLayout
.eventCygProfileFuncExit(),
85 fLayout
.eventCygProfileFastFuncExit());
88 // ------------------------------------------------------------------------
89 // Methods from AbstractTmfStateProvider
90 // ------------------------------------------------------------------------
93 public LttngUstCallStackProvider
getNewInstance() {
94 return new LttngUstCallStackProvider(getTrace());
98 public int getVersion() {
102 // ------------------------------------------------------------------------
103 // Methods from CallStackStateProvider
104 // ------------------------------------------------------------------------
107 * Check that this event contains the required information we need to be
108 * used in the call stack view. We need at least the "procname" and "vtid"
112 protected boolean considerEvent(ITmfEvent event
) {
113 if (!(event
instanceof CtfTmfEvent
)) {
116 ITmfEventField content
= ((CtfTmfEvent
) event
).getContent();
117 if (content
.getField(fLayout
.contextVtid()) == null ||
118 content
.getField(fLayout
.contextProcname()) == null) {
125 public String
functionEntry(ITmfEvent event
) {
126 String eventName
= event
.getName();
127 if (!funcEntryEvents
.contains(eventName
)) {
130 Long address
= (Long
) event
.getContent().getField(fLayout
.fieldAddr()).getValue();
131 return Long
.toHexString(address
);
135 public String
functionExit(ITmfEvent event
) {
136 String eventName
= event
.getName();
137 if (!funcExitEvents
.contains(eventName
)) {
141 * The 'addr' field may or may not be present in func_exit events,
142 * depending on if cyg-profile.so or cyg-profile-fast.so was used.
144 ITmfEventField field
= event
.getContent().getField(fLayout
.fieldAddr());
146 return CallStackStateProvider
.UNDEFINED
;
148 Long address
= (Long
) field
.getValue();
149 return Long
.toHexString(address
);
153 public String
getThreadName(ITmfEvent event
) {
154 /* Class type and content was already checked if we get called here */
155 ITmfEventField content
= ((CtfTmfEvent
) event
).getContent();
156 String procName
= (String
) content
.getField(fLayout
.contextProcname()).getValue();
157 Long vtid
= (Long
) content
.getField(fLayout
.contextVtid()).getValue();
159 if (procName
== null || vtid
== null) {
160 throw new IllegalStateException();
163 return procName
+ '-' + vtid
.toString();
167 protected Long
getThreadId(ITmfEvent event
) {
168 ITmfEventField content
= ((CtfTmfEvent
) event
).getContent();
169 return (Long
) content
.getField(fLayout
.contextVtid()).getValue();