Skip to content

fix(profiling): increase default max frames for stack profiler to 512 #13323

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

taegyunkim
Copy link
Contributor

@taegyunkim taegyunkim commented May 2, 2025

Background
max_frames (DD_PROFILING_MAX_FRAMES) is used to control how many frames we sample/export and show to the user. stack profiler, memory profiler, and lock profiler uses the same max_frames even though they have different performance characteristics with regards to increasing that number. We believe stack_v2 sampler is performant enough as it by default unwinds 2048 frames, set in here. But still, we only export DD_PROFILING_MAX_FRAMES number of frames to the backend.

One thing we can do is simply hardcoding up to 512 (the maximum number of frames that can be handled by the backend) frames in sample_manager.cpp as below

void
Datadog::SampleManager::set_max_nframes(unsigned int)
{
    max_nframes = g_backend_max_nframes;
}

Instead of current implementation here

Then, we don't need to plumb max_frames to ddup.config() and that for stack profiler DD_PROFILING_MAX_FRAMES would be relevant only for the legacy stack profiler, lock profiler and memory profiler.

Checklist

  • PR author has checked that all the criteria below are met
  • The PR description includes an overview of the change
  • The PR description articulates the motivation for the change
  • The change includes tests OR the PR description describes a testing strategy
  • The PR description notes risks associated with the change, if any
  • Newly-added code is easy to change
  • The change follows the library release note guidelines
  • The change includes or references documentation updates if necessary
  • Backport labels are set (if applicable)

Reviewer Checklist

  • Reviewer has checked that all the criteria below are met
  • Title is accurate
  • All changes are related to the pull request's stated goal
  • Avoids breaking API changes
  • Testing strategy adequately addresses listed risks
  • Newly-added code is easy to change
  • Release note makes sense to a user of the library
  • If necessary, author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment
  • Backport labels are set in a manner that is consistent with the release branch maintenance policy

Copy link
Contributor

github-actions bot commented May 2, 2025

CODEOWNERS have been resolved as:

releasenotes/notes/prof-max-frames-916cf15f8006e4ff.yaml                @DataDog/apm-python
ddtrace/internal/datadog/profiling/dd_wrapper/include/constants.hpp     @DataDog/profiling-python
ddtrace/internal/datadog/profiling/stack_v2/include/sampler.hpp         @DataDog/profiling-python
ddtrace/internal/datadog/profiling/stack_v2/src/sampler.cpp             @DataDog/profiling-python
ddtrace/internal/datadog/profiling/stack_v2/src/stack_v2.cpp            @DataDog/profiling-python
ddtrace/profiling/collector/stack.pyx                                   @DataDog/profiling-python
ddtrace/profiling/profiler.py                                           @DataDog/profiling-python
ddtrace/settings/profiling.py                                           @DataDog/profiling-python
tests/internal/crashtracker/test_crashtracker.py                        @DataDog/apm-core-python
tests/telemetry/test_writer.py                                          @DataDog/apm-python

Copy link
Contributor

github-actions bot commented May 2, 2025

Bootstrap import analysis

Comparison of import times between this PR and base.

Summary

The average import time from this PR is: 272 ± 3 ms.

The average import time from base is: 278 ± 4 ms.

The import time difference between this PR and base is: -6.6 ± 0.1 ms.

Import time breakdown

The following import paths have shrunk:

ddtrace.auto 3.300 ms (1.21%)
ddtrace.bootstrap.sitecustomize 2.218 ms (0.82%)
ddtrace.bootstrap.preload 1.904 ms (0.70%)
ddtrace.internal.remoteconfig.client 0.739 ms (0.27%)
multiprocessing.sharedctypes 0.084 ms (0.03%)
multiprocessing.heap 0.084 ms (0.03%)
mmap 0.084 ms (0.03%)
ddtrace.internal.products 0.081 ms (0.03%)
importlib.metadata 0.081 ms (0.03%)
importlib.abc 0.081 ms (0.03%)
importlib.resources 0.081 ms (0.03%)
ddtrace.settings.crashtracker 0.044 ms (0.02%)
ddtrace.internal.datadog.profiling.crashtracker 0.044 ms (0.02%)
ddtrace.internal.datadog.profiling.crashtracker._crashtracker 0.044 ms (0.02%)
ddtrace.settings.profiling 0.024 ms (0.01%)
ddtrace.internal.datadog.profiling.ddup 0.024 ms (0.01%)
ddtrace.internal.datadog.profiling.ddup._ddup 0.024 ms (0.01%)
ddtrace._trace.trace_handlers 0.146 ms (0.05%)
ddtrace._trace._inferred_proxy 0.094 ms (0.03%)
ddtrace.propagation.http 0.094 ms (0.03%)
ddtrace.internal._tagset 0.033 ms (0.01%)
ddtrace.appsec._common_module_patches 0.019 ms (0.01%)
ddtrace.appsec._metrics 0.019 ms (0.01%)
ddtrace 1.082 ms (0.40%)
ddtrace._logger 0.128 ms (0.05%)
ddtrace.internal.telemetry 0.128 ms (0.05%)
ddtrace.internal.telemetry.writer 0.085 ms (0.03%)
http.client 0.085 ms (0.03%)
email.parser 0.085 ms (0.03%)
email.feedparser 0.085 ms (0.03%)
email._policybase 0.085 ms (0.03%)
email.utils 0.085 ms (0.03%)
datetime 0.085 ms (0.03%)
_datetime 0.085 ms (0.03%)
ddtrace.settings._agent 0.043 ms (0.02%)
socket 0.043 ms (0.02%)
ddtrace.settings._config 0.115 ms (0.04%)
ddtrace.internal._file_queue 0.115 ms (0.04%)
secrets 0.115 ms (0.04%)
hmac 0.115 ms (0.04%)
_hashlib 0.115 ms (0.04%)
ddtrace.internal._unpatched 0.100 ms (0.04%)
subprocess 0.075 ms (0.03%)
selectors 0.075 ms (0.03%)
ddtrace.trace 0.044 ms (0.02%)
ddtrace._monkey 0.036 ms (0.01%)
ddtrace.appsec._listeners 0.036 ms (0.01%)
ddtrace.internal.core 0.036 ms (0.01%)
ddtrace.internal.core.event_hub 0.036 ms (0.01%)

@pr-commenter
Copy link

pr-commenter bot commented May 2, 2025

Benchmarks

Benchmark execution time: 2025-06-06 16:17:22

Comparing candidate commit 57b104d in PR branch taegyunkim/prof-11752-max-frames with baseline commit 995e706 in branch main.

Found 0 performance improvements and 5 performance regressions! Performance is the same for 494 metrics, 3 unstable metrics.

scenario:iastaspects-lower_aspect

  • 🟥 execution_time [+205.037ns; +252.752ns] or [+9.046%; +11.151%]

scenario:iastaspects-replace_aspect

  • 🟥 execution_time [+574.819ns; +634.836ns] or [+12.213%; +13.489%]

scenario:iastaspects-upper_aspect

  • 🟥 execution_time [+206.966ns; +246.769ns] or [+9.088%; +10.836%]

scenario:iastaspectsospath-ospathjoin_aspect

  • 🟥 execution_time [+722.152ns; +922.890ns] or [+11.751%; +15.017%]

scenario:iastaspectsospath-ospathnormcase_aspect

  • 🟥 execution_time [+419.559ns; +483.114ns] or [+12.188%; +14.034%]

@taegyunkim taegyunkim added the Profiling Continous Profling label May 13, 2025
@brettlangdon
Copy link
Member

@taegyunkim is this ready for review?

@taegyunkim taegyunkim changed the title fix(profiling): increase default max frames for stack profiler to 256 fix(profiling): increase default max frames for stack profiler to 512 Jun 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Profiling Continous Profling
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants