mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-06 02:55:49 +03:00
profile: Port to LibMain
This commit is contained in:
parent
73303f0dc1
commit
434925bbd8
Notes:
sideshowbarker
2024-07-17 18:56:15 +09:00
Author: https://github.com/rvictorr Commit: https://github.com/SerenityOS/serenity/commit/434925bbd8 Pull-request: https://github.com/SerenityOS/serenity/pull/12469 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/AtkinsSJ
@ -154,6 +154,7 @@ target_link_libraries(pls LibCrypt LibMain)
|
||||
target_link_libraries(pmap LibMain)
|
||||
target_link_libraries(pmemdump LibMain)
|
||||
target_link_libraries(pro LibMain LibProtocol)
|
||||
target_link_libraries(profile LibMain)
|
||||
target_link_libraries(ps LibMain)
|
||||
target_link_libraries(pwd LibMain)
|
||||
target_link_libraries(realpath LibMain)
|
||||
|
@ -5,11 +5,13 @@
|
||||
*/
|
||||
|
||||
#include <LibCore/ArgsParser.h>
|
||||
#include <LibCore/System.h>
|
||||
#include <LibMain/Main.h>
|
||||
#include <serenity.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
{
|
||||
Core::ArgsParser args_parser;
|
||||
|
||||
@ -60,13 +62,13 @@ int main(int argc, char** argv)
|
||||
outln("Event type can be one of: sample, context_switch, page_fault, syscall, kmalloc and kfree.");
|
||||
};
|
||||
|
||||
if (!args_parser.parse(argc, argv, Core::ArgsParser::FailureBehavior::PrintUsage)) {
|
||||
if (!args_parser.parse(arguments, Core::ArgsParser::FailureBehavior::PrintUsage)) {
|
||||
print_types();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (!pid_argument && !cmd_argument && !all_processes) {
|
||||
args_parser.print_usage(stdout, argv[0]);
|
||||
args_parser.print_usage(stdout, arguments.argv[0]);
|
||||
print_types();
|
||||
return 0;
|
||||
}
|
||||
@ -83,10 +85,7 @@ int main(int argc, char** argv)
|
||||
pid_t pid = all_processes ? -1 : atoi(pid_argument);
|
||||
|
||||
if (wait || enable) {
|
||||
if (profiling_enable(pid, event_mask) < 0) {
|
||||
perror("profiling_enable");
|
||||
return 1;
|
||||
}
|
||||
TRY(Core::System::profiling_enable(pid, event_mask));
|
||||
|
||||
if (!wait)
|
||||
return 0;
|
||||
@ -97,17 +96,11 @@ int main(int argc, char** argv)
|
||||
(void)getchar();
|
||||
}
|
||||
|
||||
if (wait || disable) {
|
||||
if (profiling_disable(pid) < 0) {
|
||||
perror("profiling_disable");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (wait || disable)
|
||||
TRY(Core::System::profiling_disable(pid));
|
||||
|
||||
if (free && profiling_free_buffer(pid) < 0) {
|
||||
perror("profiling_disable");
|
||||
return 1;
|
||||
}
|
||||
if (free)
|
||||
TRY(Core::System::profiling_free_buffer(pid));
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -121,7 +114,7 @@ int main(int argc, char** argv)
|
||||
cmd_argv.append(nullptr);
|
||||
|
||||
dbgln("Enabling profiling for PID {}", getpid());
|
||||
profiling_enable(getpid(), event_mask);
|
||||
TRY(Core::System::profiling_enable(getpid(), event_mask));
|
||||
if (execvp(cmd_argv[0], const_cast<char**>(cmd_argv.data())) < 0) {
|
||||
perror("execv");
|
||||
return 1;
|
||||
|
Loading…
Reference in New Issue
Block a user