Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api: record if PerfMark.setEnabled succeeded #181

Merged
merged 1 commit into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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