diff --git a/Userland/Utilities/profile.cpp b/Userland/Utilities/profile.cpp index 41ea8b65e5..8e8168b045 100644 --- a/Userland/Utilities/profile.cpp +++ b/Userland/Utilities/profile.cpp @@ -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 requires -e xor -d.\n"); + if (!(enable ^ disable ^ wait)) { + fprintf(stderr, "-p 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; }