Skip to content

Commit

Permalink
Inject OptionsProvider instead of individual option to `BlazeRuntim…
Browse files Browse the repository at this point in the history
…e#initProfiler()`

PiperOrigin-RevId: 671774826
Change-Id: I1cb856fcad4499c4c861a4015d68822f60fbc05e
  • Loading branch information
yuyue730 authored and copybara-github committed Sep 6, 2024
1 parent 11797b6 commit 50b7dd2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,7 @@ private BlazeCommandResult execExclusively(
tracerEnabled,
storedEventHandler,
workspace,
commonOptions,
options.getOptions(BuildEventProtocolOptions.class),
options,
env,
execStartTimeNanos,
waitTimeInMs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,20 +318,21 @@ ProfilerStartedEvent initProfiler(
boolean tracerEnabled,
ExtendedEventHandler eventHandler,
BlazeWorkspace workspace,
CommonCommandOptions options,
BuildEventProtocolOptions bepOptions,
OptionsProvider options,
CommandEnvironment env,
long execStartTimeNanos,
long waitTimeInMs) {
BuildEventProtocolOptions bepOptions = options.getOptions(BuildEventProtocolOptions.class);
CommonCommandOptions commandOptions = options.getOptions(CommonCommandOptions.class);
OutputStream out = null;
boolean recordFullProfilerData = options.recordFullProfilerData;
boolean recordFullProfilerData = commandOptions.recordFullProfilerData;
ImmutableSet.Builder<ProfilerTask> profiledTasksBuilder = ImmutableSet.builder();
Profiler.Format format = Format.JSON_TRACE_FILE_FORMAT;
Path profilePath = null;
InstrumentationOutput profile = null;
try {
if (tracerEnabled) {
if (options.profilePath == null) {
if (commandOptions.profilePath == null) {
String profileName = "command.profile.gz";
format = Format.JSON_TRACE_FILE_COMPRESSED_FORMAT;
if (bepOptions != null && bepOptions.streamingLogFileUploads) {
Expand All @@ -354,10 +355,10 @@ ProfilerStartedEvent initProfiler(
}
} else {
format =
options.profilePath.toString().endsWith(".gz")
commandOptions.profilePath.toString().endsWith(".gz")
? Format.JSON_TRACE_FILE_COMPRESSED_FORMAT
: Format.JSON_TRACE_FILE_FORMAT;
profilePath = workspace.getWorkspace().getRelative(options.profilePath);
profilePath = workspace.getWorkspace().getRelative(commandOptions.profilePath);
profile =
instrumentationOutputFactory
.createLocalInstrumentationOutputBuilder()
Expand All @@ -379,11 +380,11 @@ ProfilerStartedEvent initProfiler(
profiledTasksBuilder.add(profilerTask);
}
}
profiledTasksBuilder.addAll(options.additionalProfileTasks);
if (options.recordFullProfilerData) {
profiledTasksBuilder.addAll(commandOptions.additionalProfileTasks);
if (commandOptions.recordFullProfilerData) {
profiledTasksBuilder.addAll(EnumSet.allOf(ProfilerTask.class));
}
} else if (options.alwaysProfileSlowOperations) {
} else if (commandOptions.alwaysProfileSlowOperations) {
recordFullProfilerData = false;
out = null;
for (ProfilerTask profilerTask : ProfilerTask.values()) {
Expand All @@ -394,7 +395,7 @@ ProfilerStartedEvent initProfiler(
}
ImmutableSet<ProfilerTask> profiledTasks = profiledTasksBuilder.build();
if (!profiledTasks.isEmpty()) {
if (options.slimProfile && options.includePrimaryOutput) {
if (commandOptions.slimProfile && commandOptions.includePrimaryOutput) {
eventHandler.handle(
Event.warn(
"Enabling both --slim_profile and"
Expand All @@ -415,45 +416,45 @@ ProfilerStartedEvent initProfiler(
recordFullProfilerData,
clock,
execStartTimeNanos,
options.slimProfile,
options.includePrimaryOutput,
options.profileIncludeTargetLabel,
options.alwaysProfileSlowOperations,
commandOptions.slimProfile,
commandOptions.includePrimaryOutput,
commandOptions.profileIncludeTargetLabel,
commandOptions.alwaysProfileSlowOperations,
new CollectLocalResourceUsage(
bugReporter,
workerProcessMetricsCollector,
env.getLocalResourceManager(),
options.collectSkyframeCounts
commandOptions.collectSkyframeCounts
? env.getSkyframeExecutor().getEvaluator().getInMemoryGraph()
: null,
options.collectWorkerDataInProfiler,
options.collectLoadAverageInProfiler,
options.collectSystemNetworkUsage,
options.collectResourceEstimation,
options.collectPressureStallIndicators,
options.collectSkyframeCounts));
commandOptions.collectWorkerDataInProfiler,
commandOptions.collectLoadAverageInProfiler,
commandOptions.collectSystemNetworkUsage,
commandOptions.collectResourceEstimation,
commandOptions.collectPressureStallIndicators,
commandOptions.collectSkyframeCounts));
// Instead of logEvent() we're calling the low level function to pass the timings we took in
// the launcher. We're setting the INIT phase marker so that it follows immediately the
// LAUNCH phase.
long startupTimeNanos = options.startupTime * 1000000L;
long startupTimeNanos = commandOptions.startupTime * 1000000L;
long waitTimeNanos = waitTimeInMs * 1000000L;
long clientStartTimeNanos = execStartTimeNanos - startupTimeNanos - waitTimeNanos;
profiler.logSimpleTaskDuration(
clientStartTimeNanos,
Duration.ofNanos(startupTimeNanos),
ProfilerTask.PHASE,
ProfilePhase.LAUNCH.description);
if (options.extractDataTime > 0) {
if (commandOptions.extractDataTime > 0) {
profiler.logSimpleTaskDuration(
clientStartTimeNanos,
Duration.ofMillis(options.extractDataTime),
Duration.ofMillis(commandOptions.extractDataTime),
ProfilerTask.PHASE,
"Extracting Bazel binary");
}
if (options.waitTime > 0) {
if (commandOptions.waitTime > 0) {
profiler.logSimpleTaskDuration(
clientStartTimeNanos,
Duration.ofMillis(options.waitTime),
Duration.ofMillis(commandOptions.waitTime),
ProfilerTask.PHASE,
"Blocking on busy Bazel server (in client)");
}
Expand Down

0 comments on commit 50b7dd2

Please sign in to comment.