From 50ea0c350070a6eaddbb039fc2e79f9592fd7023 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Thu, 4 Mar 2021 23:07:38 +0100 Subject: [PATCH] Profiler: Get perfcore file from ArgsParser Fixes #5641. --- Userland/DevTools/Profiler/main.cpp | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/Userland/DevTools/Profiler/main.cpp b/Userland/DevTools/Profiler/main.cpp index f6c2fcd420..ea32b54be2 100644 --- a/Userland/DevTools/Profiler/main.cpp +++ b/Userland/DevTools/Profiler/main.cpp @@ -37,7 +37,6 @@ #include #include #include -#include #include #include #include @@ -50,31 +49,37 @@ #include #include #include -#include #include static bool generate_profile(pid_t& pid); int main(int argc, char** argv) { - Core::ArgsParser args_parser; int pid = 0; + const char* perfcore_file_arg = nullptr; + Core::ArgsParser args_parser; args_parser.add_option(pid, "PID to profile", "pid", 'p', "PID"); - args_parser.parse(argc, argv, false); + args_parser.add_positional_argument(perfcore_file_arg, "Path of perfcore file", "perfcore-file", Core::ArgsParser::Required::No); + args_parser.parse(argc, argv); + + if (pid && perfcore_file_arg) { + warnln("-p/--pid option and perfcore-file argument must not be used together!"); + return 1; + } auto app = GUI::Application::construct(argc, argv); auto app_icon = GUI::Icon::default_icon("app-profiler"); - String path; - if (argc != 2) { + String perfcore_file; + if (!perfcore_file_arg) { if (!generate_profile(pid)) return 0; - path = String::formatted("/proc/{}/perf_events", pid); + perfcore_file = String::formatted("/proc/{}/perf_events", pid); } else { - path = argv[1]; + perfcore_file = perfcore_file_arg; } - auto profile_or_error = Profile::load_from_perfcore_file(path); + auto profile_or_error = Profile::load_from_perfcore_file(perfcore_file); if (profile_or_error.is_error()) { GUI::MessageBox::show(nullptr, profile_or_error.error(), "Profiler", GUI::MessageBox::Type::Error); return 0;