Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmake/Findlibdatadog.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# libdatadog : common profiler imported libraries
# https://github.com/DataDog/libdatadog/releases/tag/v7.0.0
set(TAG_LIBDATADOG
"v8.0.0"
"v9.0.0"
CACHE STRING "libdatadog github tag")

set(Datadog_ROOT ${VENDOR_PATH}/libdatadog-${TAG_LIBDATADOG})
Expand Down
22 changes: 22 additions & 0 deletions include/crash_reporter.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0. This product includes software
// developed at Datadog (https://www.datadoghq.com/). Copyright 2021-Present
// Datadog, Inc.

#pragma once

#include "ddprof_defs.hpp"
#include "ddres_def.hpp"

#include "unwind_state.hpp"

#include <span>
#include <unistd.h>

namespace ddprof {

struct ExporterInput;

bool report_crash(pid_t pid, pid_t tid, const ExporterInput &export_input);

} // namespace ddprof
16 changes: 16 additions & 0 deletions include/crash_tracker.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0. This product includes software
// developed at Datadog (https://www.datadoghq.com/). Copyright 2021-Present
// Datadog, Inc.

#pragma once

#include <string>
#include <vector>

namespace ddprof {

bool install_crash_tracker(const std::string &handler_exe,
const std::vector<std::string> &handler_args);

} // namespace ddprof
2 changes: 2 additions & 0 deletions include/ddprof_cli.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ struct DDProfCLI {
bool remote_symbolization{false};
bool disable_symbolization{false};
bool reorder_events{false}; // reorder events by timestamp
bool report_crash{false};
bool track_crashes{false};
int maximum_pids{-1};

std::string socket_path;
Expand Down
1 change: 1 addition & 0 deletions include/ddprof_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct DDProfContext {
bool remote_symbolization{false};
bool disable_symbolization{false};
bool reorder_events{false}; // reorder events by timestamp
bool report_crash{false};
int maximum_pids{0};

cpu_set_t cpu_affinity{};
Expand Down
45 changes: 45 additions & 0 deletions include/dumpable.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0. This product includes software
// developed at Datadog (https://www.datadoghq.com/). Copyright 2021-Present
// Datadog, Inc.

#pragma once

#include <sys/prctl.h>

namespace ddprof {

class DumpableRestorer {
public:
DumpableRestorer() : _was_dumpable{prctl(PR_GET_DUMPABLE) > 0} {}
~DumpableRestorer() { prctl(PR_SET_DUMPABLE, _was_dumpable ? 1 : 0); }

DumpableRestorer(const DumpableRestorer &) = delete;
DumpableRestorer operator=(const DumpableRestorer &) = delete;

private:
bool _was_dumpable;
};

class DumpableGuard {
public:
DumpableGuard() : _was_dumpable(prctl(PR_GET_DUMPABLE, 0) > 0) {
if (!_was_dumpable) {
prctl(PR_SET_DUMPABLE, 1);
}
}

~DumpableGuard() {
if (!_was_dumpable) {
prctl(PR_SET_DUMPABLE, 0);
}
}

DumpableGuard(const DumpableGuard &) = delete;
DumpableGuard operator=(const DumpableGuard &) = delete;

private:
bool _was_dumpable;
};

} // namespace ddprof
2 changes: 2 additions & 0 deletions include/exporter/ddprof_exporter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ DDRes ddprof_exporter_export(ddog_prof_Profile *profile,

DDRes ddprof_exporter_free(DDProfExporter *exporter);

std::string determine_agent_url(const ExporterInput &exporter_input);

} // namespace ddprof
3 changes: 2 additions & 1 deletion include/perf_archmap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ enum PERF_ARCHMAP_ARM {
PAM_ARM_X28,
PAM_ARM_X29,
PAM_ARM_FP = PAM_ARM_X29, // For uniformity
PAM_ARM_LR,
PAM_ARM_X30,
PAM_ARM_LR = PAM_ARM_X30, // For uniformity
PAM_ARM_SP,
PAM_ARM_PC,
PAM_ARM_MAX,
Expand Down
7 changes: 7 additions & 0 deletions include/pprof/ddprof_pprof.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "ddprof_file_info.hpp"
#include "ddres_def.hpp"
#include "perf_watcher.hpp"
#include "symbolizer.hpp"
#include "tags.hpp"
#include "unwind_output.hpp"

Expand Down Expand Up @@ -59,4 +60,10 @@ DDRes pprof_write_profile(const DDProfPProf *pprof, int fd);

DDRes pprof_free_profile(DDProfPProf *pprof);

DDRes process_symbolization(
std::span<const FunLoc> locs, const SymbolHdr &symbol_hdr,
const FileInfoVector &file_infos, Symbolizer *symbolizer,
std::array<ddog_prof_Location, kMaxStackDepth> &locations_buff,
Symbolizer::BlazeResultsWrapper &session_results, unsigned &write_index);

} // namespace ddprof
5 changes: 3 additions & 2 deletions include/stack_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "ddprof_defs.hpp"

namespace ddprof {
struct UnwindState;
bool memory_read(ProcessAddress_t addr, ElfWord_t *result, int regno,
void *arg);
}
UnwindState *us);
} // namespace ddprof
7 changes: 4 additions & 3 deletions include/symbol_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// developed at Datadog (https://www.datadoghq.com/). Copyright 2024-Present
// Datadog, Inc.

#include "defer.hpp"
#include "unwind_state.hpp"

#include <array>
Expand All @@ -12,8 +13,8 @@

namespace ddprof {
// This is a test API. Use the symbolizer to populate pprof structures
std::vector<std::string> collect_symbols(UnwindState &state,
blaze_symbolizer *symbolizer) {
inline std::vector<std::string> collect_symbols(UnwindState &state,
blaze_symbolizer *symbolizer) {
std::vector<std::string> demangled_symbols;
auto &symbol_table = state.symbol_hdr._symbol_table;
for (size_t iloc = 0; iloc < state.output.locs.size(); ++iloc) {
Expand All @@ -23,7 +24,7 @@ std::vector<std::string> collect_symbols(UnwindState &state,
std::array<ElfAddress_t, 1> elf_addr{state.output.locs[iloc].elf_addr};
const auto &file_info_value = state.dso_hdr.get_file_info_value(
state.output.locs[iloc].file_info_id);
blaze_symbolize_src_elf src_elf{
const blaze_symbolize_src_elf src_elf{
.type_size = sizeof(blaze_symbolize_src_elf),
.path = file_info_value.get_path().c_str(),
.debug_syms = true,
Expand Down
2 changes: 2 additions & 0 deletions include/symbolizer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ class Symbolizer {
int remove_unvisited();
void reset_unvisited_flag();

AddrFormat reported_addr_format() const { return _reported_addr_format; }

private:
struct BlazeSymbolizerDeleter {
void operator()(blaze_symbolizer *ptr) const {
Expand Down
16 changes: 14 additions & 2 deletions include/syscalls.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,25 @@

#pragma once

#include <csignal>
#include <sys/syscall.h>
#include <unistd.h>

namespace ddprof {
static inline pid_t gettid() { return syscall(SYS_gettid); }
inline pid_t gettid() { return syscall(SYS_gettid); }

static inline int memfd_create(const char *name, unsigned int flags) {
inline int memfd_create(const char *name, unsigned int flags) {
return syscall(SYS_memfd_create, name, flags);
}

inline int futex(uint32_t *uaddr, int futex_op, uint32_t val,
const struct timespec *timeout, uint32_t *uaddr2,
uint32_t val3) {
return syscall(SYS_futex, uaddr, futex_op, val, timeout, uaddr2, val3);
}

inline int rt_tgsigqueueinfo(int tgid, int tid, int sig, siginfo_t *uinfo) {
return syscall(SYS_rt_tgsigqueueinfo, tgid, tid, sig, uinfo);
}

} // namespace ddprof
2 changes: 1 addition & 1 deletion include/unwind.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void unwind_init_sample(UnwindState *us, const uint64_t *sample_regs,
// Main unwind API
DDRes unwindstate_unwind(UnwindState *us);

// Mark a cycle: garbadge collection, stats
// Mark a cycle: garbage collection, stats
void unwind_cycle(UnwindState *us);

// Clear unwinding structures of this pid
Expand Down
5 changes: 5 additions & 0 deletions include/unwind_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "symbol_hdr.hpp"
#include "unwind_output.hpp"

#include <functional>
#include <optional>
#include <sys/types.h>

Expand Down Expand Up @@ -63,6 +64,10 @@ struct UnwindState {
UnwindOutput output;
UniqueElf ref_elf; // reference elf object used to initialize dwfl
int maximum_pids;

using MemoryReadCallback =
std::function<bool(ProcessAddress_t addr, ElfWord_t *result, int regno)>;
MemoryReadCallback memory_read_callback; // custom memory read callback
};

std::optional<UnwindState>
Expand Down
Loading