Skip to content

Commit

Permalink
feat: Add separate subcommand for recording
Browse files Browse the repository at this point in the history
  • Loading branch information
BigRedEye committed Aug 2, 2022
1 parent 9636100 commit fdc56ee
Showing 1 changed file with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions src/cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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[]) {
Expand Down

0 comments on commit fdc56ee

Please sign in to comment.