chrome tracing is pretty cool

This commit is contained in:
rusefi 2019-11-22 17:19:44 -05:00
parent bb22296f61
commit 16faa4c0be
2 changed files with 45 additions and 0 deletions

View File

@ -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/
* <p>
* See https://github.com/catapult-project/catapult/blob/master/tracing/README.md
*/
public class JsonOutput {
public static void main(String[] args) throws IOException {
List<Entry> 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<Entry> 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();
}
}

View File

@ -1,7 +1,9 @@
package com.rusefi.tracing;
public enum Phase {
// Begin
B,
// End
E,
i,
}