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

Add configuration hash to trace profile #23236

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions src/main/java/com/google/devtools/build/lib/profiler/Profiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.google.devtools.build.lib.profiler.StatRecorder.VfsHeuristics;
import com.google.gson.stream.JsonWriter;
import com.sun.management.OperatingSystemMXBean;

import java.io.IOException;
import java.io.OutputStream;
import java.lang.management.ManagementFactory;
Expand Down Expand Up @@ -197,7 +198,7 @@ public void writeTraceData(JsonWriter jsonWriter, long profileStartTimeNanos)
// Primary outputs are non-mergeable, thus incompatible with slim profiles.
jsonWriter.name("out").value(actionTaskData.primaryOutputPath);
}
if (actionTaskData.targetLabel != null || actionTaskData.mnemonic != null) {
if (actionTaskData.targetLabel != null || actionTaskData.mnemonic != null || actionTaskData.configuration != null) {
jsonWriter.name("args");
jsonWriter.beginObject();
if (actionTaskData.targetLabel != null) {
Expand All @@ -206,6 +207,9 @@ public void writeTraceData(JsonWriter jsonWriter, long profileStartTimeNanos)
if (actionTaskData.mnemonic != null) {
jsonWriter.name("mnemonic").value(actionTaskData.mnemonic);
}
if (actionTaskData.configuration != null) {
jsonWriter.name("configuration").value(actionTaskData.configuration);
}
jsonWriter.endObject();
}
}
Expand Down Expand Up @@ -234,6 +238,7 @@ static final class ActionTaskData extends TaskData {
@Nullable final String primaryOutputPath;
@Nullable final String targetLabel;
@Nullable final String mnemonic;
@Nullable final String configuration;

ActionTaskData(
long threadId,
Expand All @@ -243,11 +248,13 @@ static final class ActionTaskData extends TaskData {
@Nullable String mnemonic,
String description,
@Nullable String primaryOutputPath,
@Nullable String targetLabel) {
@Nullable String targetLabel,
@Nullable String configuration) {
super(threadId, startTimeNanos, durationNanos, eventType, description);
this.primaryOutputPath = primaryOutputPath;
this.targetLabel = targetLabel;
this.mnemonic = mnemonic;
this.configuration = configuration;
}
}

Expand Down Expand Up @@ -337,6 +344,7 @@ ImmutableList<SlowTask> getSlowestTasks() {
private boolean collectTaskHistograms;
private boolean includePrimaryOutput;
private boolean includeTargetLabel;
private boolean includeConfiguration;

private Profiler() {
actionCountTimeSeriesRef = new AtomicReference<>();
Expand Down Expand Up @@ -444,6 +452,7 @@ public synchronized void start(
boolean slimProfile,
boolean includePrimaryOutput,
boolean includeTargetLabel,
boolean includeConfiguration,
boolean collectTaskHistograms,
LocalResourceCollector localResourceCollector)
throws IOException {
Expand All @@ -463,6 +472,7 @@ public synchronized void start(
this.collectTaskHistograms = collectTaskHistograms;
this.includePrimaryOutput = includePrimaryOutput;
this.includeTargetLabel = includeTargetLabel;
this.includeConfiguration = includeConfiguration;
this.recordAllDurations = recordAllDurations;

JsonTraceFileWriter writer = null;
Expand Down Expand Up @@ -811,7 +821,8 @@ public SilentCloseable profileAction(
String mnemonic,
String description,
String primaryOutput,
String targetLabel) {
String targetLabel,
String configuration) {
checkNotNull(description);
if (isActive() && isProfiling(type)) {
final long startTimeNanos = clock.nanoTime();
Expand All @@ -825,7 +836,8 @@ public SilentCloseable profileAction(
description,
mnemonic,
includePrimaryOutput ? primaryOutput : null,
includeTargetLabel ? targetLabel : null);
includeTargetLabel ? targetLabel : null,
includeConfiguration ? configuration : null);
} finally {
releaseLane(lane);
}
Expand All @@ -835,11 +847,6 @@ public SilentCloseable profileAction(
}
}

public SilentCloseable profileAction(
ProfilerTask type, String description, String primaryOutput, String targetLabel) {
return profileAction(type, /* mnemonic= */ null, description, primaryOutput, targetLabel);
}

private static final SilentCloseable NOP = () -> {};

private boolean countAction(ProfilerTask type) {
Expand Down Expand Up @@ -874,7 +881,8 @@ private void completeAction(
String description,
String mnemonic,
@Nullable String primaryOutput,
@Nullable String targetLabel) {
@Nullable String targetLabel,
@Nullable String configuration) {
if (isActive()) {
long endTimeNanos = clock.nanoTime();
long duration = endTimeNanos - startTimeNanos;
Expand All @@ -889,7 +897,8 @@ private void completeAction(
mnemonic,
description,
primaryOutput,
targetLabel));
targetLabel,
configuration));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public static TraceEvent create(
@Nullable ImmutableMap<String, Object> args,
@Nullable String primaryOutputPath,
@Nullable String targetLabel,
@Nullable String mnemonic) {
@Nullable String mnemonic,
@Nullable String configuration) {
return new AutoValue_TraceEvent(
category,
name,
Expand All @@ -56,7 +57,8 @@ public static TraceEvent create(
args,
primaryOutputPath,
targetLabel,
mnemonic);
mnemonic,
configuration);
}

@Nullable
Expand Down Expand Up @@ -90,6 +92,9 @@ public static TraceEvent create(
@Nullable
public abstract String mnemonic();

@Nullable
public abstract String configuration();

private static TraceEvent createFromJsonReader(JsonReader reader) throws IOException {
String category = null;
String name = null;
Expand All @@ -101,6 +106,7 @@ private static TraceEvent createFromJsonReader(JsonReader reader) throws IOExcep
String targetLabel = null;
String mnemonic = null;
String type = null;
String configuration = null;
ImmutableMap<String, Object> args = null;

reader.beginObject();
Expand All @@ -122,6 +128,8 @@ private static TraceEvent createFromJsonReader(JsonReader reader) throws IOExcep
targetLabel = target instanceof String ? (String) target : null;
Object mnemonicValue = args.get("mnemonic");
mnemonic = mnemonicValue instanceof String ? (String) mnemonicValue : null;
Object configurationValue = args.get("configuration");
configuration = configurationValue instanceof String ? (String) configurationValue : null;
}
default -> reader.skipValue();
}
Expand All @@ -138,7 +146,8 @@ private static TraceEvent createFromJsonReader(JsonReader reader) throws IOExcep
args,
primaryOutputPath,
targetLabel,
mnemonic);
mnemonic,
configuration);
}

private static ImmutableMap<String, Object> parseMap(JsonReader reader) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ ProfilerStartedEvent initProfiler(
commandOptions.slimProfile,
commandOptions.includePrimaryOutput,
commandOptions.profileIncludeTargetLabel,
commandOptions.profileIncludeTargetConfiguration,
commandOptions.alwaysProfileSlowOperations,
new CollectLocalResourceUsage(
bugReporter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,14 @@ public String getTypeDescription() {
help = "Includes target label in action events' JSON profile data.")
public boolean profileIncludeTargetLabel;

@Option(
name = "experimental_profile_include_target_configuration",
defaultValue = "false",
documentationCategory = OptionDocumentationCategory.LOGGING,
effectTags = {OptionEffectTag.BAZEL_MONITORING},
help = "Includes target configuration hash in action events' JSON profile data.")
public boolean profileIncludeTargetConfiguration;

@Option(
name = "profile",
defaultValue = "null",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1020,7 +1020,8 @@ public ActionStepOrResult run(Environment env)
action.getMnemonic(),
action.describe(),
action.getPrimaryOutput().getExecPathString(),
getOwnerLabelAsString(action))) {
getOwnerLabelAsString(action),
getOwnerConfigurationAsString(action))) {
String message = action.getProgressMessage();
if (message != null) {
reporter.startTask(null, prependExecPhaseStats(message));
Expand Down Expand Up @@ -1089,6 +1090,14 @@ private String getOwnerLabelAsString(Action action) {
return ownerLabel.getCanonicalForm();
}

private String getOwnerConfigurationAsString(Action action) {
ActionOwner owner = action.getOwner();
if (owner == null) {
return "";
}
return owner.getConfigurationChecksum();
}

private void notifyActionCompletion(
ExtendedEventHandler eventHandler, boolean postActionCompletionEvent) {
if (statusReporter != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ private void beforeCommand() throws Exception {
/* slimProfile= */ false,
/* includePrimaryOutput= */ false,
/* includeTargetLabel= */ false,
/* includeConfiguration= */ false,
/* collectTaskHistograms= */ true,
new CollectLocalResourceUsage(
runtime.getBugReporter(),
Expand Down
Loading
Loading