Commit 4fd29552 authored by Alastair Robertson's avatar Alastair Robertson

Store number of online CPUs, so we don't need to read...

Store number of online CPUs, so we don't need to read /sys/devices/system/cpu/online while probes are running
parent ec0afc40
...@@ -250,6 +250,7 @@ int BPFtrace::setup_perf_events() ...@@ -250,6 +250,7 @@ int BPFtrace::setup_perf_events()
} }
std::vector<int> cpus = ebpf::get_online_cpus(); std::vector<int> cpus = ebpf::get_online_cpus();
online_cpus_ = cpus.size();
for (int cpu : cpus) for (int cpu : cpus)
{ {
int page_cnt = 8; int page_cnt = 8;
...@@ -277,12 +278,10 @@ int BPFtrace::setup_perf_events() ...@@ -277,12 +278,10 @@ int BPFtrace::setup_perf_events()
void BPFtrace::poll_perf_events(int epollfd, int timeout) void BPFtrace::poll_perf_events(int epollfd, int timeout)
{ {
std::vector<int> cpus = ebpf::get_online_cpus(); auto events = std::vector<struct epoll_event>(online_cpus_);
int ncpus = cpus.size();
auto events = std::vector<struct epoll_event>(ncpus);
while (true) while (true)
{ {
int ready = epoll_wait(epollfd, events.data(), ncpus, timeout); int ready = epoll_wait(epollfd, events.data(), online_cpus_, timeout);
if (ready <= 0) if (ready <= 0)
{ {
return; return;
...@@ -607,7 +606,7 @@ std::string BPFtrace::resolve_sym(uint64_t addr, bool show_offset) ...@@ -607,7 +606,7 @@ std::string BPFtrace::resolve_sym(uint64_t addr, bool show_offset)
struct bcc_symbol sym; struct bcc_symbol sym;
std::ostringstream symbol; std::ostringstream symbol;
if (ksyms.resolve_addr(addr, &sym)) if (ksyms_.resolve_addr(addr, &sym))
{ {
symbol << sym.name; symbol << sym.name;
if (show_offset) if (show_offset)
......
...@@ -45,12 +45,13 @@ protected: ...@@ -45,12 +45,13 @@ protected:
private: private:
std::vector<std::unique_ptr<AttachedProbe>> attached_probes_; std::vector<std::unique_ptr<AttachedProbe>> attached_probes_;
std::vector<std::unique_ptr<AttachedProbe>> special_attached_probes_; std::vector<std::unique_ptr<AttachedProbe>> special_attached_probes_;
KSyms ksyms; KSyms ksyms_;
int ncpus_; int ncpus_;
int online_cpus_;
std::unique_ptr<AttachedProbe> attach_probe(Probe &probe); std::unique_ptr<AttachedProbe> attach_probe(Probe &probe);
int setup_perf_events(); int setup_perf_events();
static void poll_perf_events(int epollfd, int timeout=-1); void poll_perf_events(int epollfd, int timeout=-1);
int print_map(IMap &map); int print_map(IMap &map);
int print_map_quantize(IMap &map); int print_map_quantize(IMap &map);
int print_quantize(const std::vector<uint64_t> &values) const; int print_quantize(const std::vector<uint64_t> &values) const;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment