mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 22:27:35 +00:00
profile: Add an option to wait for user input to disable profiling.
Often you want to enable and then disable profiling after a period of time. To make this slightly more ergonomic, add an option to wait for user input after enabling profiling, this will disable profiling on exit after the key press.
This commit is contained in:
parent
9de58a2d89
commit
cdd9faaf39
1 changed files with 14 additions and 4 deletions
|
@ -36,6 +36,7 @@ int main(int argc, char** argv)
|
|||
|
||||
const char* pid_argument = nullptr;
|
||||
const char* cmd_argument = nullptr;
|
||||
bool wait = false;
|
||||
bool enable = false;
|
||||
bool disable = false;
|
||||
bool all_processes = false;
|
||||
|
@ -44,6 +45,7 @@ int main(int argc, char** argv)
|
|||
args_parser.add_option(all_processes, "Profile all processes (super-user only)", nullptr, 'a');
|
||||
args_parser.add_option(enable, "Enable", nullptr, 'e');
|
||||
args_parser.add_option(disable, "Disable", nullptr, 'd');
|
||||
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.parse(argc, argv);
|
||||
|
@ -54,25 +56,33 @@ int main(int argc, char** argv)
|
|||
}
|
||||
|
||||
if (pid_argument || all_processes) {
|
||||
if (!(enable ^ disable)) {
|
||||
fprintf(stderr, "-p <PID> requires -e xor -d.\n");
|
||||
if (!(enable ^ disable ^ wait)) {
|
||||
fprintf(stderr, "-p <PID> requires -e xor -d xor -w.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
pid_t pid = all_processes ? -1 : atoi(pid_argument);
|
||||
|
||||
if (enable) {
|
||||
if (wait || enable) {
|
||||
if (profiling_enable(pid) < 0) {
|
||||
perror("profiling_enable");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
||||
if (!wait)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (wait) {
|
||||
outln("Profiling enabled, waiting for user input to disable...");
|
||||
(void)getchar();
|
||||
}
|
||||
|
||||
if (profiling_disable(pid) < 0) {
|
||||
perror("profiling_disable");
|
||||
return 1;
|
||||
}
|
||||
outln("Profiling disabled.");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue