lttng.ust: Add logging to FileOffsetMapper
authorAlexandre Montplaisir <alexmonthy@efficios.com>
Thu, 30 Jun 2016 18:11:27 +0000 (14:11 -0400)
committerAlexandre Montplaisir <alexmonthy@efficios.com>
Mon, 11 Jul 2016 23:16:07 +0000 (19:16 -0400)
Should help identify requests and cache hits/misses more easily.

Change-Id: I80eb4b405ad0ceb61e6a8386d397d110729badd0
Signed-off-by: Alexandre Montplaisir <alexmonthy@efficios.com>
Reviewed-on: https://git.eclipse.org/r/76399
Reviewed-by: Hudson CI
common/org.eclipse.tracecompass.common.core/annotations/com/google/common/base/Objects$ToStringHelper.eea [new file with mode: 0644]
lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/internal/lttng2/ust/core/analysis/debuginfo/FileOffsetMapper.java

diff --git a/common/org.eclipse.tracecompass.common.core/annotations/com/google/common/base/Objects$ToStringHelper.eea b/common/org.eclipse.tracecompass.common.core/annotations/com/google/common/base/Objects$ToStringHelper.eea
new file mode 100644 (file)
index 0000000..ae974a0
--- /dev/null
@@ -0,0 +1,4 @@
+class com/google/common/base/Objects$ToStringHelper
+toString
+ ()Ljava/lang/String;
+ ()L1java/lang/String;
index 69c7b1f6661ddd5382bbeab5a5945c3bdfdfe783..d426042769be636d9e14de3b6730c56c6350f356 100644 (file)
@@ -19,9 +19,11 @@ import java.nio.file.Files;
 import java.util.Arrays;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.logging.Logger;
 import java.util.stream.Collectors;
 
 import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.common.core.log.TraceCompassLog;
 import org.eclipse.tracecompass.lttng2.ust.core.analysis.debuginfo.SourceCallsite;
 import org.eclipse.tracecompass.tmf.core.event.lookup.TmfCallsite;
 
@@ -38,6 +40,8 @@ import com.google.common.cache.LoadingCache;
  */
 public final class FileOffsetMapper {
 
+    private static final Logger LOGGER = TraceCompassLog.getLogger(FileOffsetMapper.class);
+
     private static final String DISCRIMINATOR = "\\(discriminator.*\\)"; //$NON-NLS-1$
     private static final String ADDR2LINE_EXECUTABLE = "addr2line"; //$NON-NLS-1$
 
@@ -81,6 +85,15 @@ public final class FileOffsetMapper {
                     Objects.equal(fBuildId, other.fBuildId) &&
                     Objects.equal(fOffset, other.fOffset);
         }
+
+        @Override
+        public String toString() {
+            return Objects.toStringHelper(this)
+                    .add("fFilePath", fFilePath) //$NON-NLS-1$
+                    .add("fBuildId", fBuildId) //$NON-NLS-1$
+                    .add("fOffset", String.format("0x%h", fOffset)) //$NON-NLS-1$ //$NON-NLS-2$
+                    .toString();
+        }
     }
 
     /**
@@ -97,6 +110,7 @@ public final class FileOffsetMapper {
             .build(new CacheLoader<FileOffset, @Nullable Iterable<SourceCallsite>>() {
                 @Override
                 public @Nullable Iterable<SourceCallsite> load(FileOffset fo) {
+                    LOGGER.fine(() -> "[FileOffsetMapper:CacheMiss] file/offset=" + fo.toString()); //$NON-NLS-1$
                     return getCallsiteFromOffsetWithAddr2line(fo);
                 }
             }));
@@ -120,14 +134,20 @@ public final class FileOffsetMapper {
      *         the "highest" inlining location, down to the initial definition.
      */
     public static @Nullable Iterable<SourceCallsite> getCallsiteFromOffset(File file, @Nullable String buildId, long offset) {
+        LOGGER.finer(() -> String.format("[FileOffsetMapper:Request] file=%s, buildId=%s, offset=0x%h", //$NON-NLS-1$
+                file.toString(), buildId, offset));
+
         if (!Files.exists((file.toPath()))) {
+            LOGGER.finer(() -> "[FileOffsetMapper:RequestFailed] File not found"); //$NON-NLS-1$
             return null;
         }
         // TODO We should also eventually verify that the passed buildId matches
         // the file we are attempting to open.
-
         FileOffset fo = new FileOffset(checkNotNull(file.toString()), buildId, offset);
-        return CALLSITE_CACHE.getUnchecked(fo);
+
+        Iterable<SourceCallsite> callsites = CALLSITE_CACHE.getUnchecked(fo);
+        LOGGER.finer(() -> String.format("[FileOffsetMapper:RequestComplete] callsites=%s", callsites)); //$NON-NLS-1$
+        return callsites;
     }
 
     private static @Nullable Iterable<SourceCallsite> getCallsiteFromOffsetWithAddr2line(FileOffset fo) {
This page took 0.027173 seconds and 5 git commands to generate.