Skip to content

Commit 50b7dd2

Browse files
yuyue730copybara-github
authored andcommitted
Inject OptionsProvider instead of individual option to BlazeRuntime#initProfiler()
PiperOrigin-RevId: 671774826 Change-Id: I1cb856fcad4499c4c861a4015d68822f60fbc05e
1 parent 11797b6 commit 50b7dd2

File tree

2 files changed

+28
-28
lines changed

2 files changed

+28
-28
lines changed

src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcher.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,7 @@ private BlazeCommandResult execExclusively(
387387
tracerEnabled,
388388
storedEventHandler,
389389
workspace,
390-
commonOptions,
391-
options.getOptions(BuildEventProtocolOptions.class),
390+
options,
392391
env,
393392
execStartTimeNanos,
394393
waitTimeInMs);

src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -318,20 +318,21 @@ ProfilerStartedEvent initProfiler(
318318
boolean tracerEnabled,
319319
ExtendedEventHandler eventHandler,
320320
BlazeWorkspace workspace,
321-
CommonCommandOptions options,
322-
BuildEventProtocolOptions bepOptions,
321+
OptionsProvider options,
323322
CommandEnvironment env,
324323
long execStartTimeNanos,
325324
long waitTimeInMs) {
325+
BuildEventProtocolOptions bepOptions = options.getOptions(BuildEventProtocolOptions.class);
326+
CommonCommandOptions commandOptions = options.getOptions(CommonCommandOptions.class);
326327
OutputStream out = null;
327-
boolean recordFullProfilerData = options.recordFullProfilerData;
328+
boolean recordFullProfilerData = commandOptions.recordFullProfilerData;
328329
ImmutableSet.Builder<ProfilerTask> profiledTasksBuilder = ImmutableSet.builder();
329330
Profiler.Format format = Format.JSON_TRACE_FILE_FORMAT;
330331
Path profilePath = null;
331332
InstrumentationOutput profile = null;
332333
try {
333334
if (tracerEnabled) {
334-
if (options.profilePath == null) {
335+
if (commandOptions.profilePath == null) {
335336
String profileName = "command.profile.gz";
336337
format = Format.JSON_TRACE_FILE_COMPRESSED_FORMAT;
337338
if (bepOptions != null && bepOptions.streamingLogFileUploads) {
@@ -354,10 +355,10 @@ ProfilerStartedEvent initProfiler(
354355
}
355356
} else {
356357
format =
357-
options.profilePath.toString().endsWith(".gz")
358+
commandOptions.profilePath.toString().endsWith(".gz")
358359
? Format.JSON_TRACE_FILE_COMPRESSED_FORMAT
359360
: Format.JSON_TRACE_FILE_FORMAT;
360-
profilePath = workspace.getWorkspace().getRelative(options.profilePath);
361+
profilePath = workspace.getWorkspace().getRelative(commandOptions.profilePath);
361362
profile =
362363
instrumentationOutputFactory
363364
.createLocalInstrumentationOutputBuilder()
@@ -379,11 +380,11 @@ ProfilerStartedEvent initProfiler(
379380
profiledTasksBuilder.add(profilerTask);
380381
}
381382
}
382-
profiledTasksBuilder.addAll(options.additionalProfileTasks);
383-
if (options.recordFullProfilerData) {
383+
profiledTasksBuilder.addAll(commandOptions.additionalProfileTasks);
384+
if (commandOptions.recordFullProfilerData) {
384385
profiledTasksBuilder.addAll(EnumSet.allOf(ProfilerTask.class));
385386
}
386-
} else if (options.alwaysProfileSlowOperations) {
387+
} else if (commandOptions.alwaysProfileSlowOperations) {
387388
recordFullProfilerData = false;
388389
out = null;
389390
for (ProfilerTask profilerTask : ProfilerTask.values()) {
@@ -394,7 +395,7 @@ ProfilerStartedEvent initProfiler(
394395
}
395396
ImmutableSet<ProfilerTask> profiledTasks = profiledTasksBuilder.build();
396397
if (!profiledTasks.isEmpty()) {
397-
if (options.slimProfile && options.includePrimaryOutput) {
398+
if (commandOptions.slimProfile && commandOptions.includePrimaryOutput) {
398399
eventHandler.handle(
399400
Event.warn(
400401
"Enabling both --slim_profile and"
@@ -415,45 +416,45 @@ ProfilerStartedEvent initProfiler(
415416
recordFullProfilerData,
416417
clock,
417418
execStartTimeNanos,
418-
options.slimProfile,
419-
options.includePrimaryOutput,
420-
options.profileIncludeTargetLabel,
421-
options.alwaysProfileSlowOperations,
419+
commandOptions.slimProfile,
420+
commandOptions.includePrimaryOutput,
421+
commandOptions.profileIncludeTargetLabel,
422+
commandOptions.alwaysProfileSlowOperations,
422423
new CollectLocalResourceUsage(
423424
bugReporter,
424425
workerProcessMetricsCollector,
425426
env.getLocalResourceManager(),
426-
options.collectSkyframeCounts
427+
commandOptions.collectSkyframeCounts
427428
? env.getSkyframeExecutor().getEvaluator().getInMemoryGraph()
428429
: null,
429-
options.collectWorkerDataInProfiler,
430-
options.collectLoadAverageInProfiler,
431-
options.collectSystemNetworkUsage,
432-
options.collectResourceEstimation,
433-
options.collectPressureStallIndicators,
434-
options.collectSkyframeCounts));
430+
commandOptions.collectWorkerDataInProfiler,
431+
commandOptions.collectLoadAverageInProfiler,
432+
commandOptions.collectSystemNetworkUsage,
433+
commandOptions.collectResourceEstimation,
434+
commandOptions.collectPressureStallIndicators,
435+
commandOptions.collectSkyframeCounts));
435436
// Instead of logEvent() we're calling the low level function to pass the timings we took in
436437
// the launcher. We're setting the INIT phase marker so that it follows immediately the
437438
// LAUNCH phase.
438-
long startupTimeNanos = options.startupTime * 1000000L;
439+
long startupTimeNanos = commandOptions.startupTime * 1000000L;
439440
long waitTimeNanos = waitTimeInMs * 1000000L;
440441
long clientStartTimeNanos = execStartTimeNanos - startupTimeNanos - waitTimeNanos;
441442
profiler.logSimpleTaskDuration(
442443
clientStartTimeNanos,
443444
Duration.ofNanos(startupTimeNanos),
444445
ProfilerTask.PHASE,
445446
ProfilePhase.LAUNCH.description);
446-
if (options.extractDataTime > 0) {
447+
if (commandOptions.extractDataTime > 0) {
447448
profiler.logSimpleTaskDuration(
448449
clientStartTimeNanos,
449-
Duration.ofMillis(options.extractDataTime),
450+
Duration.ofMillis(commandOptions.extractDataTime),
450451
ProfilerTask.PHASE,
451452
"Extracting Bazel binary");
452453
}
453-
if (options.waitTime > 0) {
454+
if (commandOptions.waitTime > 0) {
454455
profiler.logSimpleTaskDuration(
455456
clientStartTimeNanos,
456-
Duration.ofMillis(options.waitTime),
457+
Duration.ofMillis(commandOptions.waitTime),
457458
ProfilerTask.PHASE,
458459
"Blocking on busy Bazel server (in client)");
459460
}

0 commit comments

Comments
 (0)