From ec3596545abd68dc94324ce6f30ba05051c595d5 Mon Sep 17 00:00:00 2001 From: Brian Gianforcaro Date: Sun, 18 Apr 2021 21:25:43 -0700 Subject: [PATCH] profile: Expose the ability to free the kernel profiling buffer. --- Userland/Utilities/profile.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Userland/Utilities/profile.cpp b/Userland/Utilities/profile.cpp index 8e8168b045..cb9480a116 100644 --- a/Userland/Utilities/profile.cpp +++ b/Userland/Utilities/profile.cpp @@ -37,6 +37,7 @@ int main(int argc, char** argv) const char* pid_argument = nullptr; const char* cmd_argument = nullptr; bool wait = false; + bool free = false; bool enable = false; bool disable = false; bool all_processes = false; @@ -45,6 +46,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(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(cmd_argument, "Command", nullptr, 'c', "command"); @@ -56,8 +58,8 @@ int main(int argc, char** argv) } if (pid_argument || all_processes) { - if (!(enable ^ disable ^ wait)) { - fprintf(stderr, "-p requires -e xor -d xor -w.\n"); + if (!(enable ^ disable ^ wait ^ free)) { + fprintf(stderr, "-p requires -e xor -d xor -w xor -f.\n"); return 1; } @@ -78,11 +80,18 @@ int main(int argc, char** argv) (void)getchar(); } - if (profiling_disable(pid) < 0) { + if (wait || disable) { + if (profiling_disable(pid) < 0) { + perror("profiling_disable"); + return 1; + } + outln("Profiling disabled."); + } + + if (free && profiling_free_buffer(pid) < 0) { perror("profiling_disable"); return 1; } - outln("Profiling disabled."); return 0; }