Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ endif()

# Add echion
set(ECHION_COMMIT
"1b02a8fcccaa4b748b494f3c3177b78be6503967" # https://github.com/P403n1x87/echion/commit/1b02a8fcccaa4b748b494f3c3177b78be6503967
"76e4c237b8813555f7a3ae386409afd55c973fbf" # https://github.com/P403n1x87/echion/commit/76e4c237b8813555f7a3ae386409afd55c973fbf
CACHE STRING "Commit hash of echion to use")
FetchContent_Declare(
echion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class StackRenderer : public RendererInterface
// the sample is created, this has to be reset.
bool pushed_task_name = false;

Result<void> open() override { return Result<void>::ok(); }
void open() override {}
void close() override {}
void header() override {}
void metadata(const std::string&, const std::string&) override {}
Expand Down
17 changes: 7 additions & 10 deletions ddtrace/internal/datadog/profiling/stack_v2/src/sampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include "thread_span_links.hpp"

#include "echion/errors.h"
#include "echion/greenlets.h"
#include "echion/interp.h"
#include "echion/tasks.h"
Expand Down Expand Up @@ -154,7 +153,7 @@ Sampler::sampling_thread(const uint64_t seq_num)
// Perform the sample
for_each_interp([&](InterpreterInfo& interp) -> void {
for_each_thread(interp, [&](PyThreadState* tstate, ThreadInfo& thread) {
(void)thread.sample(interp.id, tstate, wall_time_us);
thread.sample(interp.id, tstate, wall_time_us);
});
});

Expand Down Expand Up @@ -246,21 +245,19 @@ Sampler::register_thread(uint64_t id, uint64_t native_id, const char* name)
static bool has_errored = false;
auto it = thread_info_map.find(id);
if (it == thread_info_map.end()) {
auto maybe_thread_info = ThreadInfo::create(id, native_id, name);
if (maybe_thread_info) {
thread_info_map.emplace(id, std::move(*maybe_thread_info));
} else {
try {
thread_info_map.emplace(id, std::make_unique<ThreadInfo>(id, native_id, name));
} catch (const ThreadInfo::Error& e) {
if (!has_errored) {
has_errored = true;
std::cerr << "Failed to register thread: " << std::hex << id << std::dec << " (" << native_id << ") "
<< name << std::endl;
}
}
} else {
auto maybe_thread_info = ThreadInfo::create(id, native_id, name);
if (maybe_thread_info) {
it->second = std::move(*maybe_thread_info);
} else {
try {
it->second = std::make_unique<ThreadInfo>(id, native_id, name);
} catch (const ThreadInfo::Error& e) {
if (!has_errored) {
has_errored = true;
std::cerr << "Failed to register thread: " << std::hex << id << std::dec << " (" << native_id << ") "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,22 @@ StackRenderer::render_frame(Frame& frame)
// some defaults.
static constexpr std::string_view missing_filename = "<unknown file>";
static constexpr std::string_view missing_name = "<unknown function>";

auto line = frame.location.line;

std::string_view filename_str;
std::string_view name_str;
auto maybe_name_str = string_table.lookup(frame.name);
if (maybe_name_str) {
name_str = maybe_name_str->get();
} else {
try {
filename_str = string_table.lookup(frame.filename);
} catch (StringTable::Error&) {
filename_str = missing_filename;
}

try {
name_str = string_table.lookup(frame.name);
} catch (StringTable::Error&) {
name_str = missing_name;
}

auto line = frame.location.line;

// DEV: Echion pushes a dummy frame containing task name, and its line
// number is set to 0.
if (line == 0) {
Expand All @@ -151,14 +156,6 @@ StackRenderer::render_frame(Frame& frame)
return;
}

std::string_view filename_str;
auto maybe_filename_str = string_table.lookup(frame.filename);
if (maybe_filename_str) {
filename_str = maybe_filename_str->get();
} else {
filename_str = missing_filename;
}

ddup_push_frame(sample, name_str, filename_str, 0, line);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,15 +210,16 @@ track_greenlet(PyObject* Py_UNUSED(m), PyObject* args)
if (!PyArg_ParseTuple(args, "lOO", &greenlet_id, &name, &frame))
return NULL;

auto maybe_greenlet_name = string_table.key(name);
if (!maybe_greenlet_name) {
StringTable::Key greenlet_name;

try {
greenlet_name = string_table.key(name);
} catch (StringTable::Error&) {
// We failed to get this task but we keep going
PyErr_SetString(PyExc_RuntimeError, "Failed to get greenlet name from the string table");
return NULL;
}

auto greenlet_name = *maybe_greenlet_name;

Py_BEGIN_ALLOW_THREADS;
Sampler::get().track_greenlet(greenlet_id, greenlet_name, frame);
Py_END_ALLOW_THREADS;
Expand Down