Skip to content
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

chore(asm): add a ctypes based ddprof module #11157

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

juanjux
Copy link
Collaborator

@juanjux juanjux commented Oct 24, 2024

Add a small and private ctypes-based _ddprof module and a script to download the .so binary (including it is not an option since it's 17mb) to ease using ddprof start and stop functions to profile specific parts of the tracer.

Signed-off-by: Juanjo Alvarez [email protected]## 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

Signed-off-by: Juanjo Alvarez <[email protected]>
Signed-off-by: Juanjo Alvarez <[email protected]>
@juanjux juanjux added changelog/no-changelog A changelog entry is not required for this PR. ASM Application Security Monitoring labels Oct 24, 2024
@juanjux juanjux self-assigned this Oct 24, 2024
@juanjux juanjux requested review from a team as code owners October 24, 2024 16:24
Copy link
Contributor

github-actions bot commented Oct 24, 2024

CODEOWNERS have been resolved as:

ddtrace/appsec/_ddprof.py                                               @DataDog/asm-python
ddtrace/appsec/ddprof_lib/download_ddprof.sh                            @DataDog/asm-python
hatch.toml                                                              @DataDog/python-guild

Copy link
Contributor

CODEOWNERS have been resolved as:

ddtrace/appsec/ddprof.py                                                @DataDog/asm-python
.gitignore                                                              @DataDog/apm-core-python
ddtrace/appsec/_iast/_taint_tracking/__init__.py                        @DataDog/asm-python

Copy link
Member

@gnufede gnufede left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, maybe you can add some example script that calls start_profiling and stop_profiling to showcase the usage

@pr-commenter
Copy link

pr-commenter bot commented Oct 24, 2024

Benchmarks

Benchmark execution time: 2024-10-25 15:00:48

Comparing candidate commit 2480b57 in PR branch juanjux/ddprof-python-module with baseline commit d3485f2 in branch main.

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

scenario:iast_aspects-format_map_aspect

  • 🟩 execution_time [-525.919ns; -463.170ns] or [-9.195%; -8.098%]

scenario:iast_aspects-ospathbasename_aspect

  • 🟩 execution_time [-492.665ns; -440.462ns] or [-13.176%; -11.780%]

scenario:iast_aspects-ospathdirname_aspect

  • 🟩 execution_time [-725.191ns; -659.693ns] or [-16.549%; -15.054%]

scenario:iast_aspects-ospathsplit_aspect

  • 🟩 execution_time [-368.071ns; -305.914ns] or [-8.705%; -7.235%]

scenario:iast_aspects-split_aspect

  • 🟩 execution_time [-219.355ns; -198.714ns] or [-11.722%; -10.619%]

@taegyunkim
Copy link
Contributor

taegyunkim commented Oct 24, 2024

Should it be used as the following?

from ddtrace.appsec._ddprof import ddprof

ddprof.ddprof_start_profiling()
# run something interesting to be profiled here
# probably using native extensions
ddprof.ddprof_stop_profiling()

@juanjux
Copy link
Collaborator Author

juanjux commented Oct 25, 2024

Should it be used as the following?

from ddtrace.appsec._ddprof import ddprof

ddprof.ddprof_start_profiling()
# run something interesting to be profiled here
# probably using native extensions
ddprof.ddprof_stop_profiling()

That's right (stop profiling has a parameter for the timeout to wait in milliseconds). There is not much complication on it.

@juanjux juanjux requested a review from a team as a code owner October 25, 2024 09:56
@datadog-dd-trace-py-rkomorn
Copy link

datadog-dd-trace-py-rkomorn bot commented Oct 25, 2024

Datadog Report

Branch report: juanjux/ddprof-python-module
Commit report: 2480b57
Test service: dd-trace-py

✅ 0 Failed, 1286 Passed, 0 Skipped, 29m 44.22s Total duration (7m 55.54s time saved)

Signed-off-by: Juanjo Alvarez <[email protected]>
Copy link
Contributor

@sanchda sanchda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is exactly why we build libdd_profiling.so and it's really exciting to see it used!

Signed-off-by: Juanjo Alvarez <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ASM Application Security Monitoring changelog/no-changelog A changelog entry is not required for this PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants