Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
dd6bece
perf(profiling): honor configured maximum frame count
taegyunkim Jul 15, 2026
f7aa16e
Merge branch 'main' into taegyunkim/prof-14213-propagate-max-frames
taegyunkim Jul 17, 2026
a4800c7
refactor(profiling): use frame config directly
taegyunkim Jul 17, 2026
ac6a45d
refactor(profiling): clarify stack frame limit naming
taegyunkim Jul 17, 2026
c979a4e
Merge branch 'main' into taegyunkim/prof-14213-propagate-max-frames
taegyunkim Jul 21, 2026
07e6264
Merge remote-tracking branch 'origin/main' into taegyunkim/prof-14213…
taegyunkim Aug 12, 2026
cf54353
Merge remote-tracking branch 'origin/main' into taegyunkim/prof-14213…
taegyunkim Aug 12, 2026
3ee80d5
fix(profiling): preserve native frame limit semantics
taegyunkim Aug 12, 2026
cd17890
Merge branch 'main' into taegyunkim/prof-14213-propagate-max-frames
taegyunkim Aug 13, 2026
e7b4fa0
Merge remote-tracking branch 'origin/main' into taegyunkim/prof-14213…
taegyunkim Aug 14, 2026
c68120f
Merge remote-tracking branch 'origin/taegyunkim/prof-14213-propagate-…
taegyunkim Aug 14, 2026
56be92f
test(profiling): strengthen frame limit regressions
taegyunkim Aug 17, 2026
bc3e3ea
fix(profiling): avoid false truncation markers
taegyunkim Aug 17, 2026
7c5caf1
refactor(profiling): return stack unwind metadata
taegyunkim Aug 18, 2026
ec93733
refactor(profiling): clarify stack unwind controls
taegyunkim Aug 19, 2026
0b6cd5e
refactor(profiling): make truncation status explicit
taegyunkim Aug 19, 2026
fb910b6
refactor(profiling): align plain stack default
taegyunkim Aug 19, 2026
28ec6bd
perf(profiling): bound task stack collection
taegyunkim Jul 15, 2026
aaadf06
fix(profiling): resolve clang-tidy issues
taegyunkim Jul 15, 2026
f5a6906
Merge branch 'main' into taegyunkim/prof-14213-propagate-max-frames
taegyunkim Aug 21, 2026
ecd37d9
perf(profiling): merge main and clarify frame-limit unwinding
taegyunkim Sep 9, 2026
b8284b1
fix(profiling): handle fuzz unwind result and separate release-note u…
taegyunkim Sep 9, 2026
14ccc62
Merge origin/main into taegyunkim/prof-14213-propagate-max-frames
taegyunkim Sep 10, 2026
eb7cc2a
refactor(profiling): rename unknown truncation state
taegyunkim Sep 10, 2026
a705c40
Merge remote-tracking branch 'origin/taegyunkim/prof-14213-propagate-…
taegyunkim Sep 10, 2026
d175ccd
test(profiling): update stack discovery limit coverage
taegyunkim Sep 10, 2026
89c3bc8
Merge remote-tracking branch 'origin/main' into taegyunkim/prof-14213…
taegyunkim Sep 14, 2026
9a45b10
Merge branch 'main' into taegyunkim/prof-14213-task-stack-frame-budget
taegyunkim Sep 15, 2026
7f050d0
docs(profiling): simplify task stack release note
taegyunkim Sep 15, 2026
a86914f
Merge origin/main into taegyunkim/prof-14213-task-stack-frame-budget
taegyunkim Sep 21, 2026
1001c2e
refactor(profiling): defer frame cache scaling to follow-up
taegyunkim Sep 21, 2026
2be8f16
Merge latest origin/main into taegyunkim/prof-14213-task-stack-frame-…
taegyunkim Sep 21, 2026
375e522
docs(profiling): explain omission marker placement
taegyunkim Sep 21, 2026
827dacc
refactor(profiling): simplify task unwind metadata
taegyunkim Sep 21, 2026
468ee51
docs(profiling): clarify task unwind and omission arguments
taegyunkim Sep 22, 2026
0c757a4
refactor(profiling): clarify stack context and isolate collector tests
taegyunkim Sep 22, 2026
5b43c9b
refactor(profiling): use truncation terminology for stack markers
taegyunkim Sep 22, 2026
967fa94
Merge origin/main into taegyunkim/prof-14213-task-stack-frame-budget
taegyunkim Sep 27, 2026
d361c54
Merge remote-tracking branch 'origin/main' into taegyunkim/prof-14213…
taegyunkim Oct 23, 2026
af0606d
Merge remote-tracking branch 'origin/main' into taegyunkim/prof-14213…
taegyunkim Nov 17, 2026
b060c30
fix(profiling): exclude running sibling frames from suspended tasks
taegyunkim Nov 19, 2026
36ef989
fix(profiling): stitch running parent frames after suspended children
taegyunkim Nov 19, 2026
76a2b0e
fix(profiling): omit the uvloop wrapper from running task stacks
taegyunkim Nov 19, 2026
8260d94
fix(profiling): retain the coroutine leaf under tiny frame budgets
taegyunkim Nov 19, 2026
abee11c
Merge branch 'main' into taegyunkim/prof-14213-task-stack-frame-budget
taegyunkim Nov 19, 2026
34adcb1
fix(profiling): handle asyncio boundaries hidden by the frame limit
taegyunkim Nov 19, 2026
99af1ef
Merge remote-tracking branch 'origin/main' into taegyunkim/prof-14213…
taegyunkim Nov 20, 2026
d8870d6
test(profiling): move shared task stack tests to test_asyncio_task_st…
taegyunkim Nov 20, 2026
841084c
Merge branch 'main' into taegyunkim/prof-14213-task-stack-frame-budget
taegyunkim Nov 23, 2026
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 @@ -87,7 +87,7 @@ class EchionSampler
bool asyncio_loop_tracked_ = false;
size_t asyncio_task_count_ = 0;

// Maximum number of frames to collect for plain thread stacks.
// Maximum number of frames to collect for thread and task stacks.
size_t stack_max_frames_ = g_default_max_nframes;

// Maximum number of leaf tasks / greenlets to unwind and emit per cycle.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,15 @@ class FrameStack : public std::vector<Frame>
public:
using Key = Frame::Key;

void render(EchionSampler& echion, TruncationStatus truncation);
// truncation_index is the index into this FrameStack before which to render the truncation marker.
// An index of size() puts the marker after all frames; SIZE_MAX disables it.
// truncated_frames is the number of truncated thread frames represented by the marker; zero emits nothing.
void render(EchionSampler& echion, TruncationStatus truncation, size_t truncation_index, size_t truncated_frames);
};

[[nodiscard]] size_t
rendered_location_count(const Frame& frame);

// Forward declaration
class EchionSampler;

Expand Down Expand Up @@ -95,6 +101,8 @@ class StackInfo
uint64_t task_id;
bool on_cpu;
FrameStack stack;
size_t truncation_index = SIZE_MAX;
size_t truncated_frames = 0;

// Per-task override wall-time to use in reservoir sampling.
// nullopt means "use the thread-level wall time"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,10 @@ class TaskInfo
{
}

size_t unwind(EchionSampler& echion, FrameStack&, bool using_uvloop);
// Append up to max_depth coroutine frames to stack, starting with the innermost coroutine.
// Return the discovered coroutine-frame count, including frames not appended because of the limit.
// Stitching uses this count to distinguish coroutine frames from synchronous frames in the physical stack.
size_t unwind(EchionSampler& echion, FrameStack& stack, bool using_uvloop, size_t max_depth);
};

// Checks whether a Frame is the uvloop.run coroutine wrapper.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <cstdint>
#include <functional>
#include <mutex>
#include <optional>
#include <unordered_map>

#if defined PL_LINUX
Expand Down Expand Up @@ -59,17 +60,15 @@ class ThreadInfo
uintptr_t asyncio_loop = 0;
uintptr_t tstate_addr = 0; // Remote address of PyThreadState for accessing asyncio_tasks_head
bool using_uvloop = false; // Whether this thread is using uvloop instead of asyncio
// Index into python_stack of the event-loop boundary frame.
// Empty if no boundary was found in the collected physical frames.
std::optional<size_t> asyncio_boundary_index;

[[nodiscard]] Result<void> update_cpu_time();

[[nodiscard]] Result<void> sample(EchionSampler&, PyThreadState*, microsecond_t);
[[nodiscard]] Result<void> unwind(EchionSampler&, PyThreadState*, microsecond_t wall_time_us);

// Number of frames in python_stack from the asyncio boundary frame (inclusive) up to the root,
// that is to say the asyncio machinery plus the synchronous entry point. Returns the size of the
// whole stack when the boundary frame is not there.
[[nodiscard]] size_t find_upper_python_stack_size(EchionSampler&) const;

// ------------------------------------------------------------------------
#if defined PL_LINUX
ThreadInfo(uintptr_t thread_id, unsigned long native_id, const char* name, clockid_t cpu_clock_id)
Expand Down Expand Up @@ -127,6 +126,7 @@ class ThreadInfo

