X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=lttng%2Forg.eclipse.tracecompass.lttng2.ust.core%2Fsrc%2Forg%2Feclipse%2Ftracecompass%2Finternal%2Flttng2%2Fust%2Fcore%2Fanalysis%2Fmemory%2FUstMemoryStateProvider.java;h=68d5426e2463afa85c6bd1ac05cdf252a9e3b5d9;hb=0e4f957eff33d35923105497af515178953cacbc;hp=3175711a1191b0213aab2211f6fd125104097f7a;hpb=4252328e562ff15671facb499a70f6f2b74bbcb4;p=deliverable%2Ftracecompass.git diff --git a/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/internal/lttng2/ust/core/analysis/memory/UstMemoryStateProvider.java b/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/internal/lttng2/ust/core/analysis/memory/UstMemoryStateProvider.java index 3175711a11..68d5426e24 100644 --- a/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/internal/lttng2/ust/core/analysis/memory/UstMemoryStateProvider.java +++ b/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/internal/lttng2/ust/core/analysis/memory/UstMemoryStateProvider.java @@ -20,6 +20,7 @@ import java.util.Map; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.tracecompass.lttng2.ust.core.trace.LttngUstTrace; +import org.eclipse.tracecompass.lttng2.ust.core.trace.layout.ILttngUstEventLayout; import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder; import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException; import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException; @@ -31,6 +32,8 @@ import org.eclipse.tracecompass.tmf.core.event.ITmfEventField; import org.eclipse.tracecompass.tmf.core.statesystem.AbstractTmfStateProvider; import org.eclipse.tracecompass.tmf.core.statesystem.ITmfStateProvider; +import com.google.common.collect.ImmutableMap; + /** * State provider to track the memory of the threads using the UST libc wrapper * memory events. @@ -43,13 +46,23 @@ public class UstMemoryStateProvider extends AbstractTmfStateProvider { /* Version of this state provider */ private static final int VERSION = 1; - /* Maps a pointer to a memory zone to the size of the memory */ - private final Map fMemory = new HashMap<>(); - private static final Long MINUS_ONE = Long.valueOf(-1); private static final Long ZERO = Long.valueOf(0); private static final String EMPTY_STRING = ""; //$NON-NLS-1$ + private static final int MALLOC_INDEX = 1; + private static final int FREE_INDEX = 2; + private static final int CALLOC_INDEX = 3; + private static final int REALLOC_INDEX = 4; + private static final int MEMALIGN_INDEX = 5; + private static final int POSIX_MEMALIGN_INDEX = 6; + + /** Map of a pointer to a memory zone to the size of the memory */ + private final Map fMemory = new HashMap<>(); + + private final @NonNull ILttngUstEventLayout fLayout; + private final @NonNull Map fEventNames; + /** * Constructor * @@ -58,69 +71,86 @@ public class UstMemoryStateProvider extends AbstractTmfStateProvider { */ public UstMemoryStateProvider(@NonNull LttngUstTrace trace) { super(trace, "Ust:Memory"); //$NON-NLS-1$ + fLayout = trace.getEventLayout(); + fEventNames = buildEventNames(fLayout); + } + + private static @NonNull Map buildEventNames(ILttngUstEventLayout layout) { + ImmutableMap.Builder builder = ImmutableMap.builder(); + builder.put(layout.eventLibcMalloc(), MALLOC_INDEX); + builder.put(layout.eventLibcFree(), FREE_INDEX); + builder.put(layout.eventLibcCalloc(), CALLOC_INDEX); + builder.put(layout.eventLibcRealloc(), REALLOC_INDEX); + builder.put(layout.eventLibcMemalign(), MEMALIGN_INDEX); + builder.put(layout.eventLibcPosixMemalign(), POSIX_MEMALIGN_INDEX); + return builder.build(); } @Override protected void eventHandle(ITmfEvent event) { String name = event.getName(); - switch (name) { - case UstMemoryStrings.MALLOC: { - Long ptr = (Long) event.getContent().getField(UstMemoryStrings.FIELD_PTR).getValue(); + Integer index = fEventNames.get(name); + int intIndex = (index == null ? -1 : index.intValue()); + + switch (intIndex) { + case MALLOC_INDEX: { + Long ptr = (Long) event.getContent().getField(fLayout.fieldPtr()).getValue(); if (ZERO.equals(ptr)) { return; } - Long size = (Long) event.getContent().getField(UstMemoryStrings.FIELD_SIZE).getValue(); + Long size = (Long) event.getContent().getField(fLayout.fieldSize()).getValue(); setMem(event, ptr, size); } break; - case UstMemoryStrings.FREE: { - Long ptr = (Long) event.getContent().getField(UstMemoryStrings.FIELD_PTR).getValue(); + case FREE_INDEX: { + Long ptr = (Long) event.getContent().getField(fLayout.fieldPtr()).getValue(); if (ZERO.equals(ptr)) { return; } setMem(event, ptr, ZERO); } break; - case UstMemoryStrings.CALLOC: { - Long ptr = (Long) event.getContent().getField(UstMemoryStrings.FIELD_PTR).getValue(); + case CALLOC_INDEX: { + Long ptr = (Long) event.getContent().getField(fLayout.fieldPtr()).getValue(); if (ZERO.equals(ptr)) { return; } - Long nmemb = (Long) event.getContent().getField(UstMemoryStrings.FIELD_NMEMB).getValue(); - Long size = (Long) event.getContent().getField(UstMemoryStrings.FIELD_SIZE).getValue(); + Long nmemb = (Long) event.getContent().getField(fLayout.fieldNmemb()).getValue(); + Long size = (Long) event.getContent().getField(fLayout.fieldSize()).getValue(); setMem(event, ptr, size * nmemb); } break; - case UstMemoryStrings.REALLOC: { - Long ptr = (Long) event.getContent().getField(UstMemoryStrings.FIELD_PTR).getValue(); + case REALLOC_INDEX: { + Long ptr = (Long) event.getContent().getField(fLayout.fieldPtr()).getValue(); if (ZERO.equals(ptr)) { return; } - Long newPtr = (Long) event.getContent().getField(UstMemoryStrings.FIELD_INPTR).getValue(); - Long size = (Long) event.getContent().getField(UstMemoryStrings.FIELD_SIZE).getValue(); + Long newPtr = (Long) event.getContent().getField(fLayout.fieldInPtr()).getValue(); + Long size = (Long) event.getContent().getField(fLayout.fieldSize()).getValue(); setMem(event, ptr, ZERO); setMem(event, newPtr, size); } break; - case UstMemoryStrings.MEMALIGN: { - Long ptr = (Long) event.getContent().getField(UstMemoryStrings.FIELD_PTR).getValue(); + case MEMALIGN_INDEX: { + Long ptr = (Long) event.getContent().getField(fLayout.fieldPtr()).getValue(); if (ZERO.equals(ptr)) { return; } - Long size = (Long) event.getContent().getField(UstMemoryStrings.FIELD_SIZE).getValue(); + Long size = (Long) event.getContent().getField(fLayout.fieldSize()).getValue(); setMem(event, ptr, size); } break; - case UstMemoryStrings.POSIX_MEMALIGN: { - Long ptr = (Long) event.getContent().getField(UstMemoryStrings.FIELD_OUTPTR).getValue(); + case POSIX_MEMALIGN_INDEX: { + Long ptr = (Long) event.getContent().getField(fLayout.fieldOutPtr()).getValue(); if (ZERO.equals(ptr)) { return; } - Long size = (Long) event.getContent().getField(UstMemoryStrings.FIELD_SIZE).getValue(); + Long size = (Long) event.getContent().getField(fLayout.fieldSize()).getValue(); setMem(event, ptr, size); } break; default: + /* Ignore other event types */ break; } @@ -141,16 +171,16 @@ public class UstMemoryStateProvider extends AbstractTmfStateProvider { return VERSION; } - private static Long getVtid(ITmfEvent event) { - ITmfEventField field = event.getContent().getField(UstMemoryStrings.CONTEXT_VTID); + private Long getVtid(ITmfEvent event) { + ITmfEventField field = event.getContent().getField(fLayout.contextVtid()); if (field == null) { return MINUS_ONE; } return (Long) field.getValue(); } - private static String getProcname(ITmfEvent event) { - ITmfEventField field = event.getContent().getField(UstMemoryStrings.CONTEXT_PROCNAME); + private String getProcname(ITmfEvent event) { + ITmfEventField field = event.getContent().getField(fLayout.contextProcname()); if (field == null) { return EMPTY_STRING; }