Skip to content

Commit

Permalink
api: record if PerfMark.setEnabled succeeded (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
carl-mastrangelo committed Nov 8, 2022
1 parent 28cff69 commit ef41d3c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
4 changes: 4 additions & 0 deletions api/src/main/java/io/perfmark/Impl.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ protected Impl(Tag key) {

protected void setEnabled(boolean value) {}

protected boolean setEnabled(boolean value, boolean overload) {
return false;
}

protected <T> void startTask(T taskNameObject, StringFunction<? super T> taskNameFunc) {}

protected void startTask(String taskName, Tag tag) {}
Expand Down
6 changes: 4 additions & 2 deletions api/src/main/java/io/perfmark/PerfMark.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.perfmark;

import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.DoNotCall;
import com.google.errorprone.annotations.MustBeClosed;
import java.lang.reflect.Method;
Expand Down Expand Up @@ -96,8 +97,9 @@ public final class PerfMark {
*
* @param value {@code true} to enable PerfMark recording, or {@code false} to disable it.
*/
public static void setEnabled(boolean value) {
impl.setEnabled(value);
@CanIgnoreReturnValue
public static boolean setEnabled(boolean value) {
return impl.setEnabled(value, false);
}

/**
Expand Down
3 changes: 3 additions & 0 deletions api/src/test/java/io/perfmark/CompatibilityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ public void checkPublicMethods() throws Exception {

var m = currentPerfMarkClz.getMethod(method.getName(), paramTypes);
assertNotNull(method.getName(), m);
if (returnType == void.class) {
return;
}
assertEquals(m.getReturnType(), returnType);
}
}
Expand Down
10 changes: 9 additions & 1 deletion impl/src/main/java/io/perfmark/impl/SecretPerfMarkImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,15 @@ public PerfMarkImpl(Tag key) {

@Override
protected synchronized void setEnabled(boolean value) {
logEnabledChange(value, setEnabledQuiet(value, System.nanoTime()));
boolean changed = setEnabledQuiet(value, System.nanoTime());
logEnabledChange(value, changed);
}

@Override
protected synchronized boolean setEnabled(boolean value, boolean overload) {
boolean changed = setEnabledQuiet(value, System.nanoTime());
logEnabledChange(value, changed);
return changed;
}

private static synchronized void logEnabledChange(boolean value, boolean success) {
Expand Down

0 comments on commit ef41d3c

Please sign in to comment.