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 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.internal
.lttng2
.ust
.core
.trace
.callstack
;
15 import java
.util
.HashSet
;
18 import org
.eclipse
.linuxtools
.tmf
.core
.callstack
.CallStackStateProvider
;
19 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
20 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEventField
;
21 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
22 import org
.eclipse
.linuxtools
.tmf
.ctf
.core
.CtfTmfEvent
;
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
<>();
55 /** Event names indicating function exit */
56 private static final Set
<String
> FUNC_EXIT_EVENTS
= new HashSet
<>();
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(ITmfTrace trace
) {
87 // ------------------------------------------------------------------------
88 // Methods from AbstractTmfStateProvider
89 // ------------------------------------------------------------------------
92 public LttngUstCallStackProvider
getNewInstance() {
93 return new LttngUstCallStackProvider(getTrace());
97 public int getVersion() {
101 // ------------------------------------------------------------------------
102 // Methods from CallStackStateProvider
103 // ------------------------------------------------------------------------
106 * Check that this event contains the required information we need to be
107 * used in the call stack view. We need at least the "procname" and "vtid"
111 protected boolean considerEvent(ITmfEvent event
) {
112 if (!(event
instanceof CtfTmfEvent
)) {
115 ITmfEventField content
= ((CtfTmfEvent
) event
).getContent();
116 if (content
.getField(CONTEXT_VTID
) == null ||
117 content
.getField(CONTEXT_PROCNAME
) == null) {
124 public String
functionEntry(ITmfEvent event
) {
125 String eventName
= event
.getType().getName();
126 if (!FUNC_ENTRY_EVENTS
.contains(eventName
)) {
129 Long address
= (Long
) event
.getContent().getField(FIELD_ADDR
).getValue();
130 return Long
.toHexString(address
);
134 public String
functionExit(ITmfEvent event
) {
135 String eventName
= event
.getType().getName();
136 if (!FUNC_EXIT_EVENTS
.contains(eventName
)) {
140 * The 'addr' field may or may not be present in func_exit events,
141 * depending on if cyg-profile.so or cyg-profile-fast.so was used.
143 ITmfEventField field
= event
.getContent().getField(FIELD_ADDR
);
145 return CallStackStateProvider
.UNDEFINED
;
147 Long address
= (Long
) field
.getValue();
148 return Long
.toHexString(address
);
152 public String
getThreadName(ITmfEvent event
) {
153 /* Class type and content was already checked if we get called here */
154 ITmfEventField content
= ((CtfTmfEvent
) event
).getContent();
155 String procName
= (String
) content
.getField(CONTEXT_PROCNAME
).getValue();
156 Long vtid
= (Long
) content
.getField(CONTEXT_VTID
).getValue();
158 if (procName
== null || vtid
== null) {
159 throw new IllegalStateException();
162 return new String(procName
+ '-' + vtid
.toString());