Skip to content

Commit

Permalink
Add ifdef guards
Browse files Browse the repository at this point in the history
  • Loading branch information
cvonelm committed Aug 19, 2024
1 parent cc31de5 commit 522ac64
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions include/lo2s/monitor/process_monitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
#pragma once
#include <lo2s/monitor/abstract_process_monitor.hpp>
#include <lo2s/monitor/main_monitor.hpp>
#ifdef HAVE_BPF
#include <lo2s/monitor/posix_monitor.hpp>
#endif
#include <lo2s/monitor/scope_monitor.hpp>
#include <lo2s/process_info.hpp>

Expand Down Expand Up @@ -54,7 +56,9 @@ class ProcessMonitor : public AbstractProcessMonitor, public MainMonitor

private:
std::map<Thread, ScopeMonitor> threads_;
#ifdef HAVE_BPF
std::unique_ptr<PosixMonitor> posix_monitor_;
#endif
};
} // namespace monitor
} // namespace lo2s
10 changes: 9 additions & 1 deletion src/monitor/process_monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ namespace monitor

ProcessMonitor::ProcessMonitor() : MainMonitor()
{
#ifdef HAVE_BPF
if (config().use_posix_io)
{
posix_monitor_ = std::make_unique<PosixMonitor>(trace_);
posix_monitor_->start();
}
#endif
trace_.add_monitoring_thread(gettid(), "ProcessMonitor", "ProcessMonitor");
}

Expand All @@ -48,10 +50,13 @@ void ProcessMonitor::insert_process(Process parent, Process process, std::string

void ProcessMonitor::insert_thread(Process process, Thread thread, std::string name, bool spawn)
{

#ifdef HAVE_BPF
if (posix_monitor_)
{
posix_monitor_->insert_thread(thread);
}
#endif
trace_.add_thread(thread, name);

if (config().sampling)
Expand Down Expand Up @@ -88,10 +93,12 @@ void ProcessMonitor::update_process_name(Process process, const std::string& nam

void ProcessMonitor::exit_thread(Thread thread)
{
#ifdef HAVE_BPF
if (posix_monitor_)
{
posix_monitor_->exit_thread(thread);
}
#endif
if (threads_.count(thread) != 0)
{
threads_.at(thread).stop();
Expand All @@ -105,11 +112,12 @@ ProcessMonitor::~ProcessMonitor()
{
thread.second.stop();
}

#ifdef HAVE_BPF
if (posix_monitor_)
{
posix_monitor_->stop();
}
#endif
}
} // namespace monitor
} // namespace lo2s

0 comments on commit 522ac64

Please sign in to comment.