Skip to content

Commit

Permalink
Move profile spans into logEntry/logEntryWithoutId.
Browse files Browse the repository at this point in the history
A pair of spans is used to make contention apparent in profiles. This makes them more obviously correct.

PiperOrigin-RevId: 680961338
Change-Id: I4501deffb5b47fae47fda560786ac0580248b8b7
  • Loading branch information
tjgq authored and copybara-github committed Oct 1, 2024
1 parent 6fedd40 commit 0f14eff
Showing 1 changed file with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,7 @@ public void logSpawn(
builder.setTimeoutMillis(timeout.toMillis());
builder.setMetrics(getSpawnMetricsProto(result));

try (SilentCloseable c1 = Profiler.instance().profile("logEntry")) {
logEntryWithoutId(() -> ExecLogEntry.newBuilder().setSpawn(builder));
}
logEntryWithoutId(() -> ExecLogEntry.newBuilder().setSpawn(builder));
}
}

Expand All @@ -288,9 +286,7 @@ public void logSymlinkAction(AbstractAction action) throws IOException, Interrup
}
builder.setMnemonic(action.getMnemonic());

try (SilentCloseable c1 = Profiler.instance().profile("logEntry")) {
logEntryWithoutId(() -> ExecLogEntry.newBuilder().setSymlinkAction(builder));
}
logEntryWithoutId(() -> ExecLogEntry.newBuilder().setSymlinkAction(builder));
}
}

Expand Down Expand Up @@ -651,9 +647,18 @@ private int logUnresolvedSymlink(ActionInput input, Path path)
*
* @param supplier called to compute the entry; may cause other entries to be logged
*/
private synchronized void logEntryWithoutId(ExecLogEntrySupplier supplier)
private void logEntryWithoutId(ExecLogEntrySupplier supplier)
throws IOException, InterruptedException {
outputStream.write(supplier.get().build());
try (SilentCloseable c = Profiler.instance().profile("logEntryWithoutId")) {
logEntryWithoutIdSynchronized(supplier);
}
}

private synchronized void logEntryWithoutIdSynchronized(ExecLogEntrySupplier supplier)
throws IOException, InterruptedException {
try (SilentCloseable c = Profiler.instance().profile("logEntryWithoutId/synchronized")) {
outputStream.write(supplier.get().build());
}
}

/**
Expand All @@ -667,7 +672,14 @@ private synchronized void logEntryWithoutId(ExecLogEntrySupplier supplier)
* @return the entry ID
*/
@CheckReturnValue
private synchronized int logEntry(@Nullable Object key, ExecLogEntrySupplier supplier)
private int logEntry(@Nullable Object key, ExecLogEntrySupplier supplier)
throws IOException, InterruptedException {
try (SilentCloseable c = Profiler.instance().profile("logEntry")) {
return logEntrySynchronized(key, supplier);
}
}

private synchronized int logEntrySynchronized(@Nullable Object key, ExecLogEntrySupplier supplier)
throws IOException, InterruptedException {
try (SilentCloseable c = Profiler.instance().profile("logEntry/synchronized")) {
if (key == null) {
Expand Down

0 comments on commit 0f14eff

Please sign in to comment.