mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
Kernel: Add .profile extension to perfcore files
This adds a ".profile" extension to perfcore files written by the Kernel. Also, the process name is now visible in the perfcore filename. Furthermore, this patch adds error handling for the case where the filename generated by the Kernel is already taken. In that case, a digit will be added to the filename (before the extension). This also adds some more error logging to dump_perfcore().
This commit is contained in:
parent
c85ab623c0
commit
a6c4e84ac8
Notes:
sideshowbarker
2024-07-18 08:47:20 +09:00
Author: https://github.com/MaxWipfli Commit: https://github.com/SerenityOS/serenity/commit/a6c4e84ac88 Pull-request: https://github.com/SerenityOS/serenity/pull/8854 Reviewed-by: https://github.com/alimpfard ✅
1 changed files with 22 additions and 7 deletions
|
@ -533,21 +533,36 @@ bool Process::dump_perfcore()
|
|||
VERIFY(is_dumpable());
|
||||
VERIFY(m_perf_event_buffer);
|
||||
dbgln("Generating perfcore for pid: {}", pid().value());
|
||||
auto description_or_error = VirtualFileSystem::the().open(String::formatted("perfcore.{}", pid().value()), O_CREAT | O_EXCL, 0400, current_directory(), UidAndGid { uid(), gid() });
|
||||
if (description_or_error.is_error())
|
||||
|
||||
// Try to generate a filename which isn't already used.
|
||||
auto base_filename = String::formatted("{}_{}", name(), pid().value());
|
||||
auto description_or_error = VirtualFileSystem::the().open(String::formatted("{}.profile", base_filename), O_CREAT | O_EXCL, 0400, current_directory(), UidAndGid { uid(), gid() });
|
||||
for (size_t attempt = 1; attempt < 10 && description_or_error.is_error(); ++attempt)
|
||||
description_or_error = VirtualFileSystem::the().open(String::formatted("{}.{}.profile", base_filename, attempt), O_CREAT | O_EXCL, 0400, current_directory(), UidAndGid { uid(), gid() });
|
||||
if (description_or_error.is_error()) {
|
||||
dbgln("Failed to generate perfcore for pid {}: Could not generate filename for the perfcore file.", pid().value());
|
||||
return false;
|
||||
auto& description = description_or_error.value();
|
||||
}
|
||||
|
||||
auto& description = *description_or_error.value();
|
||||
KBufferBuilder builder;
|
||||
if (!m_perf_event_buffer->to_json(builder))
|
||||
if (!m_perf_event_buffer->to_json(builder)) {
|
||||
dbgln("Failed to generate perfcore for pid {}: Could not serialize performance events to JSON.", pid().value());
|
||||
return false;
|
||||
}
|
||||
|
||||
auto json = builder.build();
|
||||
if (!json)
|
||||
if (!json) {
|
||||
dbgln("Failed to generate perfcore for pid {}: Could not allocate buffer.", pid().value());
|
||||
return false;
|
||||
}
|
||||
auto json_buffer = UserOrKernelBuffer::for_kernel_buffer(json->data());
|
||||
if (description->write(json_buffer, json->size()).is_error())
|
||||
if (description.write(json_buffer, json->size()).is_error()) {
|
||||
return false;
|
||||
dbgln("Wrote perfcore to {}", description->absolute_path());
|
||||
dbgln("Failed to generate perfcore for pid {}: Cound not write to perfcore file.", pid().value());
|
||||
}
|
||||
|
||||
dbgln("Wrote perfcore for pid {} to {}", pid().value(), description.absolute_path());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue