Skip to content

Commit

Permalink
Add an hidden option to enable remote symbolization
Browse files Browse the repository at this point in the history
Enabling remote symbolization currently has 2 effects
* use elf addresses instead of process addresses in exported pprof
* add a `remote_symbols:yes` tag
  • Loading branch information
nsavoire committed Feb 5, 2024
1 parent 2c27bc0 commit 5f25f84
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 12 deletions.
2 changes: 2 additions & 0 deletions include/ddprof_cli.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ struct DDProfCLI {
bool show_samples{false};
bool fault_info{true};
bool help_extended{false};
bool remote_symbolization{false};

std::string socket_path;
int pipefd_to_library{-1};
bool continue_exec{false};
Expand Down
2 changes: 2 additions & 0 deletions include/ddprof_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ struct DDProfContext {
UniqueFd pipefd_to_library;
bool show_samples{false};
bool timeline{false};
bool remote_symbolization{false};

cpu_set_t cpu_affinity{};
std::string switch_user;
std::string internal_stats;
Expand Down
1 change: 1 addition & 0 deletions include/pprof/ddprof_pprof.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ struct DDProfPProf {
ddog_prof_Profile _profile{};
unsigned _nb_values = 0;
Tags _tags;
bool use_process_adresses{true};
};

struct DDProfValuePack {
Expand Down
4 changes: 2 additions & 2 deletions include/unwind_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ struct UnwindState;

bool is_max_stack_depth_reached(const UnwindState &us);

DDRes add_frame(SymbolIdx_t symbol_idx, MapInfoIdx_t map_idx, ElfAddress_t pc,
UnwindState *us);
DDRes add_frame(SymbolIdx_t symbol_idx, MapInfoIdx_t map_idx,
ProcessAddress_t pc, ElfAddress_t elf_addr, UnwindState *us);

void add_common_frame(UnwindState *us, SymbolErrors lookup_case);

Expand Down
3 changes: 2 additions & 1 deletion include/unwind_output.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
namespace ddprof {

struct FunLoc {
uint64_t ip; // Relative to file, not VMA
ProcessAddress_t ip; // process address
ElfAddress_t elf_addr; // elf address (in elf file virtual memory space)
SymbolIdx_t _symbol_idx;
MapInfoIdx_t _map_info_idx;

Expand Down
1 change: 1 addition & 0 deletions include/unwind_output_hash.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct UnwindOutputHash {
hash_combine(seed, uo.tid);
for (const auto &fl : uo.locs) {
hash_combine(seed, fl.ip);
// no need to hash fl.elf_addr since it's derived from fl.ip
hash_combine(seed, fl._symbol_idx);
hash_combine(seed, fl._map_info_idx);
}
Expand Down
7 changes: 7 additions & 0 deletions src/ddprof_cli.cc
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,13 @@ int DDProfCLI::parse(int argc, const char *argv[]) {
->envname("DD_PROFILING_LOADED_LIBS_CHECK_INTERVAL")
->group(""));

extended_options.push_back(app.add_option("--remote_symbolization",
remote_symbolization,
"Enable remote symbolization")
->default_val(false)
->envname("DD_PROFILING_REMOTE_SYMBOLIZATION")
->group(""));

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

Expand Down
2 changes: 2 additions & 0 deletions src/ddprof_context_lib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ void copy_cli_values(const DDProfCLI &ddprof_cli, DDProfContext &ctx) {
ctx.params.show_samples = ddprof_cli.show_samples;
ctx.params.timeline = ddprof_cli.timeline;
ctx.params.fault_info = ddprof_cli.fault_info;
ctx.params.remote_symbolization = ddprof_cli.remote_symbolization;

ctx.params.initial_loaded_libs_check_delay =
ddprof_cli.initial_loaded_libs_check_delay;
ctx.params.loaded_libs_check_interval = ddprof_cli.loaded_libs_check_interval;
Expand Down
18 changes: 14 additions & 4 deletions src/pprof/ddprof_pprof.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ void write_mapping(const MapInfo &mapinfo, ddog_prof_Mapping *ffi_mapping) {
}

void write_location(const FunLoc *loc, const MapInfo &mapinfo,
const Symbol &symbol, ddog_prof_Location *ffi_location) {
const Symbol &symbol, ddog_prof_Location *ffi_location,
bool use_process_adresses) {
write_mapping(mapinfo, &ffi_location->mapping);
write_function(symbol, &ffi_location->function);
ffi_location->address = loc->ip;
ffi_location->address = use_process_adresses ? loc->ip : loc->elf_addr;
ffi_location->line = symbol._lineno;
}

Expand Down Expand Up @@ -255,6 +256,14 @@ DDRes pprof_create_profile(DDProfPProf *pprof, DDProfContext &ctx) {
std::string("container_id"));
}

if (ctx.params.remote_symbolization) {
pprof->_tags.emplace_back(std::string("remote_symbols"),
std::string("yes"));
pprof->use_process_adresses = false;
} else {
pprof->use_process_adresses = true;
}

return {};
}

Expand Down Expand Up @@ -301,7 +310,8 @@ DDRes pprof_aggregate(const UnwindOutput *uw_output,
for (const FunLoc &loc : locs) {
// possibly several lines to handle inlined function (not handled for now)
write_location(&loc, mapinfo_table[loc._map_info_idx],
symbol_table[loc._symbol_idx], &locations_buff[cur_loc]);
symbol_table[loc._symbol_idx], &locations_buff[cur_loc],
pprof->use_process_adresses);
++cur_loc;
}

Expand Down Expand Up @@ -401,7 +411,7 @@ void ddprof_print_sample(const UnwindOutput &uw_output,
buf += path.substr(pos == std::string_view::npos ? 0 : pos + 1);
buf += ")";
} else {
absl::StrAppendFormat(&buf, "%#x", loc_it->ip);
absl::StrAppendFormat(&buf, "%#x/%#x", loc_it->ip, loc_it->elf_addr);
}
} else {
std::string_view const func{sym._symname};
Expand Down
5 changes: 3 additions & 2 deletions src/unwind_dwfl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ DDRes add_dwfl_frame(UnwindState *us, const Dso &dso, ElfAddress_t pc,
unwind_symbol_hdr._dso_symbol_lookup, file_info_id, pc, dso);
MapInfoIdx_t const map_idx = us->symbol_hdr._mapinfo_lookup.get_or_insert(
us->pid, us->symbol_hdr._mapinfo_table, dso, ddprof_mod._build_id);
return add_frame(symbol_idx, map_idx, pc, us);
return add_frame(symbol_idx, map_idx, pc, pc - ddprof_mod._sym_bias, us);
}

// check for runtime symbols provided in /tmp files
Expand All @@ -250,7 +250,8 @@ DDRes add_runtime_symbol_frame(UnwindState *us, const Dso &dso, ElfAddress_t pc,
MapInfoIdx_t const map_idx = us->symbol_hdr._mapinfo_lookup.get_or_insert(
us->pid, us->symbol_hdr._mapinfo_table, dso, {});

return add_frame(symbol_idx, map_idx, pc, us);
return add_frame(symbol_idx, map_idx, pc, pc - dso.start() + dso.offset(),
us);
}
} // namespace

Expand Down
7 changes: 4 additions & 3 deletions src/unwind_helpers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace ddprof {

namespace {
void add_frame_without_mapping(UnwindState *us, SymbolIdx_t symbol_idx) {
add_frame(symbol_idx, -1, 0, us);
add_frame(symbol_idx, -1, 0, 0, us);
}

} // namespace
Expand All @@ -25,8 +25,8 @@ bool is_max_stack_depth_reached(const UnwindState &us) {
return us.output.locs.size() + 2 >= kMaxStackDepth;
}

DDRes add_frame(SymbolIdx_t symbol_idx, MapInfoIdx_t map_idx, ElfAddress_t pc,
UnwindState *us) {
DDRes add_frame(SymbolIdx_t symbol_idx, MapInfoIdx_t map_idx,
ProcessAddress_t pc, ElfAddress_t elf_addr, UnwindState *us) {
UnwindOutput *output = &us->output;
if (output->locs.size() >= kMaxStackDepth) {
DDRES_RETURN_WARN_LOG(DD_WHAT_UW_MAX_DEPTH,
Expand All @@ -35,6 +35,7 @@ DDRes add_frame(SymbolIdx_t symbol_idx, MapInfoIdx_t map_idx, ElfAddress_t pc,
FunLoc current;
current._symbol_idx = symbol_idx;
current.ip = pc;
current.elf_addr = elf_addr;
if (map_idx == -1) {
// just add an empty element for mapping info
current._map_info_idx = us->symbol_hdr._common_mapinfo_lookup.get_or_insert(
Expand Down

0 comments on commit 5f25f84

Please sign in to comment.