lttng.ust: Add logging to FileOffsetMapper
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.ust.core / src / org / eclipse / tracecompass / internal / lttng2 / ust / core / analysis / debuginfo / FileOffsetMapper.java
index c2fe8d4e1107a0dbda560881c8290d2503b93bbe..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$
 
@@ -51,10 +55,10 @@ public final class FileOffsetMapper {
     private static class FileOffset {
 
         private final String fFilePath;
-        private final String fBuildId;
+        private final @Nullable String fBuildId;
         private final long fOffset;
 
-        public FileOffset(String filePath, String buildId, long offset) {
+        public FileOffset(String filePath, @Nullable String buildId, long offset) {
             fFilePath = filePath;
             fBuildId = buildId;
             fOffset = offset;
@@ -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);
                 }
             }));
@@ -119,15 +133,21 @@ public final class FileOffsetMapper {
      * @return The list of callsites corresponding to the offset, reported from
      *         the "highest" inlining location, down to the initial definition.
      */
-    public static @Nullable Iterable<SourceCallsite> getCallsiteFromOffset(File file, String buildId, long offset) {
+    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.036744 seconds and 5 git commands to generate.