Skip to content
Permalink
Browse files

Update tracewrite to use new format

  • Loading branch information...
carl-mastrangelo committed Nov 3, 2019
1 parent a3c254f commit a03d6a90c059502634c6bba2b805d109a11607cb
@@ -105,10 +105,6 @@ public static void startTask(String taskName, String subTaskName) {
impl.startTask(taskName + subTaskName);
}

public static void startTask(DelayedString taskName) {
impl.startTask(taskName.get());
}

/**
* Marks an event. Events are logically both a task start and a task end. Events have no duration
* associated. Events still represent the instant something occurs. If PerfMark is disabled, this
@@ -148,10 +148,16 @@ private Mark(

LINK(OperationType.LINK, 1, 0),

/** An unkeyed tag that has a single string value. */
TAG_N0S1(OperationType.TAG, 0, 1),
TAG_N0S2(OperationType.TAG, 0, 2),
/** An unkeyed tag that has a single numeric value. */
TAG_N1S0(OperationType.TAG, 1, 0),
/**
* An unkeyed tag that has a string and numeric value. The values are unrelated to each other.
*/
TAG_N1S1(OperationType.TAG, 1, 1),

TAG_KEYED_N0S2(OperationType.TAG, 0, 2),
;

private final OperationType opType;
@@ -210,45 +216,62 @@ public Operation getOperation() {
return operation;
}

@Nullable
@Deprecated
public String getTagName() {
public String getTagStringValue() {
switch (operation) {
case TAG_N0S1:
case TAG_N1S1:
return s1;
case TAG_N0S2:
return tagName(s1, s2);
case TAG_KEYED_N0S2:
case EVENT_N2S2:
return s2;
case EVENT_N2S3:
return s3;
case TAG_N1S0:
return Long.toString(n1);
case TAG_N1S1:
return tagName(s1, Long.toString(n1));
case NONE:
case TASK_START_N1S1:
case TASK_START_N1S2:
case TASK_END_N1S1:
case TASK_END_N1S2:
case EVENT_N1S1:
case EVENT_N1S2:
case MARK:
case LINK:
throw new UnsupportedOperationException();
}
throw new AssertionError(operation.opType);
}

public long getTagFirstNumeric() {
switch (operation) {
case TAG_N1S0:
case TAG_N1S1:
return n1;
case EVENT_N2S2:
case EVENT_N2S3:
return n2;
case TAG_N0S1:
case TAG_KEYED_N0S2:
case NONE:
case TASK_START_N1S1:
case TASK_START_N1S2:
case TASK_END_N1S1:
case TASK_END_N1S2:
case EVENT_N1S1:
case EVENT_N1S2:
case MARK:
case LINK:
throw new UnsupportedOperationException();
}
throw new AssertionError(operation.opType);
}

@Deprecated
public long getTagId() {
public String getTagKey() {
switch (operation) {
case TAG_KEYED_N0S2:
return s1;
case TAG_N1S1:
case TAG_N0S1:
return NO_TAG_ID;
case TAG_N0S2:
return NO_TAG_ID;
case TAG_N1S0:
return n1;
case TAG_N1S1:
return n1;
case NONE:
case TASK_START_N1S1:
case TASK_START_N1S2:
@@ -281,14 +304,6 @@ public Marker getMarker() {
throw new AssertionError(operation.opType);
}

public static String joinTaskName(String taskName, String subTaskName) {
return taskName + '.' + subTaskName;
}

public static String tagName(String tagName, String tagValue) {
return tagName + ':' + tagValue;
}

public String getTaskName() {
switch (operation) {
case TASK_START_N1S1:
@@ -304,9 +319,9 @@ public String getTaskName() {
case MARK:
case LINK:
case TAG_N0S1:
case TAG_N0S2:
case TAG_N1S0:
case TAG_N1S1:
case TAG_KEYED_N0S2:
throw new UnsupportedOperationException();
}
throw new AssertionError(operation);
@@ -318,7 +333,7 @@ public String getSubTaskName() {
case TASK_START_N1S2:
case EVENT_N1S2:
case EVENT_N2S3:
return s1;
return s2;
case TASK_START_N1S1:
case TASK_END_N1S1:
case EVENT_N1S1:
@@ -327,7 +342,7 @@ public String getSubTaskName() {
case MARK:
case LINK:
case TAG_N0S1:
case TAG_N0S2:
case TAG_KEYED_N0S2:
case TAG_N1S0:
case TAG_N1S1:
throw new UnsupportedOperationException();
@@ -84,6 +84,9 @@ private void onRealMark(Mark mark, Collection<Mark> unmatchedPairMarks) {
case LINK:
onLink(mark);
return;
case MARK:
onMarker(mark);
return;
case NONE:
break;
}
@@ -100,6 +103,8 @@ protected void onEvent(Mark mark) {}

protected void onAttachTag(Mark mark) {}

protected void onMarker(Mark mark) {}

private static Map<Long, List<MarkList>> groupMarkListsByGeneration(
List<? extends MarkList> markLists) {
Map<Long, List<MarkList>> generationToMarkLists = new TreeMap<>();
@@ -159,6 +164,7 @@ private static void createFakes(
case EVENT:
case LINK:
case TAG:
case MARK:
continue loop;
case NONE:
break;
@@ -186,6 +192,7 @@ private static void setNanoTimeBounds(long[] nanoTimeBounds, Mark mark) {
return;
case LINK:
case TAG:
case MARK:
return;
case NONE:
break;
@@ -209,7 +216,7 @@ private static Mark createFakeEnd(Mark start, long lastNanoTime) {
case MARK:
case LINK:
case TAG_N0S1:
case TAG_N0S2:
case TAG_KEYED_N0S2:
case TAG_N1S0:
case TAG_N1S1:
case NONE:
@@ -235,7 +242,7 @@ private static Mark createFakeStart(Mark end, long firstNanoTime) {
case MARK:
case LINK:
case TAG_N0S1:
case TAG_N0S2:
case TAG_KEYED_N0S2:
case TAG_N1S0:
case TAG_N1S1:
break;
@@ -17,12 +17,14 @@
package io.perfmark.tracewriter;

import com.google.gson.annotations.SerializedName;
import io.perfmark.impl.Mark;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Set;
import javax.annotation.CheckReturnValue;
import javax.annotation.Nullable;

@@ -69,15 +71,13 @@ private TraceEvent() {}
@Nullable
@SerializedName("args")
@SuppressWarnings("unused")
private Map<String, ?> args = null;
private TagMap args = null;

@Nullable
@SerializedName("cname")
@SuppressWarnings("unused")
private String colorName = null;

private transient int argCalls;

TraceEvent name(String name) {
if (name == null) {
throw new NullPointerException("name");
@@ -154,64 +154,24 @@ TraceEvent id(long id) {
* Note This should only be used for tags, as the map size is used to determine the arg names in
* TraceEventWriter. This will overwrite any existing args.
*
* @param args the args to use.
* @param tagMap the args to use.
* @return this
*/
TraceEvent args(Map<String, ?> args) {
if (args == null) {
throw new NullPointerException("args");
}
Map<String, Object> newArgs = new LinkedHashMap<>(args.size());
for (Map.Entry<String, ?> arg : args.entrySet()) {
if (arg.getKey() == null) {
throw new NullPointerException("key");
}
if (arg.getValue() == null) {
throw new NullPointerException("value");
}
newArgs.put(arg.getKey(), arg.getValue());
TraceEvent args(TagMap tagMap) {
if (tagMap == null) {
throw new NullPointerException("tagMap");
}
TraceEvent other = clone();
if (!newArgs.isEmpty()) {
other.args = Collections.unmodifiableMap(newArgs);
} else {
other.args = null;
}
other.args = tagMap;
return other;
}

/**
* Note This should only be used for tags, as the map size is used to determine the arg names in
* TraceEventWriter.
*
* @param argKey the arg key
* @param argValue the arg value
* @return this
*/
TraceEvent arg(String argKey, Object argValue) {
if (argKey == null) {
throw new NullPointerException("argKey");
}
if (argValue == null) {
throw new NullPointerException("argValue");
}
TraceEvent other = clone();
TagMap args() {
if (args == null) {
other.args = Collections.singletonMap(argKey, argValue);
return TagMap.EMPTY;
} else {
Map<String, Object> newArgs = new LinkedHashMap<>(args);
newArgs.put(argKey, argValue);
other.args = Collections.unmodifiableMap(newArgs);
return args;
}
return other;
}

int getArgsSize() {
return argCalls;
}

void incrementArgsSize() {
argCalls++;
}

@Override
@@ -222,4 +182,46 @@ protected TraceEvent clone() {
throw new RuntimeException(e);
}
}

static final class TagMap extends AbstractMap<String, Object> {

static final TagMap EMPTY =
new TagMap(Collections.<Entry<String, ?>>emptyList(), Collections.emptyList());

private final List<Entry<String, ?>> keyedValues;
private final List<?> unkeyedValues;

private TagMap(List<Entry<String, ?>> keyedValues, List<?> unkeyedValues) {
this.keyedValues = keyedValues;
this.unkeyedValues = unkeyedValues;
}

TagMap withUnkeyed(@Nullable String tagName, long tagId) {
List<Object> unkeyedValues = null;
if (tagName != null && !Mark.NO_TAG_NAME.equals(tagName)) {
unkeyedValues = new ArrayList<>(this.unkeyedValues);
unkeyedValues.add(tagName);
}
if (tagId != Mark.NO_TAG_ID) {
unkeyedValues = unkeyedValues != null ? unkeyedValues : new ArrayList<>(this.unkeyedValues);
unkeyedValues.add(tagId);
}
if (unkeyedValues != null) {
return new TagMap(keyedValues, Collections.unmodifiableList(unkeyedValues));
} else {
return new TagMap(keyedValues, this.unkeyedValues);
}
}

TagMap withKeyed(@Nullable String tagName, Object tagValue) {
List<Entry<String, ?>> keyedValues = new ArrayList<>(this.keyedValues);
keyedValues.add(new SimpleImmutableEntry<>(String.valueOf(tagName), tagValue));
return new TagMap(Collections.unmodifiableList(keyedValues), unkeyedValues);
}

@Override
public Set<Entry<String, Object>> entrySet() {
return null;
}
}
}

0 comments on commit a03d6a9

Please sign in to comment.
You can’t perform that action at this time.