From c469808d479db2c72e2f4b101b2ec716d5281ac1 Mon Sep 17 00:00:00 2001 From: Alexandre Montplaisir Date: Mon, 22 Jun 2015 20:15:48 -0400 Subject: [PATCH] lttng: Move the UST Callstack analysis to use ILttngUstEventLayout The UST callstack implementation was defining the event and field names it's looking for on its own. This is bad and prone to future breakage. Instead, integrate these event definitions in the LttngUstEventLayout, and move the analysis to use these instead. Change-Id: I098d8569ab2c9c0d2ffd0975aba528a177a02af2 Signed-off-by: Alexandre Montplaisir Reviewed-on: https://git.eclipse.org/r/50686 Reviewed-by: Hudson CI Reviewed-by: Matthew Khouzam Tested-by: Matthew Khouzam --- .../callstack/LttngUstCallStackProvider.java | 77 ++++++++++--------- .../trace/layout/LttngUst20EventLayout.java | 29 +++++++ .../trace/layout/ILttngUstEventLayout.java | 11 +++ 3 files changed, 79 insertions(+), 38 deletions(-) diff --git a/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/internal/lttng2/ust/core/callstack/LttngUstCallStackProvider.java b/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/internal/lttng2/ust/core/callstack/LttngUstCallStackProvider.java index 6d149116de..cf8c57549f 100644 --- a/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/internal/lttng2/ust/core/callstack/LttngUstCallStackProvider.java +++ b/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/internal/lttng2/ust/core/callstack/LttngUstCallStackProvider.java @@ -13,16 +13,22 @@ package org.eclipse.tracecompass.internal.lttng2.ust.core.callstack; -import java.util.HashSet; +import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull; + import java.util.Set; import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.tracecompass.internal.lttng2.ust.core.trace.layout.LttngUst20EventLayout; +import org.eclipse.tracecompass.lttng2.ust.core.trace.LttngUstTrace; +import org.eclipse.tracecompass.lttng2.ust.core.trace.layout.ILttngUstEventLayout; import org.eclipse.tracecompass.tmf.core.callstack.CallStackStateProvider; import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; import org.eclipse.tracecompass.tmf.core.event.ITmfEventField; import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent; +import com.google.common.collect.ImmutableSet; + /** * Callstack provider for LTTng-UST traces. * @@ -38,40 +44,20 @@ import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent; */ public class LttngUstCallStackProvider extends CallStackStateProvider { - // ------------------------------------------------------------------------ - // Event strings - // ------------------------------------------------------------------------ - - /** Name of the fake field for the vtid contexts */ - private static final String CONTEXT_VTID = "context._vtid"; //$NON-NLS-1$ - - /** Name of the fake field for the procname context */ - private static final String CONTEXT_PROCNAME = "context._procname"; //$NON-NLS-1$ - - /** Field name for the target function address */ - private static final String FIELD_ADDR = "addr"; //$NON-NLS-1$ - - /** Event names indicating function entry */ - private static final Set FUNC_ENTRY_EVENTS = new HashSet<>(); - - /** Event names indicating function exit */ - private static final Set FUNC_EXIT_EVENTS = new HashSet<>(); - - static { - /* This seems overkill, but it will be checked every event. Gotta go FAST! */ - FUNC_ENTRY_EVENTS.add("lttng_ust_cyg_profile:func_entry"); //$NON-NLS-1$ - FUNC_ENTRY_EVENTS.add("lttng_ust_cyg_profile_fast:func_entry"); //$NON-NLS-1$ - - FUNC_EXIT_EVENTS.add("lttng_ust_cyg_profile:func_exit"); //$NON-NLS-1$ - FUNC_EXIT_EVENTS.add("lttng_ust_cyg_profile_fast:func_exit"); //$NON-NLS-1$ - } - /** * Version number of this state provider. Please bump this if you modify * the contents of the generated state history in some way. */ private static final int VERSION = 2; + /** Event names indicating function entry */ + private final @NonNull Set funcEntryEvents; + + /** Event names indicating function exit */ + private final @NonNull Set funcExitEvents; + + private final @NonNull ILttngUstEventLayout fLayout; + // ------------------------------------------------------------------------ // Constructor // ------------------------------------------------------------------------ @@ -84,6 +70,21 @@ public class LttngUstCallStackProvider extends CallStackStateProvider { */ public LttngUstCallStackProvider(@NonNull ITmfTrace trace) { super(trace); + + if (trace instanceof LttngUstTrace) { + fLayout = ((LttngUstTrace) trace).getEventLayout(); + } else { + /* For impostor trace types, assume they use the LTTng 2.0 layout */ + fLayout = LttngUst20EventLayout.getInstance(); + } + + funcEntryEvents = checkNotNull(ImmutableSet.of( + fLayout.eventCygProfileFuncEntry(), + fLayout.eventCygProfileFastFuncEntry())); + + funcExitEvents = checkNotNull(ImmutableSet.of( + fLayout.eventCygProfileFuncExit(), + fLayout.eventCygProfileFastFuncExit())); } // ------------------------------------------------------------------------ @@ -115,8 +116,8 @@ public class LttngUstCallStackProvider extends CallStackStateProvider { return false; } ITmfEventField content = ((CtfTmfEvent) event).getContent(); - if (content.getField(CONTEXT_VTID) == null || - content.getField(CONTEXT_PROCNAME) == null) { + if (content.getField(fLayout.contextVtid()) == null || + content.getField(fLayout.contextProcname()) == null) { return false; } return true; @@ -125,24 +126,24 @@ public class LttngUstCallStackProvider extends CallStackStateProvider { @Override public String functionEntry(ITmfEvent event) { String eventName = event.getName(); - if (!FUNC_ENTRY_EVENTS.contains(eventName)) { + if (!funcEntryEvents.contains(eventName)) { return null; } - Long address = (Long) event.getContent().getField(FIELD_ADDR).getValue(); + Long address = (Long) event.getContent().getField(fLayout.fieldAddr()).getValue(); return Long.toHexString(address); } @Override public String functionExit(ITmfEvent event) { String eventName = event.getName(); - if (!FUNC_EXIT_EVENTS.contains(eventName)) { + if (!funcExitEvents.contains(eventName)) { return null; } /* * The 'addr' field may or may not be present in func_exit events, * depending on if cyg-profile.so or cyg-profile-fast.so was used. */ - ITmfEventField field = event.getContent().getField(FIELD_ADDR); + ITmfEventField field = event.getContent().getField(fLayout.fieldAddr()); if (field == null) { return CallStackStateProvider.UNDEFINED; } @@ -154,8 +155,8 @@ public class LttngUstCallStackProvider extends CallStackStateProvider { public String getThreadName(ITmfEvent event) { /* Class type and content was already checked if we get called here */ ITmfEventField content = ((CtfTmfEvent) event).getContent(); - String procName = (String) content.getField(CONTEXT_PROCNAME).getValue(); - Long vtid = (Long) content.getField(CONTEXT_VTID).getValue(); + String procName = (String) content.getField(fLayout.contextProcname()).getValue(); + Long vtid = (Long) content.getField(fLayout.contextVtid()).getValue(); if (procName == null || vtid == null) { throw new IllegalStateException(); @@ -167,6 +168,6 @@ public class LttngUstCallStackProvider extends CallStackStateProvider { @Override protected Long getThreadId(ITmfEvent event) { ITmfEventField content = ((CtfTmfEvent) event).getContent(); - return (Long) content.getField(CONTEXT_VTID).getValue(); + return (Long) content.getField(fLayout.contextVtid()).getValue(); } } diff --git a/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/internal/lttng2/ust/core/trace/layout/LttngUst20EventLayout.java b/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/internal/lttng2/ust/core/trace/layout/LttngUst20EventLayout.java index 711dd3b0b6..d818bdf562 100644 --- a/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/internal/lttng2/ust/core/trace/layout/LttngUst20EventLayout.java +++ b/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/internal/lttng2/ust/core/trace/layout/LttngUst20EventLayout.java @@ -69,6 +69,30 @@ public class LttngUst20EventLayout implements ILttngUstEventLayout { return "ust_libc:posix_memalign"; } + // ------------------------------------------------------------------------ + // Event names used in liblttng-cyg-profile + // ------------------------------------------------------------------------ + + @Override + public String eventCygProfileFuncEntry() { + return "lttng_ust_cyg_profile:func_entry"; + } + + @Override + public String eventCygProfileFastFuncEntry() { + return "lttng_ust_cyg_profile_fast:func_entry"; + } + + @Override + public String eventCygProfileFuncExit() { + return "lttng_ust_cyg_profile:func_exit"; + } + + @Override + public String eventCygProfileFastFuncExit() { + return "lttng_ust_cyg_profile_fast:func_exit"; + } + // ------------------------------------------------------------------------ // Field names // ------------------------------------------------------------------------ @@ -98,6 +122,11 @@ public class LttngUst20EventLayout implements ILttngUstEventLayout { return "in_ptr"; } + @Override + public String fieldAddr() { + return "addr"; + } + // ------------------------------------------------------------------------ // Context field names // Note: The CTF parser exposes contexts as fields called "context._" diff --git a/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/trace/layout/ILttngUstEventLayout.java b/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/trace/layout/ILttngUstEventLayout.java index eabe2b6996..f4b3bb1d35 100644 --- a/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/trace/layout/ILttngUstEventLayout.java +++ b/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/trace/layout/ILttngUstEventLayout.java @@ -30,6 +30,15 @@ public interface ILttngUstEventLayout { String eventLibcMemalign(); String eventLibcPosixMemalign(); + // ------------------------------------------------------------------------ + // Event names used in liblttng-ust-cyg-profile(-fast) + // ------------------------------------------------------------------------ + + String eventCygProfileFuncEntry(); + String eventCygProfileFastFuncEntry(); + String eventCygProfileFuncExit(); + String eventCygProfileFastFuncExit(); + // ------------------------------------------------------------------------ // Field names // ------------------------------------------------------------------------ @@ -40,6 +49,8 @@ public interface ILttngUstEventLayout { String fieldOutPtr(); String fieldInPtr(); + String fieldAddr(); + // ------------------------------------------------------------------------ // Context field names // ------------------------------------------------------------------------ -- 2.34.1