1 /*******************************************************************************
2 * Copyright (c) 2013 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 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.internal
.lttng2
.ust
.core
.trace
.callstack
;
15 import java
.util
.HashSet
;
18 import org
.eclipse
.linuxtools
.lttng2
.ust
.core
.trace
.LttngUstTrace
;
19 import org
.eclipse
.linuxtools
.tmf
.core
.callstack
.CallStackStateProvider
;
20 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfEvent
;
21 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEventField
;
25 * Callstack provider for LTTng-UST traces.
27 * If the traces contains 'func_entry' and 'func_exit' event (see the
28 * lttng-ust-cyg-profile manpage), AND contains vtid and procname contexts, we
29 * can use this information to populate the TMF Callstack View.
31 * Granted, most UST traces will not contain this information. In this case,
32 * this will simply build an empty state system, and the view will remain
35 * @author Alexandre Montplaisir
37 public class LttngUstCallStackProvider
extends CallStackStateProvider
{
39 // ------------------------------------------------------------------------
41 // ------------------------------------------------------------------------
43 /** Name of the fake field for the vtid contexts */
44 private static final String CONTEXT_VTID
= "context._vtid"; //$NON-NLS-1$
46 /** Name of the fake field for the procname context */
47 private static final String CONTEXT_PROCNAME
= "context._procname"; //$NON-NLS-1$
49 /** Field name for the target function address */
50 private static final String FIELD_ADDR
= "addr"; //$NON-NLS-1$
52 /** Event names indicating function entry */
53 private static final Set
<String
> FUNC_ENTRY_EVENTS
= new HashSet
<String
>();
55 /** Event names indicating function exit */
56 private static final Set
<String
> FUNC_EXIT_EVENTS
= new HashSet
<String
>();
59 /* This seems overkill, but it will be checked every event. Gotta go FAST! */
60 FUNC_ENTRY_EVENTS
.add("lttng_ust_cyg_profile:func_entry"); //$NON-NLS-1$
61 FUNC_ENTRY_EVENTS
.add("lttng_ust_cyg_profile_fast:func_entry"); //$NON-NLS-1$
63 FUNC_EXIT_EVENTS
.add("lttng_ust_cyg_profile:func_exit"); //$NON-NLS-1$
64 FUNC_EXIT_EVENTS
.add("lttng_ust_cyg_profile_fast:func_exit"); //$NON-NLS-1$
68 * Version number of this state provider. Please bump this if you modify
69 * the contents of the generated state history in some way.
71 private static final int VERSION
= 1;
73 // ------------------------------------------------------------------------
75 // ------------------------------------------------------------------------
83 public LttngUstCallStackProvider(LttngUstTrace trace
) {
87 // ------------------------------------------------------------------------
88 // Methods from AbstractTmfStateProvider
89 // ------------------------------------------------------------------------
92 public LttngUstTrace
getTrace() {
93 /* Type is enforced by the constructor */
94 return (LttngUstTrace
) super.getTrace();
98 public LttngUstCallStackProvider
getNewInstance() {
99 return new LttngUstCallStackProvider(getTrace());
103 public int getVersion() {
107 // ------------------------------------------------------------------------
108 // Methods from CallStackStateProvider
109 // ------------------------------------------------------------------------
112 * Check that this event contains the required information we need to be
113 * used in the call stack view. We need at least the "procname" and "vtid"
117 protected boolean considerEvent(ITmfEvent event
) {
118 if (!(event
instanceof CtfTmfEvent
)) {
121 ITmfEventField content
= ((CtfTmfEvent
) event
).getContent();
122 if (content
.getField(CONTEXT_VTID
) == null ||
123 content
.getField(CONTEXT_PROCNAME
) == null) {
130 public String
functionEntry(ITmfEvent event
) {
131 String eventName
= ((CtfTmfEvent
) event
).getEventName();
132 if (!FUNC_ENTRY_EVENTS
.contains(eventName
)) {
135 Long address
= (Long
) event
.getContent().getField(FIELD_ADDR
).getValue();
136 return Long
.toHexString(address
);
140 public String
functionExit(ITmfEvent event
) {
141 String eventName
= ((CtfTmfEvent
) event
).getEventName();
142 if (!FUNC_EXIT_EVENTS
.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(FIELD_ADDR
);
151 return CallStackStateProvider
.UNDEFINED
;
153 Long address
= (Long
) field
.getValue();
154 return Long
.toHexString(address
);
158 public String
getThreadName(ITmfEvent event
) {
159 /* Class type and content was already checked if we get called here */
160 ITmfEventField content
= ((CtfTmfEvent
) event
).getContent();
161 String procName
= (String
) content
.getField(CONTEXT_PROCNAME
).getValue();
162 Long vtid
= (Long
) content
.getField(CONTEXT_VTID
).getValue();
164 if (procName
== null || vtid
== null) {
165 throw new IllegalStateException();
168 return new String(procName
+ '-' + vtid
.toString());