From fdc56eec1f2c47406987364af0f7ec18b0732ca0 Mon Sep 17 00:00:00 2001 From: Sergey Skvortsov Date: Tue, 2 Aug 2022 17:47:15 +0300 Subject: [PATCH] feat: Add separate subcommand for recording --- src/cli/main.cpp | 43 +++++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/src/cli/main.cpp b/src/cli/main.cpp index 5a0bcd9..dbfa0ca 100644 --- a/src/cli/main.cpp +++ b/src/cli/main.cpp @@ -787,18 +787,7 @@ Options ParseOptions(int argc, const char* argv[]) { return options; } -int Main(int argc, const char* argv[]) { - if (const char* env = std::getenv("POORPROF_LOG_LEVEL")) { - spdlog::set_level(spdlog::level::from_str(env)); - } else { - spdlog::set_level(spdlog::level::info); - } - spdlog::set_default_logger(spdlog::stderr_color_mt("stderr")); - spdlog::set_pattern("%Y-%m-%dT%H:%M:%S.%f {%^%l%$} %v"); - DEFER { - spdlog::shutdown(); - }; - +int Record(int argc, const char* argv[]) { util::HandleSigInt(3); Options options = ParseOptions(argc, argv); @@ -837,6 +826,36 @@ int Main(int argc, const char* argv[]) { return 0; } +int Main(int argc, const char* argv[]) { + if (const char* env = std::getenv("POORPROF_LOG_LEVEL")) { + spdlog::set_level(spdlog::level::from_str(env)); + } else { + spdlog::set_level(spdlog::level::info); + } + spdlog::set_default_logger(spdlog::stderr_color_mt("stderr")); + spdlog::set_pattern("%Y-%m-%dT%H:%M:%S.%f {%^%l%$} %v"); + DEFER { + spdlog::shutdown(); + }; + + cpparg::command_parser parser{argv[0]}; + parser.title("Poorprof -- wall time profiler"); + + parser + .command("record") + .description("Collect stack samples from running process") + .handle(Record); + + parser + .command("help") + .description("Show this help") + .handle([&parser](...) { + parser.exit_with_help("", 0); + }); + + return parser.parse(argc, argv); +} + } // namespace poorprof int main(int argc, const char* argv[]) {