Skip to content

Address concurrency and app start detection issues in Profiling#3117

Merged
0xnm merged 1 commit into
feature/perfetto-profilingfrom
nogorodnikov/fix-concurrency-and-app-start-for-profiling
Jan 8, 2026
Merged

Address concurrency and app start detection issues in Profiling#3117
0xnm merged 1 commit into
feature/perfetto-profilingfrom
nogorodnikov/fix-concurrency-and-app-start-for-profiling

Conversation

@0xnm

@0xnm 0xnm commented Jan 8, 2026

Copy link
Copy Markdown
Member

What does this PR do?

This PR does the following:

  • Fixes some threading/concurrency issues due to the properties accessed from different threads: profiler callback thread vs SDK thread
  • Fixes app start detection logic: we were checking if any historical reason is from the launcher, we need to check only the current (most recent one).

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Make sure you discussed the feature or bugfix with the maintaining team in an Issue
  • Make sure each commit and the PR mention the Issue number (cf the CONTRIBUTING doc)

@0xnm
0xnm force-pushed the nogorodnikov/fix-concurrency-and-app-start-for-profiling branch 2 times, most recently from fbee0fc to 978b12f Compare January 8, 2026 11:33
@0xnm
0xnm force-pushed the nogorodnikov/fix-concurrency-and-app-start-for-profiling branch from 978b12f to 2f753fd Compare January 8, 2026 12:46
@0xnm
0xnm marked this pull request as ready for review January 8, 2026 13:10
@0xnm
0xnm requested a review from a team as a code owner January 8, 2026 13:10
@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Jan 8, 2026

Copy link
Copy Markdown

🎯 Code Coverage
Patch Coverage: 65.52%
Overall Coverage: 66.58% (+0.02%)

View detailed report

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 2f753fd | Docs | Datadog PR Page | Was this helpful? Give us feedback!

val endTime = timeProvider.getDeviceTimestampMillis()
val duration = endTime - profilingStartTime
if (result.errorCode == ProfilingResult.ERROR_NONE) {
// TODO RUM-13679: need to delete the file after it is no longer needed

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ProfilingManager stores the result as a temp file and it will be cleaned up automatically, I don't think we need to handle it by us.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

it will be cleaned up automatically

do you know the cleanup logic? because we store the path to the file, so is there any risk that by the time we try to read from this path file is not there already?

the location given is not in the cache folder

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't know how it is cleaned under the hood exactly, but I guess we will probably not hit the this risk since from the callback to writing batch, it has very small delay (although we switch the thread).

I think we can add a telemetry to monitor if we can actually hit the case where we fail the read the result with the this path.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

From my runs I see that profiling results are stored on the device like forever. Maybe they are cleaned up though once /data/data/<app>/files/profiling folder hits certain size.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Google claims that to keep the results forever we need to enable a flag through adb, let's confirm with them about this.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 69.23077% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.54%. Comparing base (9158eb9) to head (2f753fd).

Files with missing lines Patch % Lines
...dog/android/profiling/internal/ProfilingFeature.kt 25.00% 6 Missing ⚠️
...og/android/profiling/DdProfilingContentProvider.kt 0.00% 2 Missing ⚠️
Additional details and impacted files
@@                      Coverage Diff                       @@
##           feature/perfetto-profiling    #3117      +/-   ##
==============================================================
+ Coverage                       71.43%   71.54%   +0.11%     
==============================================================
  Files                             894      894              
  Lines                           32821    32838      +17     
  Branches                         5512     5516       +4     
==============================================================
+ Hits                            23444    23491      +47     
+ Misses                           7811     7791      -20     
+ Partials                         1566     1556      -10     
Files with missing lines Coverage Δ
...roid/profiling/internal/ProfilingRequestFactory.kt 100.00% <100.00%> (+16.28%) ⬆️
...dog/android/profiling/internal/ProfilingStorage.kt 100.00% <100.00%> (+5.88%) ⬆️
...id/profiling/internal/perfetto/PerfettoProfiler.kt 95.16% <ø> (+1.51%) ⬆️
...og/android/profiling/DdProfilingContentProvider.kt 0.00% <0.00%> (ø)
...dog/android/profiling/internal/ProfilingFeature.kt 62.50% <25.00%> (-7.07%) ⬇️

... and 43 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@0xnm
0xnm merged commit 4b65d7d into feature/perfetto-profiling Jan 8, 2026
26 checks passed
@0xnm
0xnm deleted the nogorodnikov/fix-concurrency-and-app-start-for-profiling branch January 8, 2026 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants