common.core: add marker events
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Sat, 10 Dec 2016 01:20:04 +0000 (20:20 -0500)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Wed, 10 May 2017 19:56:37 +0000 (15:56 -0400)
These will help create custom markers.

Change-Id: Ia0a9cd4d5d9272a01b8ee7f6aeaab421ebe0cfc4
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/87265
Reviewed-by: Hudson CI
Reviewed-by: Genevieve Bastien <gbastien+lttng@versatic.net>
Tested-by: Genevieve Bastien <gbastien+lttng@versatic.net>
common/org.eclipse.tracecompass.common.core.tests/src/org/eclipse/tracecompass/common/core/tests/log/LoggerTest.java
common/org.eclipse.tracecompass.common.core/src/org/eclipse/tracecompass/common/core/log/TraceCompassLogUtils.java

index f946e77357342c3de54b8dad7b7a1ddd8316d034..5cde3740d533a3a94570f5244ecef050d02b5d53 100644 (file)
@@ -549,4 +549,18 @@ public class LoggerTest {
         assertEquals("FINER: {\"ts\":0,\"ph\":\"C\",\"tid\":1,\"name\":\"counter\",\"args\":{\"cats\":0}}", fLog.getMessages().get(2));
     }
 
+    /**
+     * Test Marker
+     */
+    @Test
+    public void testMarker() {
+        Logger logger = fLogger;
+        assertNotNull(logger);
+        TraceCompassLogUtils.traceMarker(logger, Level.CONFIG, "instant", 0);
+        TraceCompassLogUtils.traceMarker(logger, Level.CONFIG, "colored", 15, "color", 0xaabccdd);
+        fStreamHandler.flush();
+        assertEquals("CONFIG: {\"ts\":0,\"ph\":\"R\",\"tid\":1,\"name\":\"instant\",\"dur\":0}", fLog.getMessages().get(0));
+        assertEquals("CONFIG: {\"ts\":0,\"ph\":\"R\",\"tid\":1,\"name\":\"colored\",\"dur\":15,\"args\":{\"color\":179031261}}", fLog.getMessages().get(1));
+    }
+
 }
index 04f4b2c1e1de10af1b804cc5243c08c804c8a90f..337844e39f6dbbc682c6a2b01358d8c2cbc3d6b3 100644 (file)
@@ -712,6 +712,37 @@ public final class TraceCompassLogUtils {
         });
     }
 
+    /**
+     * The Marker events are events with a duration that define a region of
+     * interest. These regions can be displayed in views as Markers or other
+     * indicators.
+     *
+     * @param logger
+     *            The Logger
+     * @param level
+     *            The {@link Level} of this event.
+     * @param name
+     *            The name of the marker message message
+     * @param duration
+     *            How long the marker should last
+     * @param args
+     *            The counters to log in the format : "title", value, note
+     *            "color" and an rbga will be used
+     */
+    public static void traceMarker(Logger logger, Level level, @Nullable String name, long duration, Object... args) {
+        long time = System.nanoTime();
+        long threadId = Thread.currentThread().getId();
+        logger.log(level, () -> {
+            StringBuilder sb = new StringBuilder();
+            sb.append('{');
+            appendCommon(sb, 'R', time, threadId);
+            appendName(sb, name);
+            sb.append(',');
+            writeObject(sb, "dur", duration); //$NON-NLS-1$
+            return appendArgs(sb, args).append('}').toString();
+        });
+    }
+
     // -------------------------------------------------------------------------
     // Helpers
     // -------------------------------------------------------------------------
This page took 0.025508 seconds and 5 git commands to generate.