diff options
author | Googler <noreply@google.com> | 2018-08-13 07:55:35 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-08-13 07:57:14 -0700 |
commit | 90729a57a865c08fe561be6a49734582becfbb53 (patch) | |
tree | 76b5ac5d48216dbeafa34b9ab6f0b0a27aa3ea54 /src/main/java/com/google/devtools/build/lib/buildtool/ExecutionProgressReceiver.java | |
parent | ea168de2b7929277366ba27028fc4c8af2fa9235 (diff) |
Fix lock contention in Reporter.startTask/.finishTask by:
- Using a thread-safe container to store handlers.
- Using a ThreadLocal NumberFormat to produce readable action counts.
NumberFormat (or rather the default implementation DecimalFormat) use
internal state and locking.
- Adding a lock-free fast path for START and FINISH events in
ExperimentalEventHandler.
RELNOTES: None.
PiperOrigin-RevId: 208479896
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/buildtool/ExecutionProgressReceiver.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/buildtool/ExecutionProgressReceiver.java | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/buildtool/ExecutionProgressReceiver.java b/src/main/java/com/google/devtools/build/lib/buildtool/ExecutionProgressReceiver.java index 2b614b0630..484298c4c7 100644 --- a/src/main/java/com/google/devtools/build/lib/buildtool/ExecutionProgressReceiver.java +++ b/src/main/java/com/google/devtools/build/lib/buildtool/ExecutionProgressReceiver.java @@ -46,7 +46,13 @@ public final class ExecutionProgressReceiver extends EvaluationProgressReceiver.NullEvaluationProgressReceiver implements SkyframeActionExecutor.ProgressSupplier, SkyframeActionExecutor.ActionCompletedReceiver { - private static final NumberFormat PROGRESS_MESSAGE_NUMBER_FORMATTER; + private static final ThreadLocal<NumberFormat> PROGRESS_MESSAGE_NUMBER_FORMATTER = + ThreadLocal.withInitial( + () -> { + NumberFormat numberFormat = NumberFormat.getIntegerInstance(Locale.ENGLISH); + numberFormat.setGroupingUsed(true); + return numberFormat; + }); // Must be thread-safe! private final Set<ConfiguredTargetKey> builtTargets; @@ -59,11 +65,6 @@ public final class ExecutionProgressReceiver /** Number of exclusive tests. To be accounted for in progress messages. */ private final int exclusiveTestsCount; - static { - PROGRESS_MESSAGE_NUMBER_FORMATTER = NumberFormat.getIntegerInstance(Locale.ENGLISH); - PROGRESS_MESSAGE_NUMBER_FORMATTER.setGroupingUsed(true); - } - /** * {@code builtTargets} is accessed through a synchronized set, and so no other access to it is * permitted while this receiver is active. @@ -153,8 +154,10 @@ public final class ExecutionProgressReceiver public String getProgressString() { return String.format( "[%s / %s]", - PROGRESS_MESSAGE_NUMBER_FORMATTER.format(completedActions.size()), - PROGRESS_MESSAGE_NUMBER_FORMATTER.format(exclusiveTestsCount + enqueuedActions.size())); + PROGRESS_MESSAGE_NUMBER_FORMATTER.get().format(completedActions.size()), + PROGRESS_MESSAGE_NUMBER_FORMATTER + .get() + .format(exclusiveTestsCount + enqueuedActions.size())); } ActionExecutionInactivityWatchdog.InactivityMonitor createInactivityMonitor( |