Skip to content

Commit

Permalink
Add option to disable symbolization (#380)
Browse files Browse the repository at this point in the history
  • Loading branch information
nsavoire authored Feb 22, 2024
1 parent 847f86c commit 7730467
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 13 deletions.
1 change: 1 addition & 0 deletions include/ddprof_cli.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ struct DDProfCLI {
bool fault_info{true};
bool help_extended{false};
bool remote_symbolization{false};
bool disable_symbolization{false};

std::string socket_path;
int pipefd_to_library{-1};
Expand Down
1 change: 1 addition & 0 deletions include/ddprof_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ struct DDProfContext {
bool show_samples{false};
bool timeline{false};
bool remote_symbolization{false};
bool disable_symbolization{false};

cpu_set_t cpu_affinity{};
std::string switch_user;
Expand Down
3 changes: 2 additions & 1 deletion include/dwfl_symbol_lookup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct DwflSymbolLookupStats {
class DwflSymbolLookup {
public:
// build and check env var to know check setting
DwflSymbolLookup();
explicit DwflSymbolLookup(bool disable_symbolization = false);

// Get symbol from internal cache or fetch through dwarf
SymbolIdx_t get_or_insert(const DDProfMod &ddprof_mod, SymbolTable &table,
Expand Down Expand Up @@ -85,6 +85,7 @@ class DwflSymbolLookup {
// unordered map of DSO elements
FileInfo2SymbolMap _file_info_map;
DwflSymbolLookupStats _stats;
bool _disable_symbolization{false};
};

} // namespace ddprof
6 changes: 4 additions & 2 deletions include/symbol_hdr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@

namespace ddprof {
struct SymbolHdr {
explicit SymbolHdr(std::string_view path_to_proc = "")
: _runtime_symbol_lookup(path_to_proc) {}
explicit SymbolHdr(bool disable_symbolization = false,
std::string_view path_to_proc = "")
: _dwfl_symbol_lookup(disable_symbolization),
_runtime_symbol_lookup(path_to_proc) {}
void display_stats() const {
_dwfl_symbol_lookup.stats().display(_dwfl_symbol_lookup.size());
_dso_symbol_lookup.stats_display();
Expand Down
10 changes: 7 additions & 3 deletions include/unwind_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ struct UnwindRegisters {
/// Single structure with everything necessary in unwinding. The structure is
/// given through callbacks
struct UnwindState {
explicit UnwindState(UniqueElf ref_elf, int dd_profiling_fd = -1)
: dso_hdr("", dd_profiling_fd), ref_elf(std::move(ref_elf)) {
explicit UnwindState(UniqueElf ref_elf, int dd_profiling_fd = -1,
bool disable_symbolization = false)
: dso_hdr("", dd_profiling_fd), symbol_hdr(disable_symbolization),
ref_elf(std::move(ref_elf)) {
output.clear();
output.locs.reserve(kMaxStackDepth);
}
Expand All @@ -65,7 +67,9 @@ struct UnwindState {
UniqueElf ref_elf; // reference elf object used to initialize dwfl
};

std::optional<UnwindState> create_unwind_state(int dd_profiling_fd = -1);
std::optional<UnwindState>
create_unwind_state(int dd_profiling_fd = -1,
bool disable_symbolization = false);

static inline bool unwind_registers_equal(const UnwindRegisters *lhs,
const UnwindRegisters *rhs) {
Expand Down
7 changes: 7 additions & 0 deletions src/ddprof_cli.cc
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,13 @@ int DDProfCLI::parse(int argc, const char *argv[]) {
->envname("DD_PROFILING_REMOTE_SYMBOLIZATION")
->group(""));

extended_options.push_back(app.add_flag("--disable-symbolization",
disable_symbolization,
"Disable symbolization")
->default_val(false)
->envname("DD_PROFILING_DISABLE_SYMBOLIZATION")
->group(""));

// Parse
CLI11_PARSE(app, argc, argv);

Expand Down
1 change: 1 addition & 0 deletions src/ddprof_context_lib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ void copy_cli_values(const DDProfCLI &ddprof_cli, DDProfContext &ctx) {
ctx.params.timeline = ddprof_cli.timeline;
ctx.params.fault_info = ddprof_cli.fault_info;
ctx.params.remote_symbolization = ddprof_cli.remote_symbolization;
ctx.params.disable_symbolization = ddprof_cli.disable_symbolization;

ctx.params.initial_loaded_libs_check_delay =
ddprof_cli.initial_loaded_libs_check_delay;
Expand Down
3 changes: 2 additions & 1 deletion src/ddprof_worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,8 @@ DDRes worker_library_init(DDProfContext &ctx,
// Make sure worker index is initialized correctly
ctx.worker_ctx.i_current_pprof = 0;
ctx.worker_ctx.exp_tid = {0};
auto unwind_state = create_unwind_state(ctx.params.dd_profiling_fd);
auto unwind_state = create_unwind_state(ctx.params.dd_profiling_fd,
ctx.params.disable_symbolization);
if (!unwind_state) {
LG_ERR("Failed to create unwind state");
return ddres_error(DD_WHAT_UW_ERROR);
Expand Down
6 changes: 4 additions & 2 deletions src/dwfl_symbol_lookup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

namespace ddprof {

DwflSymbolLookup::DwflSymbolLookup() {
DwflSymbolLookup::DwflSymbolLookup(bool disable_symbolization)
: _disable_symbolization(disable_symbolization) {
if (const char *env_p = std::getenv("DDPROF_CACHE_SETTING")) {
if (strcmp(env_p, "VALIDATE") == 0) {
// Allows to compare the accuracy of the cache
Expand Down Expand Up @@ -93,7 +94,8 @@ SymbolIdx_t DwflSymbolLookup::insert(const DDProfMod &ddprof_mod,

ElfAddress_t const elf_pc = process_pc - ddprof_mod._sym_bias;

if (!symbol_get_from_dwfl(ddprof_mod._mod, process_pc, symbol, elf_sym,
if (_disable_symbolization ||
!symbol_get_from_dwfl(ddprof_mod._mod, process_pc, symbol, elf_sym,
lbias)) {
++_stats._no_dwfl_symbols;
// Override with info from dso
Expand Down
5 changes: 3 additions & 2 deletions src/unwind_state.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
#include "logger.hpp"

namespace ddprof {
std::optional<UnwindState> create_unwind_state(int dd_profiling_fd) {
std::optional<UnwindState> create_unwind_state(int dd_profiling_fd,
bool disable_symbolization) {
auto elf = create_elf_from_self();
if (!elf) {
return std::nullopt;
}

return UnwindState(std::move(elf), dd_profiling_fd);
return UnwindState(std::move(elf), dd_profiling_fd, disable_symbolization);
}
} // namespace ddprof
4 changes: 3 additions & 1 deletion test/ddprof_exporter-ut.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

namespace ddprof {
// todo : cut this dependency
DwflSymbolLookup::DwflSymbolLookup() : _lookup_setting(K_CACHE_ON) {}
DwflSymbolLookup::DwflSymbolLookup(bool disable_symbolization)
: _lookup_setting(K_CACHE_ON),
_disable_symbolization(disable_symbolization) {}

// Mock
int get_nb_hw_thread() { return 2; }
Expand Down
4 changes: 3 additions & 1 deletion test/ddprof_pprof-ut.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@

namespace ddprof {
// todo : cut this dependency
DwflSymbolLookup::DwflSymbolLookup() : _lookup_setting(K_CACHE_ON) {}
DwflSymbolLookup::DwflSymbolLookup(bool disable_symbolization)
: _lookup_setting(K_CACHE_ON),
_disable_symbolization(disable_symbolization) {}

TEST(DDProfPProf, init_profiles) {
DDProfPProf pprof;
Expand Down

0 comments on commit 7730467

Please sign in to comment.