1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 05:07:45 +00:00

profile: Add -a option as an alias for "-p -1" (all processes)

This commit is contained in:
Andreas Kling 2021-03-21 16:00:52 +01:00
parent 1603623772
commit f89c479358

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -38,26 +38,28 @@ int main(int argc, char** argv)
const char* cmd_argument = nullptr; const char* cmd_argument = nullptr;
bool enable = false; bool enable = false;
bool disable = false; bool disable = false;
bool all_processes = false;
args_parser.add_option(pid_argument, "Target PID", nullptr, 'p', "PID"); args_parser.add_option(pid_argument, "Target PID", nullptr, 'p', "PID");
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(enable, "Enable", nullptr, 'e');
args_parser.add_option(disable, "Disable", nullptr, 'd'); args_parser.add_option(disable, "Disable", nullptr, 'd');
args_parser.add_option(cmd_argument, "Command", nullptr, 'c', "command"); args_parser.add_option(cmd_argument, "Command", nullptr, 'c', "command");
args_parser.parse(argc, argv); args_parser.parse(argc, argv);
if (!pid_argument && !cmd_argument) { if (!pid_argument && !cmd_argument && !all_processes) {
args_parser.print_usage(stdout, argv[0]); args_parser.print_usage(stdout, argv[0]);
return 0; return 0;
} }
if (pid_argument) { if (pid_argument || all_processes) {
if (!(enable ^ disable)) { if (!(enable ^ disable)) {
fprintf(stderr, "-p <PID> requires -e xor -d.\n"); fprintf(stderr, "-p <PID> requires -e xor -d.\n");
return 1; return 1;
} }
pid_t pid = atoi(pid_argument); pid_t pid = all_processes ? -1 : atoi(pid_argument);
if (enable) { if (enable) {
if (profiling_enable(pid) < 0) { if (profiling_enable(pid) < 0) {