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

UserspaceEmulator: Optionally generate a Profiler-compatible profile

`ue --profile --profile-file ~/some-file.profile id` can now generate a
full profile (instruction-by-instruction, if needed), at the cost of not
being able to see past the syscall boundary (a.la. callgrind).
This makes it significantly easier to profile seemingly fast userspace
things, like Loader.so :^)
This commit is contained in:
Ali Mohammad Pur 2021-08-05 22:42:31 +04:30 committed by Andreas Kling
parent 3829bf115c
commit 521217735b
4 changed files with 91 additions and 1 deletions

View file

@ -8,6 +8,7 @@
#include "MmapRegion.h"
#include "SimpleRegion.h"
#include <AK/Debug.h>
#include <AK/FileStream.h>
#include <AK/Format.h>
#include <fcntl.h>
#include <sched.h>
@ -27,6 +28,9 @@
# pragma GCC optimize("O3")
#endif
extern bool g_dump_profile;
extern Optional<OutputFileStream> g_profile_stream;
namespace UserspaceEmulator {
u32 Emulator::virt_syscall(u32 function, u32 arg1, u32 arg2, u32 arg3)
@ -812,6 +816,8 @@ static void round_to_page_size(FlatPtr& address, size_t& size)
u32 Emulator::virt$munmap(FlatPtr address, size_t size)
{
if (g_dump_profile)
emit_profile_event(*g_profile_stream, "munmap", String::formatted("\"ptr\": {}, \"size\": {}", address, size));
round_to_page_size(address, size);
Vector<Region*, 4> marked_for_deletion;
bool has_non_mmap_region = false;
@ -870,6 +876,9 @@ u32 Emulator::virt$mmap(u32 params_addr)
name_str = { name.data(), name.size() };
}
if (g_dump_profile)
emit_profile_event(*g_profile_stream, "mmap", String::formatted(R"("ptr": {}, "size": {}, "name": "{}")", final_address, final_size, name_str));
if (params.flags & MAP_ANONYMOUS) {
mmu().add_region(MmapRegion::create_anonymous(final_address, final_size, params.prot, move(name_str)));
} else {