1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 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
.linuxtools
.internal
.lttng2
.ust
.core
.trace
.callstack
;
16 import java
.util
.HashSet
;
19 import org
.eclipse
.linuxtools
.tmf
.core
.callstack
.CallStackStateProvider
;
20 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
21 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEventField
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
23 import org
.eclipse
.linuxtools
.tmf
.ctf
.core
.CtfTmfEvent
;
26 * Callstack provider for LTTng-UST traces.
28 * If the traces contains 'func_entry' and 'func_exit' event (see the
29 * lttng-ust-cyg-profile manpage), AND contains vtid and procname contexts, we
30 * can use this information to populate the TMF Callstack View.
32 * Granted, most UST traces will not contain this information. In this case,
33 * this will simply build an empty state system, and the view will remain
36 * @author Alexandre Montplaisir
38 public class LttngUstCallStackProvider
extends CallStackStateProvider
{
40 // ------------------------------------------------------------------------
42 // ------------------------------------------------------------------------
44 /** Name of the fake field for the vtid contexts */
45 private static final String CONTEXT_VTID
= "context._vtid"; //$NON-NLS-1$
47 /** Name of the fake field for the procname context */
48 private static final String CONTEXT_PROCNAME
= "context._procname"; //$NON-NLS-1$
50 /** Field name for the target function address */
51 private static final String FIELD_ADDR
= "addr"; //$NON-NLS-1$
53 /** Event names indicating function entry */
54 private static final Set
<String
> FUNC_ENTRY_EVENTS
= new HashSet
<>();
56 /** Event names indicating function exit */
57 private static final Set
<String
> FUNC_EXIT_EVENTS
= new HashSet
<>();
60 /* This seems overkill, but it will be checked every event. Gotta go FAST! */
61 FUNC_ENTRY_EVENTS
.add("lttng_ust_cyg_profile:func_entry"); //$NON-NLS-1$
62 FUNC_ENTRY_EVENTS
.add("lttng_ust_cyg_profile_fast:func_entry"); //$NON-NLS-1$
64 FUNC_EXIT_EVENTS
.add("lttng_ust_cyg_profile:func_exit"); //$NON-NLS-1$
65 FUNC_EXIT_EVENTS
.add("lttng_ust_cyg_profile_fast:func_exit"); //$NON-NLS-1$
69 * Version number of this state provider. Please bump this if you modify
70 * the contents of the generated state history in some way.
72 private static final int VERSION
= 2;
74 // ------------------------------------------------------------------------
76 // ------------------------------------------------------------------------
84 public LttngUstCallStackProvider(ITmfTrace trace
) {
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(CONTEXT_VTID
) == null ||
118 content
.getField(CONTEXT_PROCNAME
) == null) {
125 public String
functionEntry(ITmfEvent event
) {
126 String eventName
= event
.getType().getName();
127 if (!FUNC_ENTRY_EVENTS
.contains(eventName
)) {
130 Long address
= (Long
) event
.getContent().getField(FIELD_ADDR
).getValue();
131 return Long
.toHexString(address
);
135 public String
functionExit(ITmfEvent event
) {
136 String eventName
= event
.getType().getName();
137 if (!FUNC_EXIT_EVENTS
.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(FIELD_ADDR
);
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(CONTEXT_PROCNAME
).getValue();
157 Long vtid
= (Long
) content
.getField(CONTEXT_VTID
).getValue();
159 if (procName
== null || vtid
== null) {
160 throw new IllegalStateException();
163 return new String(procName
+ '-' + vtid
.toString());
167 protected Long
getThreadId(ITmfEvent event
) {
168 ITmfEventField content
= ((CtfTmfEvent
) event
).getContent();
169 return (Long
) content
.getField(CONTEXT_VTID
).getValue();