Skip to content

Commit

Permalink
fix(process monitoring): dont abort lo2s on unexpected child process
Browse files Browse the repository at this point in the history
exit

If currently a process exits after ptrace catched it but before
sampling with perf_event_open has been set up, perf_event_open will
throw ESRCH ("no such process"), aborting lo2s.

Instead, handle ESRCH more gracefully by printing a warning but
otherwise ignoring the non-existent process.
  • Loading branch information
cvonelm committed Mar 6, 2024
1 parent ccbae16 commit 3a578c0
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/monitor/process_monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,27 @@ void ProcessMonitor::insert_thread(Process process, Thread thread, std::string n
perf::counter::CounterProvider::instance().has_group_counters(ExecutionScope(thread)) ||
perf::counter::CounterProvider::instance().has_userspace_counters(ExecutionScope(thread)))
{
auto inserted =
threads_.emplace(std::piecewise_construct, std::forward_as_tuple(thread),
std::forward_as_tuple(ExecutionScope(thread), *this, spawn));
assert(inserted.second);
// actually start thread
inserted.first->second.start();
try
{
auto inserted =
threads_.emplace(std::piecewise_construct, std::forward_as_tuple(thread),
std::forward_as_tuple(ExecutionScope(thread), *this, spawn));
assert(inserted.second);
// actually start thread
inserted.first->second.start();
}
catch (std::system_error& e)
{
if (e.code().value() == ESRCH)
{
Log::warn() << process << " (" << name
<< ") disappeared before perf_event_open, ignoring!";
}
else
{
throw;
}
}
}

trace_.update_thread_name(thread, name);
Expand Down

0 comments on commit 3a578c0

Please sign in to comment.