mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:18:11 +00:00
profile: Pass the command to run using positional arguments
This changes this: ```sh profile -c "python3 -m test test_dict" ``` to this: ```sh profile -- python3 -m test test_dict ``` This should be less confusing, hopefully!
This commit is contained in:
parent
ed196fc265
commit
35126e81c4
1 changed files with 5 additions and 6 deletions
|
@ -16,7 +16,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
Core::ArgsParser args_parser;
|
Core::ArgsParser args_parser;
|
||||||
|
|
||||||
StringView pid_argument {};
|
StringView pid_argument {};
|
||||||
StringView cmd_argument {};
|
Vector<StringView> command;
|
||||||
bool wait = false;
|
bool wait = false;
|
||||||
bool free = false;
|
bool free = false;
|
||||||
bool enable = false;
|
bool enable = false;
|
||||||
|
@ -33,7 +33,6 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
args_parser.add_option(disable, "Disable", nullptr, 'd');
|
args_parser.add_option(disable, "Disable", nullptr, 'd');
|
||||||
args_parser.add_option(free, "Free the profiling buffer for the associated process(es).", nullptr, 'f');
|
args_parser.add_option(free, "Free the profiling buffer for the associated process(es).", nullptr, 'f');
|
||||||
args_parser.add_option(wait, "Enable profiling and wait for user input to disable.", nullptr, 'w');
|
args_parser.add_option(wait, "Enable profiling and wait for user input to disable.", nullptr, 'w');
|
||||||
args_parser.add_option(cmd_argument, "Command", nullptr, 'c', "command");
|
|
||||||
args_parser.add_option(Core::ArgsParser::Option {
|
args_parser.add_option(Core::ArgsParser::Option {
|
||||||
Core::ArgsParser::OptionArgumentMode::Required,
|
Core::ArgsParser::OptionArgumentMode::Required,
|
||||||
"Enable tracking specific event type", nullptr, 't', "event_type",
|
"Enable tracking specific event type", nullptr, 't', "event_type",
|
||||||
|
@ -59,6 +58,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} });
|
} });
|
||||||
|
args_parser.add_positional_argument(command, "Command to profile", "command", Core::ArgsParser::Required::No);
|
||||||
|
args_parser.set_stop_on_first_non_option(true);
|
||||||
|
|
||||||
auto print_types = [] {
|
auto print_types = [] {
|
||||||
outln();
|
outln();
|
||||||
|
@ -70,7 +71,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pid_argument.is_empty() && cmd_argument.is_empty() && !all_processes) {
|
if (pid_argument.is_empty() && command.is_empty() && !all_processes) {
|
||||||
args_parser.print_usage(stdout, arguments.argv[0]);
|
args_parser.print_usage(stdout, arguments.argv[0]);
|
||||||
print_types();
|
print_types();
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -109,11 +110,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto cmd_parts = StringView(cmd_argument).split_view(' ');
|
|
||||||
|
|
||||||
dbgln("Enabling profiling for PID {}", getpid());
|
dbgln("Enabling profiling for PID {}", getpid());
|
||||||
TRY(Core::System::profiling_enable(getpid(), event_mask));
|
TRY(Core::System::profiling_enable(getpid(), event_mask));
|
||||||
TRY(Core::System::exec(cmd_parts[0], cmd_parts, Core::System::SearchInPath::Yes));
|
TRY(Core::System::exec(command[0], command, Core::System::SearchInPath::Yes));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue