Skip to content

RUM-13679: Delete Perfetto result file after writing to batch - #3486

Merged
ambushwork merged 2 commits into
feature/continuous-profilingfrom
yl/profiling/rum-13679-perfetto-file-cleanup
Jun 1, 2026
Merged

RUM-13679: Delete Perfetto result file after writing to batch#3486
ambushwork merged 2 commits into
feature/continuous-profilingfrom
yl/profiling/rum-13679-perfetto-file-cleanup

Conversation

@ambushwork

@ambushwork ambushwork commented May 29, 2026

Copy link
Copy Markdown
Member

What does this PR do?

Fixes a disk space leak in the continuous profiling pipeline (RUM-13679).

ProfilingManager writes profile to the app's data directory. Before this change, that file was never deleted.
ProfilingDataWriter now owns the full file lifecycle: read → batch write → delete.

The file deletion will happen in such cases:

  • SDK feature scope is null (SDK not initialised at callback time)
  • File uploaded successfully
  • Profiling session had no RUM events to attach
  • File unreadable (e.g. permissions issue, empty file)

The file will be kept in these cases:

  • Process kill between Android writing the file and the resultCallback firing
  • SDK teardown races the withWriteContext dispatch

Next steps

The orphaned-file problem (process kill, SDK teardown race) requires a complementary retry mechanism later

Additional Notes

Anything else we should know when reviewing?

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)

@datadog-datadog-prod-us1-2

This comment has been minimized.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@ambushwork
ambushwork requested a review from Copilot May 29, 2026 14:46
@ambushwork

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Fixes a disk space leak in the continuous profiling pipeline by moving Perfetto trace file lifecycle management into ProfilingDataWriter (read → write to batch → delete), and adjusting ProfilingFeature behavior/logging so continuous results with no pending RUM events still trigger cleanup.

Changes:

  • ProfilingFeature now always forwards continuous profiling results to the writer (even with empty pending RUM events) and logs “not uploaded” instead of “dropped”.
  • ProfilingDataWriter deletes the Perfetto result file after the write path completes (and when the profiling feature isn’t available).
  • Tests updated/added to assert file deletion and updated behavior/log messages.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
features/dd-sdk-android-profiling/src/main/java/com/datadog/android/profiling/internal/ProfilingFeature.kt Always writes continuous results (enabling cleanup) and adjusts user log messaging.
features/dd-sdk-android-profiling/src/main/java/com/datadog/android/profiling/internal/ProfilingDataWriter.kt Implements file deletion as part of the writer’s lifecycle responsibilities.
features/dd-sdk-android-profiling/src/test/kotlin/com/datadog/android/profiling/ProfilingFeatureTest.kt Updates test expectation: writer invoked even when no pending RUM events; asserts new log message.
features/dd-sdk-android-profiling/src/test/kotlin/com/datadog/android/profiling/internal/ProfilingDataWriterTest.kt Adds assertions for Perfetto file deletion across multiple scenarios.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +41 to +60
feature.withWriteContext { context, writeScope ->
writeScope { writer ->
synchronized(this) {
buildRawBatchEvent(
context = context,
profilingResult = profilingResult,
longTaskEvents = longTasks,
anrEvents = anrEvents,
vitalEvents = vitalEvents
)?.let {
writer.write(
event = it,
batchMetadata = null,
eventType = EventType.DEFAULT
)
}
safeDelete(profilingResult.resultFilePath)
}
}
}

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.

Currently we don't have a retry mechanism for the writing failure, it will be implemented later as described above, in this case, instead of filling up the user's storage, we need to delete the file even though the write fails.

@codecov-commenter

codecov-commenter commented May 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 79.48718% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.40%. Comparing base (389f702) to head (e3a7b9f).
⚠️ Report is 5 commits behind head on feature/continuous-profiling.

Files with missing lines Patch % Lines
.../android/profiling/internal/ProfilingDataWriter.kt 78.12% 7 Missing ⚠️
...dog/android/profiling/internal/ProfilingFeature.kt 85.71% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@                       Coverage Diff                        @@
##           feature/continuous-profiling    #3486      +/-   ##
================================================================
+ Coverage                         72.36%   72.40%   +0.04%     
================================================================
  Files                               979      979              
  Lines                             36242    36258      +16     
  Branches                           6034     6035       +1     
================================================================
+ Hits                              26225    26250      +25     
+ Misses                             8359     8355       -4     
+ Partials                           1658     1653       -5     
Files with missing lines Coverage Δ
...dog/android/profiling/internal/ProfilingFeature.kt 82.86% <85.71%> (+2.14%) ⬆️
.../android/profiling/internal/ProfilingDataWriter.kt 90.30% <78.12%> (-2.92%) ⬇️

... and 37 files with indirect coverage changes

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

@ambushwork
ambushwork marked this pull request as ready for review June 1, 2026 06:14
@ambushwork
ambushwork requested review from a team as code owners June 1, 2026 06:14

@hamorillo hamorillo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚀

@ambushwork
ambushwork merged commit b041cff into feature/continuous-profiling Jun 1, 2026
28 checks passed
@ambushwork
ambushwork deleted the yl/profiling/rum-13679-perfetto-file-cleanup branch June 1, 2026 09:04
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.

5 participants