Add BPFStackTable::free_symcache() to free the symbol cache for an PID (#3371)
authoryzhao <yzhao@pixielabs.ai>
Wed, 28 Apr 2021 04:48:34 +0000 (21:48 -0700)
committerGitHub <noreply@github.com>
Wed, 28 Apr 2021 04:48:34 +0000 (21:48 -0700)
This is useful when BPFStackTable is used by a long running program to
limit the memory usage, by removing the cached symbols of an exited
process.

src/cc/api/BPFTable.cc
src/cc/api/BPFTable.h

index 1ea04e3e5db72aa4078ee43ce3799fcdcaa07b17..d1050512521f36aa4d1a36f3eb739f35873c4d5d 100644 (file)
@@ -274,6 +274,14 @@ BPFStackTable::~BPFStackTable() {
     bcc_free_symcache(it.second, it.first);
 }
 
+void BPFStackTable::free_symcache(int pid) {
+  auto iter = pid_sym_.find(pid);
+  if (iter != pid_sym_.end()) {
+    bcc_free_symcache(iter->second, iter->first);
+    pid_sym_.erase(iter);
+  }
+}
+
 void BPFStackTable::clear_table_non_atomic() {
   for (int i = 0; size_t(i) < capacity(); i++) {
     remove(&i);
index d75157591f6e91317c4f1216eaee3abde83c3981..d63f3c5db993ef991ee249ce8a5ac9fbfb959f47 100644 (file)
@@ -378,6 +378,7 @@ class BPFStackTable : public BPFTableBase<int, stacktrace_t> {
   BPFStackTable(BPFStackTable&& that);
   ~BPFStackTable();
 
+  void free_symcache(int pid);
   void clear_table_non_atomic();
   std::vector<uintptr_t> get_stack_addr(int stack_id);
   std::vector<std::string> get_stack_symbol(int stack_id, int pid);