Guard Profiler#logSimpleTask against negative start times. That indicates that the Profiler was not active, and can happen if an asynchronous operation spans a Blaze command.
@@ -721,6 +721,10 @@ public final class Profiler {
}
}
+ private boolean shouldProfile(long startTime, ProfilerTask type) {
+ return isActive() && startTime > 0 && isProfiling(type);
+ }
+
/**
* Used externally to submit simple task (one that does not have any subtasks). Depending on the
* minDuration attribute of the task type, task may be just aggregated into the parent task and
@@ -731,7 +735,7 @@ public final class Profiler {
* @param description task description. May be stored until the end of the build.
*/
public void logSimpleTask(long startTime, ProfilerTask type, String description) {
- if (isActive() && isProfiling(type)) {
+ if (shouldProfile(startTime, type)) {
logTask(startTime, clock.nanoTime() - startTime, type, description);
}
}
@@ -750,7 +754,7 @@ public final class Profiler {
*/
public void logSimpleTask(
long startTimeNanos, long stopTimeNanos, ProfilerTask type, String description) {
- if (isActive() && isProfiling(type)) {
+ if (shouldProfile(startTimeNanos, type)) {
logTask(startTimeNanos, stopTimeNanos - startTimeNanos, type, description);
}
}
@@ -767,7 +771,7 @@ public final class Profiler {
*/
public void logSimpleTaskDuration(
long startTimeNanos, Duration duration, ProfilerTask type, String description) {
- if (isActive() && isProfiling(type)) {
+ if (shouldProfile(startTimeNanos, type)) {
logTask(startTimeNanos, duration.toNanos(), type, description);
}
}
