mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 03:47:34 +00:00
Kernel: Make PerformanceEventBuffer::add_process fallible with ErrorOr
This commit is contained in:
parent
d2ffcfb762
commit
8a4654a924
4 changed files with 22 additions and 16 deletions
|
@ -313,29 +313,34 @@ OwnPtr<PerformanceEventBuffer> PerformanceEventBuffer::try_create_with_size(size
|
||||||
return adopt_own_if_nonnull(new (nothrow) PerformanceEventBuffer(buffer_or_error.release_value()));
|
return adopt_own_if_nonnull(new (nothrow) PerformanceEventBuffer(buffer_or_error.release_value()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void PerformanceEventBuffer::add_process(const Process& process, ProcessEventType event_type)
|
ErrorOr<void> PerformanceEventBuffer::add_process(const Process& process, ProcessEventType event_type)
|
||||||
{
|
{
|
||||||
SpinlockLocker locker(process.address_space().get_lock());
|
SpinlockLocker locker(process.address_space().get_lock());
|
||||||
|
|
||||||
OwnPtr<KString> executable;
|
OwnPtr<KString> executable;
|
||||||
if (process.executable())
|
if (process.executable())
|
||||||
executable = MUST(process.executable()->try_serialize_absolute_path());
|
executable = TRY(process.executable()->try_serialize_absolute_path());
|
||||||
else
|
else
|
||||||
executable = MUST(KString::formatted("<{}>", process.name()));
|
executable = TRY(KString::formatted("<{}>", process.name()));
|
||||||
|
|
||||||
[[maybe_unused]] auto rc = append_with_ip_and_bp(process.pid(), 0, 0, 0,
|
TRY(append_with_ip_and_bp(process.pid(), 0, 0, 0,
|
||||||
event_type == ProcessEventType::Create ? PERF_EVENT_PROCESS_CREATE : PERF_EVENT_PROCESS_EXEC,
|
event_type == ProcessEventType::Create ? PERF_EVENT_PROCESS_CREATE : PERF_EVENT_PROCESS_EXEC,
|
||||||
0, process.pid().value(), 0, executable->view());
|
0, process.pid().value(), 0, executable->view()));
|
||||||
|
|
||||||
|
ErrorOr<void> result;
|
||||||
process.for_each_thread([&](auto& thread) {
|
process.for_each_thread([&](auto& thread) {
|
||||||
[[maybe_unused]] auto rc = append_with_ip_and_bp(process.pid(), thread.tid().value(),
|
result = append_with_ip_and_bp(process.pid(), thread.tid().value(),
|
||||||
0, 0, PERF_EVENT_THREAD_CREATE, 0, 0, 0, nullptr);
|
0, 0, PERF_EVENT_THREAD_CREATE, 0, 0, 0, nullptr);
|
||||||
|
return result.is_error() ? IterationDecision::Break : IterationDecision::Continue;
|
||||||
});
|
});
|
||||||
|
TRY(result);
|
||||||
|
|
||||||
for (auto const& region : process.address_space().regions()) {
|
for (auto const& region : process.address_space().regions()) {
|
||||||
[[maybe_unused]] auto rc = append_with_ip_and_bp(process.pid(), 0,
|
TRY(append_with_ip_and_bp(process.pid(), 0,
|
||||||
0, 0, PERF_EVENT_MMAP, 0, region->range().base().get(), region->range().size(), region->name());
|
0, 0, PERF_EVENT_MMAP, 0, region->range().base().get(), region->range().size(), region->name()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<FlatPtr> PerformanceEventBuffer::register_string(NonnullOwnPtr<KString> string)
|
ErrorOr<FlatPtr> PerformanceEventBuffer::register_string(NonnullOwnPtr<KString> string)
|
||||||
|
|
|
@ -121,7 +121,7 @@ public:
|
||||||
|
|
||||||
ErrorOr<void> to_json(KBufferBuilder&) const;
|
ErrorOr<void> to_json(KBufferBuilder&) const;
|
||||||
|
|
||||||
void add_process(const Process&, ProcessEventType event_type);
|
ErrorOr<void> add_process(const Process&, ProcessEventType event_type);
|
||||||
|
|
||||||
ErrorOr<FlatPtr> register_string(NonnullOwnPtr<KString>);
|
ErrorOr<FlatPtr> register_string(NonnullOwnPtr<KString>);
|
||||||
|
|
||||||
|
|
|
@ -18,14 +18,14 @@ public:
|
||||||
{
|
{
|
||||||
if (g_profiling_all_threads) {
|
if (g_profiling_all_threads) {
|
||||||
VERIFY(g_global_perf_events);
|
VERIFY(g_global_perf_events);
|
||||||
g_global_perf_events->add_process(process, ProcessEventType::Create);
|
(void)g_global_perf_events->add_process(process, ProcessEventType::Create);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline static void add_process_exec_event(Process& process)
|
inline static void add_process_exec_event(Process& process)
|
||||||
{
|
{
|
||||||
if (auto* event_buffer = process.current_perf_events_buffer()) {
|
if (auto* event_buffer = process.current_perf_events_buffer()) {
|
||||||
event_buffer->add_process(process, ProcessEventType::Exec);
|
(void)event_buffer->add_process(process, ProcessEventType::Exec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -788,11 +788,12 @@ void Process::tracer_trap(Thread& thread, const RegisterState& regs)
|
||||||
|
|
||||||
bool Process::create_perf_events_buffer_if_needed()
|
bool Process::create_perf_events_buffer_if_needed()
|
||||||
{
|
{
|
||||||
if (!m_perf_event_buffer) {
|
if (m_perf_event_buffer)
|
||||||
m_perf_event_buffer = PerformanceEventBuffer::try_create_with_size(4 * MiB);
|
return true;
|
||||||
m_perf_event_buffer->add_process(*this, ProcessEventType::Create);
|
m_perf_event_buffer = PerformanceEventBuffer::try_create_with_size(4 * MiB);
|
||||||
}
|
if (!m_perf_event_buffer)
|
||||||
return !!m_perf_event_buffer;
|
return false;
|
||||||
|
return !m_perf_event_buffer->add_process(*this, ProcessEventType::Create).is_error();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Process::delete_perf_events_buffer()
|
void Process::delete_perf_events_buffer()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue