-
Notifications
You must be signed in to change notification settings - Fork 0
Integrate dd-win-prof profiling feature into dd-sdk-cpp #185
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
Open
r1viollet
wants to merge
9
commits into
main
Choose a base branch
from
r1viollet/profiling-integration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a08b5ed
Integrate dd-win-prof profiling feature into dd-sdk-cpp
r1viollet 1677e63
Simplify RUM x Profiling setup
r1viollet 18a7494
RUM x Profiling: add an example
r1viollet c5f59c0
RUM x Profiling: profiling integration
r1viollet 9517679
Add a staging endpoint
r1viollet a764ac8
Avoid redundant calls and allocations in RUM→profiling bridge
r1viollet 327faa3
RUM x Profiling: Handle end of sessions
r1viollet fd53e04
Merge branch 'main' of github.com:DataDog/dd-sdk-cpp into r1viollet/p…
r1viollet 23f5263
RUM x Profiling: minor adjustments
r1viollet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,3 +11,4 @@ Testing/ | |
| .crashes/ | ||
| __pycache__/ | ||
| *.pyc | ||
| .env | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| include(FetchContent) | ||
|
|
||
| # Allow overriding the GitHub fetch with a local clone of dd-win-prof. When | ||
| # set, CMake skips the network fetch and uses the local source directory | ||
| # directly. | ||
| set(DD_WIN_PROF_SOURCE_DIR "" CACHE PATH | ||
| "Local path to dd-win-prof source tree (overrides GitHub fetch)") | ||
|
|
||
| if(DD_WIN_PROF_SOURCE_DIR) | ||
| FetchContent_Declare( | ||
| dd-win-prof | ||
| SOURCE_DIR "${DD_WIN_PROF_SOURCE_DIR}" | ||
| ) | ||
| else() | ||
| # TODO: Pin to a released tag once the split RUM context API is merged. | ||
| # For now, this points to a specific commit on main. | ||
| FetchContent_Declare( | ||
| dd-win-prof | ||
| GIT_REPOSITORY https://github.com/DataDog/dd-win-prof.git | ||
| GIT_TAG 75f644a | ||
| ) | ||
| endif() | ||
|
|
||
| FetchContent_MakeAvailable(dd-win-prof) | ||
|
|
||
| # Link dd-win-prof into the SDK as a public dependency so that consumers can | ||
| # include dd-win-prof.h directly if needed. | ||
| target_link_libraries(dd_native PUBLIC dd-win-prof) | ||
|
|
||
| if(DD_BUILD_INSTALL) | ||
| # Install dd-win-prof.dll to bin/ so it ships alongside the SDK. Include it in | ||
| # the DatadogTargets export set since dd_native depends on it. | ||
| install(TARGETS dd-win-prof | ||
| EXPORT DatadogTargets | ||
| RUNTIME DESTINATION bin | ||
| ) | ||
|
|
||
| # Install datadog_profiling_ffi.dll, which dd-win-prof.dll loads at runtime. | ||
| install(FILES "$<TARGET_FILE:libdatadog_dynamic>" DESTINATION bin) | ||
| endif() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # Profiling + RUM integration smoke test | ||
| # Only built when DD_ENABLE_PROFILER is ON (requires dd-win-prof). | ||
|
|
||
| add_executable(dd_profiling_test | ||
| main.cpp | ||
| ) | ||
| target_compile_definitions(dd_profiling_test PRIVATE _CRT_SECURE_NO_WARNINGS) | ||
| target_enable_strict_warnings(dd_profiling_test) | ||
| target_enable_coverage(dd_profiling_test) | ||
| target_enable_sanitizers(dd_profiling_test) | ||
| datadog_enable(dd_profiling_test) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| # profiling-test | ||
|
|
||
| Minimal smoke test that exercises the dd-sdk-cpp **Profiling + RUM** integration end-to-end. | ||
|
|
||
| ## What it does | ||
|
|
||
| 1. Creates a `datadog::Core` (service=`profiling-test`, env=`dev`, staging endpoint) | ||
| 2. Registers **Profiling** (agentless, symbolize=true) and **RUM** | ||
| 3. Calls `core->Start()` which auto-wires RUM context into the profiler | ||
| 4. Simulates 3 view transitions with ~5s of CPU busy-loop each: | ||
| - `HomePage` -> `SettingsPage` -> `ProfilePage` | ||
| 5. Calls `core->Stop()` and prints a summary | ||
|
|
||
| Total runtime: ~15s. The profiler should collect CPU/wall-time samples tagged with the active RUM view. | ||
|
|
||
| ## Environment variables | ||
|
|
||
| | Variable | Read by | Description | | ||
| |---|---|---| | ||
| | `DD_CLIENT_TOKEN` | Code | Client token (used by Core for RUM) | | ||
| | `DD_RUM_APPLICATION_ID` | Code | RUM application ID | | ||
| | `DD_API_KEY` | Profiler (env) | Datadog API key for profile upload | | ||
| | `DD_SITE` | Profiler (env) | Datadog site, e.g. `datad0g.com` (staging) or `datadoghq.com` (prod) | | ||
|
|
||
| Create a `.env` file in this directory (git-ignored): | ||
|
|
||
| ``` | ||
| DD_CLIENT_TOKEN=your-client-token-here | ||
| DD_RUM_APPLICATION_ID=your-rum-app-id-here | ||
| DD_API_KEY=your-api-key-here | ||
| DD_SITE=datad0g.com | ||
| ``` | ||
|
|
||
| Then source it before running: | ||
|
|
||
| ```powershell | ||
| # Load env vars from .env | ||
| . .\load-env.ps1 | ||
|
|
||
| # Or specify a custom path | ||
| . .\load-env.ps1 -Path C:\path\to\.env | ||
| ``` | ||
|
|
||
| ## Build | ||
|
|
||
| From the `dd-sdk-cpp` root: | ||
|
|
||
| ```powershell | ||
| cmake -B build -G "Visual Studio 17 2022" -A x64 ` | ||
| -DDD_ENABLE_PROFILER=ON ` | ||
| -DDD_BUILD_EXAMPLES=ON ` | ||
| -DDD_HTTP_USE_SYSTEM_LIBCURL=OFF ` | ||
| -DDD_WIN_PROF_SOURCE_DIR="$PWD\..\dd-win-prof" | ||
|
|
||
| cmake --build build --config Release --target dd_profiling_test | ||
| ``` | ||
|
|
||
| ## Run | ||
|
|
||
| ```powershell | ||
| .\build\examples\profiling-test\Release\dd_profiling_test.exe | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| # Load environment variables from a .env file. | ||
| # Usage: | ||
| # . .\load-env.ps1 # loads .env from current directory | ||
| # . .\load-env.ps1 -Path C:\path\to\.env | ||
|
|
||
| param( | ||
| [string]$Path = (Join-Path $PSScriptRoot ".env") | ||
| ) | ||
|
|
||
| if (-not (Test-Path $Path)) { | ||
| Write-Error "File not found: $Path" | ||
| return | ||
| } | ||
|
|
||
| $count = 0 | ||
| Get-Content $Path | ForEach-Object { | ||
| $line = $_.Trim() | ||
| # Skip empty lines and comments | ||
| if ($line -eq "" -or $line.StartsWith("#")) { return } | ||
|
|
||
| $eq = $line.IndexOf("=") | ||
| if ($eq -lt 1) { return } | ||
|
|
||
| $name = $line.Substring(0, $eq).Trim() | ||
| $value = $line.Substring($eq + 1).Trim() | ||
| # Strip surrounding quotes if present | ||
| if (($value.StartsWith('"') -and $value.EndsWith('"')) -or | ||
| ($value.StartsWith("'") -and $value.EndsWith("'"))) { | ||
| $value = $value.Substring(1, $value.Length - 2) | ||
| } | ||
|
|
||
| [System.Environment]::SetEnvironmentVariable($name, $value, "Process") | ||
| Write-Host " $name = $($value.Substring(0, [Math]::Min(8, $value.Length)))..." | ||
| $count++ | ||
| } | ||
|
|
||
| Write-Host "Loaded $count variable(s) from $Path" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for now we have some redundant config