Commit | Line | Data |
---|---|---|
1c6660ca | 1 | /******************************************************************************* |
ed902a2b | 2 | * Copyright (c) 2013, 2015 Ericsson |
1c6660ca AM |
3 | * |
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 | |
8 | * | |
9 | * Contributors: | |
10 | * Alexandre Montplaisir - Initial API and implementation | |
ac31f2fb | 11 | * Patrick Tasse - Add support for thread id |
1c6660ca AM |
12 | *******************************************************************************/ |
13 | ||
116738ad | 14 | package org.eclipse.tracecompass.internal.lttng2.ust.core.callstack; |
1c6660ca | 15 | |
c469808d AM |
16 | import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull; |
17 | ||
1c6660ca AM |
18 | import java.util.Set; |
19 | ||
d0c7e4ba | 20 | import org.eclipse.jdt.annotation.NonNull; |
c469808d AM |
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; | |
2bdf0193 AM |
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; | |
9722e5d7 | 28 | import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent; |
1c6660ca | 29 | |
c469808d AM |
30 | import com.google.common.collect.ImmutableSet; |
31 | ||
1c6660ca AM |
32 | /** |
33 | * Callstack provider for LTTng-UST traces. | |
34 | * | |
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. | |
38 | * | |
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 | |
41 | * unavailable. | |
42 | * | |
43 | * @author Alexandre Montplaisir | |
44 | */ | |
45 | public class LttngUstCallStackProvider extends CallStackStateProvider { | |
46 | ||
5da83da5 AM |
47 | /** |
48 | * Version number of this state provider. Please bump this if you modify | |
49 | * the contents of the generated state history in some way. | |
50 | */ | |
aaee1ffb | 51 | private static final int VERSION = 2; |
5da83da5 | 52 | |
c469808d AM |
53 | /** Event names indicating function entry */ |
54 | private final @NonNull Set<String> funcEntryEvents; | |
55 | ||
56 | /** Event names indicating function exit */ | |
57 | private final @NonNull Set<String> funcExitEvents; | |
58 | ||
59 | private final @NonNull ILttngUstEventLayout fLayout; | |
60 | ||
1c6660ca AM |
61 | // ------------------------------------------------------------------------ |
62 | // Constructor | |
63 | // ------------------------------------------------------------------------ | |
64 | ||
65 | /** | |
66 | * Constructor | |
67 | * | |
68 | * @param trace | |
69 | * The UST trace | |
70 | */ | |
d0c7e4ba | 71 | public LttngUstCallStackProvider(@NonNull ITmfTrace trace) { |
1c6660ca | 72 | super(trace); |
c469808d AM |
73 | |
74 | if (trace instanceof LttngUstTrace) { | |
75 | fLayout = ((LttngUstTrace) trace).getEventLayout(); | |
76 | } else { | |
77 | /* For impostor trace types, assume they use the LTTng 2.0 layout */ | |
78 | fLayout = LttngUst20EventLayout.getInstance(); | |
79 | } | |
80 | ||
81 | funcEntryEvents = checkNotNull(ImmutableSet.of( | |
82 | fLayout.eventCygProfileFuncEntry(), | |
83 | fLayout.eventCygProfileFastFuncEntry())); | |
84 | ||
85 | funcExitEvents = checkNotNull(ImmutableSet.of( | |
86 | fLayout.eventCygProfileFuncExit(), | |
87 | fLayout.eventCygProfileFastFuncExit())); | |
1c6660ca AM |
88 | } |
89 | ||
90 | // ------------------------------------------------------------------------ | |
91 | // Methods from AbstractTmfStateProvider | |
92 | // ------------------------------------------------------------------------ | |
93 | ||
1c6660ca AM |
94 | @Override |
95 | public LttngUstCallStackProvider getNewInstance() { | |
96 | return new LttngUstCallStackProvider(getTrace()); | |
97 | } | |
98 | ||
5da83da5 AM |
99 | @Override |
100 | public int getVersion() { | |
101 | return VERSION; | |
102 | } | |
103 | ||
1c6660ca AM |
104 | // ------------------------------------------------------------------------ |
105 | // Methods from CallStackStateProvider | |
106 | // ------------------------------------------------------------------------ | |
107 | ||
108 | /** | |
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" | |
111 | * contexts. | |
112 | */ | |
113 | @Override | |
114 | protected boolean considerEvent(ITmfEvent event) { | |
115 | if (!(event instanceof CtfTmfEvent)) { | |
116 | return false; | |
117 | } | |
118 | ITmfEventField content = ((CtfTmfEvent) event).getContent(); | |
c469808d AM |
119 | if (content.getField(fLayout.contextVtid()) == null || |
120 | content.getField(fLayout.contextProcname()) == null) { | |
1c6660ca AM |
121 | return false; |
122 | } | |
123 | return true; | |
124 | } | |
125 | ||
126 | @Override | |
127 | public String functionEntry(ITmfEvent event) { | |
578716e6 | 128 | String eventName = event.getName(); |
c469808d | 129 | if (!funcEntryEvents.contains(eventName)) { |
1c6660ca AM |
130 | return null; |
131 | } | |
c469808d | 132 | Long address = (Long) event.getContent().getField(fLayout.fieldAddr()).getValue(); |
5da83da5 | 133 | return Long.toHexString(address); |
1c6660ca AM |
134 | } |
135 | ||
136 | @Override | |
137 | public String functionExit(ITmfEvent event) { | |
578716e6 | 138 | String eventName = event.getName(); |
c469808d | 139 | if (!funcExitEvents.contains(eventName)) { |
1c6660ca AM |
140 | return null; |
141 | } | |
142 | /* | |
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. | |
145 | */ | |
c469808d | 146 | ITmfEventField field = event.getContent().getField(fLayout.fieldAddr()); |
1c6660ca AM |
147 | if (field == null) { |
148 | return CallStackStateProvider.UNDEFINED; | |
149 | } | |
150 | Long address = (Long) field.getValue(); | |
5da83da5 | 151 | return Long.toHexString(address); |
1c6660ca AM |
152 | } |
153 | ||
154 | @Override | |
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(); | |
c469808d AM |
158 | String procName = (String) content.getField(fLayout.contextProcname()).getValue(); |
159 | Long vtid = (Long) content.getField(fLayout.contextVtid()).getValue(); | |
1c6660ca AM |
160 | |
161 | if (procName == null || vtid == null) { | |
162 | throw new IllegalStateException(); | |
163 | } | |
164 | ||
165 | return new String(procName + '-' + vtid.toString()); | |
166 | } | |
ac31f2fb PT |
167 | |
168 | @Override | |
169 | protected Long getThreadId(ITmfEvent event) { | |
170 | ITmfEventField content = ((CtfTmfEvent) event).getContent(); | |
c469808d | 171 | return (Long) content.getField(fLayout.contextVtid()).getValue(); |
ac31f2fb | 172 | } |
1c6660ca | 173 | } |