chrome tracing is pretty cool
This commit is contained in:
parent
3514eb313e
commit
19ebea8b95
|
@ -0,0 +1,56 @@
|
||||||
|
package com.rusefi.tracing;
|
||||||
|
|
||||||
|
public class Entry {
|
||||||
|
private final String name;
|
||||||
|
private final Phase phase;
|
||||||
|
private final double timestampSeconds;
|
||||||
|
|
||||||
|
public Entry(String name, Phase phase, double timestampSeconds) {
|
||||||
|
this.name = name;
|
||||||
|
this.phase = phase;
|
||||||
|
this.timestampSeconds = timestampSeconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void AppendKeyValuePair(StringBuilder sb, String x, String y) {
|
||||||
|
sb.append('"');
|
||||||
|
sb.append(x);
|
||||||
|
sb.append("\":\"");
|
||||||
|
sb.append(y);
|
||||||
|
sb.append('"');
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void AppendKeyValuePair(StringBuilder sb, String x, int y) {
|
||||||
|
sb.append('"');
|
||||||
|
sb.append(x);
|
||||||
|
sb.append("\":");
|
||||||
|
sb.append(y);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void AppendKeyValuePair(StringBuilder sb, String x, double y) {
|
||||||
|
sb.append('"');
|
||||||
|
sb.append(x);
|
||||||
|
sb.append("\":");
|
||||||
|
sb.append(y);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
sb.append("{");
|
||||||
|
AppendKeyValuePair(sb, "name", name);
|
||||||
|
|
||||||
|
sb.append(",");
|
||||||
|
AppendKeyValuePair(sb, "ph", phase.toString());
|
||||||
|
sb.append(",");
|
||||||
|
AppendKeyValuePair(sb, "tid", 0);
|
||||||
|
sb.append(",");
|
||||||
|
|
||||||
|
AppendKeyValuePair(sb, "pid", 0);
|
||||||
|
sb.append(",");
|
||||||
|
AppendKeyValuePair(sb, "ts", timestampSeconds);
|
||||||
|
sb.append("}");
|
||||||
|
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package com.rusefi.tracing;
|
||||||
|
|
||||||
|
public enum Phase {
|
||||||
|
B,
|
||||||
|
E,
|
||||||
|
i,
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package com.rusefi.tracing.test;
|
||||||
|
|
||||||
|
import com.rusefi.tracing.Entry;
|
||||||
|
import com.rusefi.tracing.Phase;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
public class EntryTest {
|
||||||
|
@Test
|
||||||
|
public void testToString() {
|
||||||
|
Entry e = new Entry("hello", Phase.E, 0.1);
|
||||||
|
|
||||||
|
assertEquals("{\"name\":\"hello\",\"ph\":\"E\",\"tid\":0,\"pid\":0,\"ts\":0.1}", e.toString());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue