Skip to content
Permalink
Browse files

Expose UUID related tagging methods

Benchmarks:

```
Benchmark                            (enabled)  Mode  Cnt   Score   Error  Units
EnabledBenchmark.attachKeyedTag_sn        true  avgt    5   7.321 ± 0.370  ns/op
EnabledBenchmark.attachKeyedTag_sn       false  avgt    5   0.596 ± 0.011  ns/op
EnabledBenchmark.attachKeyedTag_snn       true  avgt    5   8.508 ± 0.161  ns/op
EnabledBenchmark.attachKeyedTag_snn      false  avgt    5   0.598 ± 0.015  ns/op
EnabledBenchmark.attachKeyedTag_ss        true  avgt    5   8.340 ± 0.076  ns/op
EnabledBenchmark.attachKeyedTag_ss       false  avgt    5   0.604 ± 0.025  ns/op
EnabledBenchmark.createTag                true  avgt    5   5.243 ± 0.162  ns/op
EnabledBenchmark.createTag               false  avgt    5   2.660 ± 0.023  ns/op
EnabledBenchmark.event                    true  avgt    5  32.908 ± 0.214  ns/op
EnabledBenchmark.event                   false  avgt    5   0.605 ± 0.012  ns/op
EnabledBenchmark.link                     true  avgt    5  12.158 ± 0.197  ns/op
EnabledBenchmark.link                    false  avgt    5   0.597 ± 0.011  ns/op
EnabledBenchmark.startStop                true  avgt    5  60.273 ± 0.852  ns/op
EnabledBenchmark.startStop               false  avgt    5   0.603 ± 0.006  ns/op
```
  • Loading branch information
carl-mastrangelo committed Nov 9, 2019
1 parent 9def59c commit c3e723cac4600327653ce273ef5804d6d248df33
@@ -25,12 +25,8 @@ compileJmhJava {
targetCompatibility = 1.9
}

configurations {
jmhCompileClasspath {
attributes {
attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 9)
}
}
java {
disableAutoTargetJvm()
}

javadoc {
@@ -43,6 +39,8 @@ jmh {
fork = 1
warmupIterations = 10

duplicateClassesStrategy "include"

/*
profilers = ["perfasm"]
@@ -67,4 +67,25 @@ public void link() {
public void event() {
PerfMark.event("hi", TAG);
}

@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void attachKeyedTag_ss() {
PerfMark.attachTag("hi", "there");
}

@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void attachKeyedTag_sn() {
PerfMark.attachTag("hi", 934);
}

@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void attachKeyedTag_snn() {
PerfMark.attachTag("hi", 934, 5);
}
}
@@ -65,6 +65,12 @@ protected void linkIn(Link link) {}

protected void attachTag(Tag tag) {}

protected void attachTag(String tagName, String tagValue) {}

protected void attachTag(String tagName, long tagValue) {}

protected void attachTag(String tagName, long tagValue0, long tagValue1) {}

protected Tag createTag(@Nullable String tagName, long tagId) {
return NO_TAG;
}
@@ -324,5 +324,67 @@ public static void attachTag(Tag tag) {
impl.attachTag(tag);
}

/**
* Attaches an additional keyed tag to the current active task. The tag provided is independent of
* the tag used with {@code startTask} and {@code stopTask}. This tag operation is different than
* {@link Tag} in that the tag value has an associated name (also called a key). The tag name and
* value are attached to the most recently started task, and don't have to match any other tags.
* This method is useful for when you have the tag information after the task is started.
*
* @param tagName The name of the value being attached
* @param tagValue The value to attach to the current task.
* @since 0.20.0
*/
public static void attachTag(String tagName, String tagValue) {
impl.attachTag(tagName, tagValue);
}

/**
* Attaches an additional keyed tag to the current active task. The tag provided is independent of
* the tag used with {@code startTask} and {@code stopTask}. This tag operation is different than
* {@link Tag} in that the tag value has an associated name (also called a key). The tag name and
* value are attached to the most recently started task, and don't have to match any other tags.
* This method is useful for when you have the tag information after the task is started.
*
* @param tagName The name of the value being attached
* @param tagValue The value to attach to the current task.
* @since 0.20.0
*/
public static void attachTag(String tagName, long tagValue) {
impl.attachTag(tagName, tagValue);
}

/**
* Attaches an additional keyed tag to the current active task. The tag provided is independent of
* the tag used with {@code startTask} and {@code stopTask}. This tag operation is different than
* {@link Tag} in that the tag values have an associated name (also called a key). The tag name
* and values are attached to the most recently started task, and don't have to match any other
* tags. This method is useful for when you have the tag information after the task is started.
*
* <p>This method may treat the given two longs as special. If the tag name contains the string
* "uuid" (case insensitive), the value may be treated as a single 128 bit value. An example
* usage:
*
* <pre>
* RPC rpc = ...
* PerfMark.startTask("sendRPC");
* try {
* UUID u = rpc.uuid();
* PerfMark.attachTag("rpc uuid", u.getMostSignificantBits(), u.getLeastSignificantBits());
* send(rpc);
* } finally {
* PerfMark.stopTask("sendRPC");
* }
* </pre>
*
* @param tagName The name of the value being attached
* @param tagValue0 The first value to attach to the current task.
* @param tagValue1 The second value to attach to the current task.
* @since 0.20.0
*/
public static void attachTag(String tagName, long tagValue0, long tagValue1) {
impl.attachTag(tagName, tagValue0, tagValue1);
}

private PerfMark() {}
}
@@ -233,6 +233,33 @@ protected void attachTag(Tag tag) {
Storage.attachTagAnyways(gen, unpackTagName(tag), unpackTagId(tag));
}

@Override
protected void attachTag(String tagName, String tagValue) {
final long gen = getGen();
if (!isEnabled(gen)) {
return;
}
Storage.attachKeyedTagAnyways(gen, tagName, tagValue);
}

@Override
protected void attachTag(String tagName, long tagValue) {
final long gen = getGen();
if (!isEnabled(gen)) {
return;
}
Storage.attachKeyedTagAnyways(gen, tagName, tagValue);
}

@Override
protected void attachTag(String tagName, long tagValue0, long tagValue1) {
final long gen = getGen();
if (!isEnabled(gen)) {
return;
}
Storage.attachKeyedTagAnyways(gen, tagName, tagValue0, tagValue1);
}

@Override
protected Tag createTag(@Nullable String tagName, long tagId) {
if (!isEnabled(getGen())) {
@@ -196,6 +196,19 @@ static void attachTagAnyways(long gen, @Nullable String tagName, long tagId) {
localMarkHolder.get().attachTag(gen, tagName, tagId);
}

static void attachKeyedTagAnyways(long gen, @Nullable String tagName, String tagValue) {
localMarkHolder.get().attachKeyedTag(gen, tagName, tagValue);
}

static void attachKeyedTagAnyways(long gen, @Nullable String tagName, long tagValue) {
localMarkHolder.get().attachKeyedTag(gen, tagName, tagValue);
}

static void attachKeyedTagAnyways(
long gen, @Nullable String tagName, long tagValue0, long tagValue1) {
localMarkHolder.get().attachKeyedTag(gen, tagName, tagValue0, tagValue1);
}

public static void resetForTest() {
localMarkHolder.remove();
}
@@ -16,6 +16,7 @@

package io.perfmark.java9;

import io.perfmark.impl.Generator;
import io.perfmark.impl.MarkHolder;
import io.perfmark.impl.MarkHolderProvider;

@@ -26,8 +27,8 @@
public VarHandleMarkHolderProvider() {
// Do some basic operations to see if it works.
MarkHolder holder = create();
holder.start(1, "bogus", 0);
holder.stop(1, "bogus", 0);
holder.start(1 << Generator.GEN_OFFSET, "bogus", 0);
holder.stop(1 << Generator.GEN_OFFSET, "bogus", 0);
int size = holder.read(false).size();
if (size != 2) {
throw new AssertionError("Wrong size " + size);
@@ -223,12 +223,4 @@ public void read_getsAllIfNotWriterButNoWrap() {
List<Mark> marks = mh.read(true);
assertEquals(events, marks.size());
}

@Test
public void bb() {
ByteBuffer buf = ByteBuffer.allocateDirect(4096).alignedSlice(4);
VarHandle q = MethodHandles.byteBufferViewVarHandle(int[].class, ByteOrder.LITTLE_ENDIAN);
q.setVolatile(buf, 0, 1);
System.out.println((int) q.getVolatile(buf, 0));
}
}
@@ -109,12 +109,11 @@ protected void onMarker(Mark mark) {}
List<? extends MarkList> markLists) {
Map<Long, List<MarkList>> generationToMarkLists = new TreeMap<>();
for (MarkList markList : markLists) {
List<Mark> marks = markList;
if (marks.isEmpty()) {
if (markList.isEmpty()) {
continue;
}
Map<Long, List<Mark>> generationToMarks = new TreeMap<>();
for (Mark mark : marks) {
for (Mark mark : markList) {
List<Mark> groupedMarks = generationToMarks.get(mark.getGeneration());
if (groupedMarks == null) {
generationToMarks.put(mark.getGeneration(), groupedMarks = new ArrayList<>());

0 comments on commit c3e723c

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