Skip to content

fix: Normalize profiling cpu usage to percent#7798

Closed
denrase wants to merge 5 commits intomainfrom
fix/cpu-usage-calc
Closed

fix: Normalize profiling cpu usage to percent#7798
denrase wants to merge 5 commits intomainfrom
fix/cpu-usage-calc

Conversation

@denrase
Copy link
Copy Markdown
Collaborator

@denrase denrase commented Apr 13, 2026

📜 Description

Fix SentrySystemWrapper CPU usage calculation by dividing Mach thread cpu_usage by TH_USAGE_SCALE, then normalizing by processor count and converting to 0..100 percent. Updates docs and adds test for the normalization logic.

💡 Motivation and Context

Closes #7456

💚 How did you test it?

Unit Tests

📝 Checklist

You have to check all boxes before merging:

  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

Fix SentrySystemWrapper CPU usage calculation by dividing Mach thread cpu_usage by TH_USAGE_SCALE, then normalizing by processor count and converting to 0..100 percent. Updates docs and adds test for the normalization logic.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 13, 2026

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

  • Track low power mode in device context by itaybre in #7777

Bug Fixes 🐛

  • (breadcrumbs) Unsubscribe to system event during background to avoid reporting breadcrumbs with wrong timestamps on return to foreground by denrase in #7803
  • (replay) Keep replayType as buffer for Session Replay triggered by an error by romtsn in #7804
  • Normalize profiling cpu usage to percent by denrase in #7798
  • Copy mutable collections before passing to scope observers by antonis in #7807
  • Detect development builds via provisioning profile entitlement by denrase in #7702

Internal Changes 🔧

Deps

  • Bump getsentry/craft/.github/workflows/changelog-preview.yml from 2.25.2 to 2.25.4 by dependabot in #7811
  • Bump actions/create-github-app-token from 3.0.0 to 3.1.1 by dependabot in #7812
  • Bump ruby/setup-ruby from 1.299.0 to 1.302.0 by dependabot in #7813
  • Bump peter-evans/create-pull-request from 8.1.0 to 8.1.1 by dependabot in #7791
  • Bump actions/upload-artifact from 7.0.0 to 7.0.1 by dependabot in #7790
  • Bump actions/upload-pages-artifact from 4.0.0 to 5.0.0 by dependabot in #7789
  • Bump actions/github-script from 8.0.0 to 9.0.0 by dependabot in #7793

🤖 This preview updates automatically when you update the PR.

@denrase denrase marked this pull request as ready for review April 13, 2026 11:36
Comment thread Sources/Sentry/include/SentrySystemWrapper.h
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.433%. Comparing base (77a335b) to head (c351c02).
⚠️ Report is 16 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##              main     #7798       +/-   ##
=============================================
- Coverage   85.434%   85.433%   -0.002%     
=============================================
  Files          487       487               
  Lines        29261     29265        +4     
  Branches     12671     12658       -13     
=============================================
+ Hits         24999     25002        +3     
- Misses        4212      4214        +2     
+ Partials        50        49        -1     
Files with missing lines Coverage Δ
Sources/Sentry/SentrySystemWrapper.mm 67.532% <100.000%> (+1.779%) ⬆️

... and 3 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 77a335b...c351c02. Read the comment docs.

@denrase denrase added the ready-to-merge Use this label to trigger all PR workflows label Apr 14, 2026
@sentry
Copy link
Copy Markdown

sentry Bot commented Apr 14, 2026

📲 Install Builds

iOS

🔗 App Name App ID Version Configuration
SDK-Size io.sentry.sample.SDK-Size 9.10.0 (1) Release

⚙️ sentry-cocoa Build Distribution Settings

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 14, 2026

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1219.47 ms 1256.38 ms 36.91 ms
Size 24.14 KiB 1.13 MiB 1.11 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
0e4b033 1203.74 ms 1249.71 ms 45.97 ms
bbee1ba 1197.79 ms 1215.42 ms 17.63 ms
59981b9 1207.25 ms 1240.71 ms 33.46 ms
64a365a 1225.60 ms 1255.49 ms 29.89 ms
93d7fdf 1225.77 ms 1259.79 ms 34.02 ms
e03f459 1222.56 ms 1255.94 ms 33.37 ms
ffac605 1217.10 ms 1256.91 ms 39.81 ms
2f4ddaa 1227.26 ms 1260.04 ms 32.78 ms
778dadf 1207.69 ms 1246.09 ms 38.40 ms
daf8b80 1233.78 ms 1259.44 ms 25.66 ms

App size

Revision Plain With Sentry Diff
0e4b033 24.14 KiB 1.11 MiB 1.09 MiB
bbee1ba 24.14 KiB 1.11 MiB 1.09 MiB
59981b9 24.14 KiB 1.09 MiB 1.06 MiB
64a365a 24.14 KiB 1.09 MiB 1.06 MiB
93d7fdf 24.14 KiB 1.11 MiB 1.08 MiB
e03f459 24.14 KiB 1.11 MiB 1.09 MiB
ffac605 24.14 KiB 1.13 MiB 1.10 MiB
2f4ddaa 24.14 KiB 1.04 MiB 1.02 MiB
778dadf 24.14 KiB 1.04 MiB 1.02 MiB
daf8b80 24.14 KiB 1.11 MiB 1.09 MiB

Previous results on branch: fix/cpu-usage-calc

Startup times

Revision Plain With Sentry Diff
cd46f3c 1212.11 ms 1250.90 ms 38.79 ms

App size

Revision Plain With Sentry Diff
cd46f3c 24.14 KiB 1.13 MiB 1.11 MiB

Copy link
Copy Markdown
Member

@philprime philprime left a comment

Choose a reason for hiding this comment

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

LGTM but I have one concern: Isn't this technically speaking a breaking change because the reported data and any related dashboards will report completely different numbers from now on?

Copy link
Copy Markdown
Contributor

@itaybre itaybre left a comment

Choose a reason for hiding this comment

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

@philprime concern seems valid, at this time we might not be able to update this untils a new major

Comment thread CHANGELOG.md Outdated
@denrase
Copy link
Copy Markdown
Collaborator Author

denrase commented Apr 21, 2026

@philprime @itaybre Should we consider it a breaking change when it was incorrect before?

@itaybre
Copy link
Copy Markdown
Contributor

itaybre commented Apr 21, 2026

@philprime @itaybre Should we consider it a breaking change when it was incorrect before?

If a user created a dashboard based on this, it would change behavior. So even if it was incorrect before, it is a breaking change (the dashboard wouldn't work with old and new data)

@philprime
Copy link
Copy Markdown
Member

@denrase after a discussion in the Team Apple SDK sync we believe that even though this is is a bug fix, it's a breaking change to any queries or dashboards built around this invalid value. Therefore we must postpone this to the next major release of v10, which is not going to happen until fall 2026

We have two options:

  1. introduce a V10 conditional compilation flag as we did back for v9, so that this change lives in the codebase, but is not included by customers
  2. close the PR, leaving the issue open, and keeping the change around until we get to do it.

I believe option 2 is easier to do right now, as a conditional compilation flag would also require us to extend CI to make sure the SDK is still functional for v10 too.

@denrase
Copy link
Copy Markdown
Collaborator Author

denrase commented Apr 27, 2026

@philprime Sounds good to me, thank you! Closing for now and will re-visit once we have v10 out.

@denrase denrase closed this Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-merge Use this label to trigger all PR workflows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: divide cpu_usage by TH_USAGE_SCALE in SentrySystemWrapper.cpuUsage()

3 participants