aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShijia Wei <shijiawei@utexas.edu>2023-07-17 23:09:39 -0500
committeryonghong-song <ys114321@gmail.com>2023-07-30 10:28:32 -0700
commit3360c798bfefa891f1c122239101d57f014856b8 (patch)
tree5294bb9935339909fead2f46fd1009a409e72c40
parenta9e381f2dcdf693b5da48e5beb8481ab68f9b21b (diff)
downloadbcc-3360c798bfefa891f1c122239101d57f014856b8.tar.gz
Expose pid parameter in bpf_open_perf_event
-rw-r--r--src/cc/api/BPF.cc4
-rw-r--r--src/cc/api/BPF.h2
-rw-r--r--src/cc/api/BPFTable.cc9
-rw-r--r--src/cc/api/BPFTable.h4
-rw-r--r--src/python/bcc/table.py8
5 files changed, 14 insertions, 13 deletions
diff --git a/src/cc/api/BPF.cc b/src/cc/api/BPF.cc
index 3d708420..ae0e7a68 100644
--- a/src/cc/api/BPF.cc
+++ b/src/cc/api/BPF.cc
@@ -610,7 +610,7 @@ StatusTuple BPF::detach_perf_event_raw(void* perf_event_attr) {
}
StatusTuple BPF::open_perf_event(const std::string& name, uint32_t type,
- uint64_t config) {
+ uint64_t config, int pid) {
if (perf_event_arrays_.find(name) == perf_event_arrays_.end()) {
TableStorage::iterator it;
if (!bpf_module_->table_storage().Find(Path({bpf_module_->id(), name}), it))
@@ -619,7 +619,7 @@ StatusTuple BPF::open_perf_event(const std::string& name, uint32_t type,
perf_event_arrays_[name] = new BPFPerfEventArray(it->second);
}
auto table = perf_event_arrays_[name];
- TRY2(table->open_all_cpu(type, config));
+ TRY2(table->open_all_cpu(type, config, pid));
return StatusTuple::OK();
}
diff --git a/src/cc/api/BPF.h b/src/cc/api/BPF.h
index 3ea602ae..01f68e51 100644
--- a/src/cc/api/BPF.h
+++ b/src/cc/api/BPF.h
@@ -305,7 +305,7 @@ class BPF {
bool add_module(std::string module);
StatusTuple open_perf_event(const std::string& name, uint32_t type,
- uint64_t config);
+ uint64_t config, int pid = -1);
StatusTuple close_perf_event(const std::string& name);
diff --git a/src/cc/api/BPFTable.cc b/src/cc/api/BPFTable.cc
index 23beae37..8b72bec9 100644
--- a/src/cc/api/BPFTable.cc
+++ b/src/cc/api/BPFTable.cc
@@ -535,14 +535,15 @@ BPFPerfEventArray::BPFPerfEventArray(const TableDesc& desc)
"' is not a perf event array");
}
-StatusTuple BPFPerfEventArray::open_all_cpu(uint32_t type, uint64_t config) {
+StatusTuple BPFPerfEventArray::open_all_cpu(uint32_t type, uint64_t config,
+ int pid) {
if (cpu_fds_.size() != 0)
return StatusTuple(-1, "Previously opened perf event not cleaned");
std::vector<int> cpus = get_online_cpus();
for (int i : cpus) {
- auto res = open_on_cpu(i, type, config);
+ auto res = open_on_cpu(i, type, config, pid);
if (!res.ok()) {
TRY2(close_all_cpu());
return res;
@@ -573,10 +574,10 @@ StatusTuple BPFPerfEventArray::close_all_cpu() {
}
StatusTuple BPFPerfEventArray::open_on_cpu(int cpu, uint32_t type,
- uint64_t config) {
+ uint64_t config, int pid) {
if (cpu_fds_.find(cpu) != cpu_fds_.end())
return StatusTuple(-1, "Perf event already open on CPU %d", cpu);
- int fd = bpf_open_perf_event(type, config, -1, cpu);
+ int fd = bpf_open_perf_event(type, config, pid, cpu);
if (fd < 0) {
return StatusTuple(-1, "Error constructing perf event %" PRIu32 ":%" PRIu64,
type, config);
diff --git a/src/cc/api/BPFTable.h b/src/cc/api/BPFTable.h
index 681b4a94..fa11b9f8 100644
--- a/src/cc/api/BPFTable.h
+++ b/src/cc/api/BPFTable.h
@@ -437,11 +437,11 @@ class BPFPerfEventArray : public BPFTableBase<int, int> {
BPFPerfEventArray(const TableDesc& desc);
~BPFPerfEventArray();
- StatusTuple open_all_cpu(uint32_t type, uint64_t config);
+ StatusTuple open_all_cpu(uint32_t type, uint64_t config, int pid = -1);
StatusTuple close_all_cpu();
private:
- StatusTuple open_on_cpu(int cpu, uint32_t type, uint64_t config);
+ StatusTuple open_on_cpu(int cpu, uint32_t type, uint64_t config, int pid = -1);
StatusTuple close_on_cpu(int cpu);
std::map<int, int> cpu_fds_;
diff --git a/src/python/bcc/table.py b/src/python/bcc/table.py
index b35cb550..794ff4bb 100644
--- a/src/python/bcc/table.py
+++ b/src/python/bcc/table.py
@@ -1016,14 +1016,14 @@ class PerfEventArray(ArrayBase):
# The actual fd is held by the perf reader, add to track opened keys
self._open_key_fds[cpu] = -1
- def _open_perf_event(self, cpu, typ, config):
- fd = lib.bpf_open_perf_event(typ, config, -1, cpu)
+ def _open_perf_event(self, cpu, typ, config, pid=-1):
+ fd = lib.bpf_open_perf_event(typ, config, pid, cpu)
if fd < 0:
raise Exception("bpf_open_perf_event failed")
self[self.Key(cpu)] = self.Leaf(fd)
self._open_key_fds[cpu] = fd
- def open_perf_event(self, typ, config):
+ def open_perf_event(self, typ, config, pid=-1):
"""open_perf_event(typ, config)
Configures the table such that calls from the bpf program to
@@ -1031,7 +1031,7 @@ class PerfEventArray(ArrayBase):
counter denoted by event ev on the local cpu.
"""
for i in get_online_cpus():
- self._open_perf_event(i, typ, config)
+ self._open_perf_event(i, typ, config, pid)
class PerCpuHash(HashTable):