void reset_cycle_state() noexcept;
void render_unwound_stacks(EchionSampler&);
bool is_asyncio_boundary_frame(EchionSampler&, const Frame&);
[[nodiscard]] Result<void> unwind_tasks(EchionSampler&, PyThreadState*, microsecond_t wall_time_us);
void unwind_greenlets(EchionSampler&, PyThreadState*, unsigned long, microsecond_t wall_time_us);
[[nodiscard]] Result<std::vector<TaskInfo::Ptr>> get_all_tasks(EchionSampler&, PyThreadState* tstate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
// Point gc_frame at the outermost coroutine frame so the GC-marker path is exercised.
PyObject* gc_frame = (*maybe_task)->coro ? (*maybe_task)->coro->frame : nullptr;
auto gc_frame_scope = echion_sampler.use_gc_frame(gc_frame);
(void)(*maybe_task)->unwind(echion_sampler, stack, using_uvloop);
(void)(*maybe_task)->unwind(echion_sampler, stack, using_uvloop, MAX_STACK_UNWIND_SAFETY_LIMIT);
}

g_data = nullptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class StackRenderer
std::optional<int64_t> walltime_ns_override = std::nullopt);
void render_frame(Frame& frame);
void mark_truncated();
void render_truncated_frames(size_t count);
void render_gc_frame();
void render_cpu_time(microsecond_t cpu_time_us);
void render_native_frame(const std::string& name, const std::string& module);
Expand Down
26 changes: 23 additions & 3 deletions ddtrace/internal/datadog/profiling/stack/src/echion/stacks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,31 @@

#include "dd_wrapper/include/profiler_state.hpp"

size_t
rendered_location_count(const Frame& frame)
{
size_t count = frame.is_in_gc ? 2 : 1;
if (frame.code_object == 0 || frame.lasti < 0) {
return count;
}

auto& registry = Datadog::ProfilerState::get().native_call_registry;
const int offset_bytes = frame.lasti * static_cast<int>(sizeof(_Py_CODEUNIT));
return registry.lookup(frame.code_object, offset_bytes, frame.first_lineno) ? count + 1 : count;
}

void
FrameStack::render(EchionSampler& echion, TruncationStatus truncation)
FrameStack::render(EchionSampler& echion, TruncationStatus truncation, size_t truncation_index, size_t truncated_frames)
{
auto& renderer = echion.renderer();
auto& registry = Datadog::ProfilerState::get().native_call_registry;

for (auto it = this->begin(); it != this->end(); ++it) {
auto& frame = *it;
for (size_t i = 0; i < size(); ++i) {
if (i == truncation_index) {
renderer.render_truncated_frames(truncated_frames);
}

auto& frame = (*this)[i];

// The collection runs underneath everything the frame is doing, including a native call
// such as gc.collect that is still in progress. Locations are leaf-to-root, so the GC
Expand All @@ -36,6 +53,9 @@ FrameStack::render(EchionSampler& echion, TruncationStatus truncation)
renderer.render_frame(frame);
}

if (truncation_index == size()) {
renderer.render_truncated_frames(truncated_frames);
}
if (truncation == TruncationStatus::Truncated) {
renderer.mark_truncated();
}
Expand Down
15 changes: 8 additions & 7 deletions ddtrace/internal/datadog/profiling/stack/src/echion/tasks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ is_uvloop_wrapper_frame(EchionSampler& echion, bool using_uvloop, const Frame& f
}

size_t
TaskInfo::unwind(EchionSampler& echion, FrameStack& stack, bool using_uvloop)
TaskInfo::unwind(EchionSampler& echion, FrameStack& stack, bool using_uvloop, size_t max_depth)
{
// TODO: Check for running task.
(void)echion;
Expand All @@ -250,11 +250,11 @@ TaskInfo::unwind(EchionSampler& echion, FrameStack& stack, bool using_uvloop)
}
}

// Total number of frames added to the Stack
size_t count = 0;
size_t depth = coro_frames.size();
size_t retained = 0;

// Unwind the coro frames
while (!coro_frames.empty()) {
// Unwind only the frames that can contribute to this task's output.
while (!coro_frames.empty() && retained < max_depth) {
PyObject* frame = coro_frames.top();
coro_frames.pop();

Expand All @@ -279,11 +279,12 @@ TaskInfo::unwind(EchionSampler& echion, FrameStack& stack, bool using_uvloop)
// Skip the uvloop wrapper frame if present (only at the outermost level of the top-level Task)
if (!stack.empty() && is_uvloop_wrapper_frame(echion, using_uvloop, stack.back())) {
stack.pop_back();
depth--;
continue;
}

count += 1;
retained++;
}

return count;
return depth;
}
Loading
Loading