Commit 62303f49 authored by Alastair Robertson's avatar Alastair Robertson

Add indent before printing stack trace values (not keys)

parent 1c305ec9
...@@ -95,7 +95,7 @@ int BPFtrace::print_map(Map &map) const ...@@ -95,7 +95,7 @@ int BPFtrace::print_map(Map &map) const
return -1; return -1;
} }
if (map.type_ == Type::stack) if (map.type_ == Type::stack)
std::cout << get_stack(value); std::cout << get_stack(value, 8);
else else
std::cout << value << std::endl; std::cout << value << std::endl;
...@@ -261,9 +261,8 @@ std::vector<uint8_t> BPFtrace::find_empty_key(Map &map, size_t size) const ...@@ -261,9 +261,8 @@ std::vector<uint8_t> BPFtrace::find_empty_key(Map &map, size_t size) const
throw std::runtime_error("Could not find empty key"); throw std::runtime_error("Could not find empty key");
} }
std::string BPFtrace::get_stack(uint64_t stackid) const std::string BPFtrace::get_stack(uint64_t stackid, int indent) const
{ {
std::ostringstream stack;
auto stack_trace = std::vector<void *>(MAX_STACK_SIZE); auto stack_trace = std::vector<void *>(MAX_STACK_SIZE);
int err = bpf_lookup_elem(stackid_map_->mapfd_, &stackid, stack_trace.data()); int err = bpf_lookup_elem(stackid_map_->mapfd_, &stackid, stack_trace.data());
if (err) if (err)
...@@ -272,12 +271,15 @@ std::string BPFtrace::get_stack(uint64_t stackid) const ...@@ -272,12 +271,15 @@ std::string BPFtrace::get_stack(uint64_t stackid) const
return ""; return "";
} }
std::ostringstream stack;
std::string padding(indent, ' ');
stack << "\n"; stack << "\n";
for (auto &addr : stack_trace) for (auto &addr : stack_trace)
{ {
if (addr == nullptr) if (addr == nullptr)
break; break;
stack << (void*)addr << std::endl; stack << padding << (void*)addr << std::endl;
} }
return stack.str(); return stack.str();
......
...@@ -19,7 +19,7 @@ public: ...@@ -19,7 +19,7 @@ public:
int start(); int start();
void stop(); void stop();
int print_maps() const; int print_maps() const;
std::string get_stack(uint64_t stackid) const; std::string get_stack(uint64_t stackid, int indent=0) const;
std::map<std::string, std::unique_ptr<Map>> maps_; std::map<std::string, std::unique_ptr<Map>> maps_;
std::map<std::string, std::tuple<uint8_t *, uintptr_t>> sections_; std::map<std::string, std::tuple<uint8_t *, uintptr_t>> sections_;
......
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