From 16faa4c0be3f44307c78d48e969bbddc38734d3b Mon Sep 17 00:00:00 2001 From: rusefi Date: Fri, 22 Nov 2019 17:19:44 -0500 Subject: [PATCH] chrome tracing is pretty cool --- .../src/com/rusefi/tracing/JsonOutput.java | 43 +++++++++++++++++++ .../models/src/com/rusefi/tracing/Phase.java | 2 + 2 files changed, 45 insertions(+) create mode 100644 java_console/models/src/com/rusefi/tracing/JsonOutput.java diff --git a/java_console/models/src/com/rusefi/tracing/JsonOutput.java b/java_console/models/src/com/rusefi/tracing/JsonOutput.java new file mode 100644 index 0000000000..96931b73d7 --- /dev/null +++ b/java_console/models/src/com/rusefi/tracing/JsonOutput.java @@ -0,0 +1,43 @@ +package com.rusefi.tracing; + +import java.io.*; +import java.util.Arrays; +import java.util.List; + +/** + * This class helps to write JSON files readable by chrome://tracing/ + *

+ * See https://github.com/catapult-project/catapult/blob/master/tracing/README.md + */ +public class JsonOutput { + + public static void main(String[] args) throws IOException { + List testEntries = Arrays.asList( + new Entry("hello", Phase.B, 0.1), + new Entry("hello2", Phase.B, 0.2), + new Entry("hello2", Phase.E, 0.3), + new Entry("hello", Phase.E, 0.4) + ); + + writeToStream(testEntries, new FileOutputStream("hello_trace.json")); + } + + private static void writeToStream(List testEntries, OutputStream outputStream) throws IOException { + + Writer out = new OutputStreamWriter(outputStream); + out.write("{\"traceEvents\": [\n"); + + boolean isFirst = true; + for (Entry e : testEntries) { + if (isFirst) { + isFirst = false; + } else { + out.write(","); + } + out.write(e.toString() + "\r\n"); + } + + out.write("]}"); + out.close(); + } +} diff --git a/java_console/models/src/com/rusefi/tracing/Phase.java b/java_console/models/src/com/rusefi/tracing/Phase.java index fceb035743..c1185d798f 100644 --- a/java_console/models/src/com/rusefi/tracing/Phase.java +++ b/java_console/models/src/com/rusefi/tracing/Phase.java @@ -1,7 +1,9 @@ package com.rusefi.tracing; public enum Phase { + // Begin B, + // End E, i, }