Skip to content

Commit 0ead16d

Browse files
derekxu16Commit Queue
authored andcommitted
[VM] Make it so that --profile-microtasks is processed by the code in both runtime/bin/main_options.h and runtime/vm/flags.h
TEST=pkg/vm_service/test/timeline_events_for_completed_microtasks_test Change-Id: Ia544cabc7bfe6e322955d16d3078cab461b803ae Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/425100 Reviewed-by: Ben Konyi <[email protected]>
1 parent 018c534 commit 0ead16d

File tree

5 files changed

+40
-0
lines changed

5 files changed

+40
-0
lines changed

pkg/dartdev/lib/src/commands/run.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,14 @@ class RunCommand extends DartdevCommand {
178178
'Defaults to ring.',
179179
valueHelp: 'recorder',
180180
hide: !verbose,
181+
)
182+
..addFlag(
183+
'profile-microtasks',
184+
hide: !verbose,
185+
negatable: false,
186+
help: 'Record information about each microtask. Information about '
187+
'completed microtasks will be written to the "Microtask" '
188+
'timeline stream.',
181189
);
182190
} else {
183191
argParser.addOption('timeline-recorder',

runtime/bin/main_options.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,24 @@ bool Options::ProcessObserveOption(const char* arg,
471471
#endif // !defined(PRODUCT)
472472
}
473473

474+
bool Options::ProcessProfileMicrotasksOption(const char* arg,
475+
CommandLineOptions* vm_options) {
476+
#if !defined(PRODUCT)
477+
constexpr const char* kProfileMicrotasksFlagAsCstr = "--profile-microtasks";
478+
constexpr const char* kAlternativeProfileMicrotasksFlagAsCstr =
479+
"--profile_microtasks";
480+
if (strncmp(kProfileMicrotasksFlagAsCstr, arg,
481+
strlen(kProfileMicrotasksFlagAsCstr)) == 0 ||
482+
strncmp(kAlternativeProfileMicrotasksFlagAsCstr, arg,
483+
strlen(kAlternativeProfileMicrotasksFlagAsCstr)) == 0) {
484+
profile_microtasks_ = true;
485+
vm_options->AddArgument(kProfileMicrotasksFlagAsCstr);
486+
return true;
487+
}
488+
#endif // !defined(PRODUCT)
489+
return false;
490+
}
491+
474492
// Explicitly handle VM flags that can be parsed by DartDev's run command.
475493
bool Options::ProcessVMDebuggingOptions(const char* arg,
476494
CommandLineOptions* vm_options) {

runtime/bin/main_options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ namespace bin {
8585
V(ProcessEnvironmentOption) \
8686
V(ProcessEnableVmServiceOption) \
8787
V(ProcessObserveOption) \
88+
V(ProcessProfileMicrotasksOption) \
8889
V(ProcessVMDebuggingOptions)
8990

9091
// This enum must match the strings in kSnapshotKindNames in main_options.cc.

runtime/lib/async.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515

1616
namespace dart {
1717

18+
// This flag is defined in "vm/microtask_mirror_queues.cc".
19+
DECLARE_FLAG(bool, profile_microtasks);
20+
1821
DEFINE_NATIVE_ENTRY(AsyncStarMoveNext_debuggerStepCheck, 0, 1) {
1922
#if !defined(PRODUCT)
2023
GET_NON_NULL_NATIVE_ARGUMENT(Closure, generator, arguments->NativeArgAt(0));
@@ -65,6 +68,7 @@ DEFINE_NATIVE_ENTRY(MicrotaskMirrorQueue_onScheduleAsyncCallback, 0, 0) {
6568
// this function can only ever be called when the `--profile-microtasks` CLI
6669
// flag is set in non-PRODUCT modes.
6770
#if !defined(PRODUCT)
71+
ASSERT(FLAG_profile_microtasks);
6872
const StackTrace& stack_trace = GetCurrentStackTrace(
6973
// We pass a `skip_frames` argument of 1 to skip the
7074
// `_MicrotaskMirrorQueue._onScheduleAsyncCallback` frame.
@@ -84,6 +88,7 @@ DEFINE_NATIVE_ENTRY(MicrotaskMirrorQueue_onSchedulePriorityAsyncCallback,
8488
// this function can only ever be called when the `--profile-microtasks` CLI
8589
// flag is set in non-PRODUCT modes.
8690
#if !defined(PRODUCT)
91+
ASSERT(FLAG_profile_microtasks);
8792
MicrotaskMirrorQueues::GetQueue(static_cast<int64_t>(isolate->main_port()))
8893
->OnSchedulePriorityAsyncCallback();
8994
return Object::null();
@@ -97,6 +102,7 @@ DEFINE_NATIVE_ENTRY(MicrotaskMirrorQueue_onAsyncCallbackComplete, 0, 2) {
97102
// this function can only ever be called when the `--profile-microtasks` CLI
98103
// flag is set in non-PRODUCT modes.
99104
#if !defined(PRODUCT)
105+
ASSERT(FLAG_profile_microtasks);
100106
GET_NON_NULL_NATIVE_ARGUMENT(Integer, start_time, arguments->NativeArgAt(0));
101107
GET_NON_NULL_NATIVE_ARGUMENT(Integer, end_time, arguments->NativeArgAt(1));
102108
MicrotaskMirrorQueues::GetQueue(static_cast<int64_t>(isolate->main_port()))

runtime/vm/microtask_mirror_queues.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@
1515

1616
namespace dart {
1717

18+
DEFINE_FLAG(
19+
bool,
20+
profile_microtasks,
21+
false,
22+
"Record information about each microtask. Information about completed "
23+
"microtasks will be written to the \"Microtask\" timeline stream.");
24+
1825
MicrotaskMirrorQueue* MicrotaskMirrorQueues::GetQueue(int64_t isolate_id) {
1926
void* key = reinterpret_cast<void*>(isolate_id);
2027
const intptr_t hash = Utils::WordHash(isolate_id);

0 commit comments

Comments
 (0)