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

Add memory usage to contexts #2133

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

Add memory usage to contexts #2133

wants to merge 17 commits into from

Conversation

denrase
Copy link
Collaborator

@denrase denrase commented Jun 25, 2024

📜 Description

Add memory usage to contexts

💡 Motivation and Context

Closes #1826

💚 How did you test it?

Sample app

📝 Checklist

  • I reviewed submitted code
  • I added tests to verify changes
  • No new PII added or SDK only sends newly added PII if sendDefaultPii is enabled
  • I updated the docs if needed
  • All tests passing
  • No breaking changes

Copy link
Contributor

github-actions bot commented Jun 25, 2024

iOS Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1222.17 ms 1248.96 ms 26.79 ms
Size 8.33 MiB 9.62 MiB 1.29 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
cd16818 1254.78 ms 1267.76 ms 12.98 ms
870f5eb 1267.78 ms 1286.86 ms 19.08 ms
fdac48a 1281.92 ms 1300.22 ms 18.31 ms
78eeed5 1259.33 ms 1270.14 ms 10.82 ms
8ced2dc 1258.35 ms 1272.98 ms 14.62 ms
d089990 1206.19 ms 1233.08 ms 26.89 ms
90db9ff 1277.18 ms 1283.69 ms 6.51 ms
e5b744f 1250.82 ms 1284.46 ms 33.64 ms
1596141 1230.77 ms 1241.90 ms 11.13 ms
f2db4ec 1244.14 ms 1259.79 ms 15.65 ms

App size

Revision Plain With Sentry Diff
cd16818 8.28 MiB 9.33 MiB 1.05 MiB
870f5eb 8.15 MiB 9.13 MiB 1000.08 KiB
fdac48a 8.10 MiB 9.08 MiB 1004.37 KiB
78eeed5 8.29 MiB 9.38 MiB 1.09 MiB
8ced2dc 8.10 MiB 9.16 MiB 1.07 MiB
d089990 8.33 MiB 9.40 MiB 1.07 MiB
90db9ff 8.10 MiB 9.08 MiB 1004.27 KiB
e5b744f 8.09 MiB 9.07 MiB 1001.19 KiB
1596141 8.29 MiB 9.37 MiB 1.08 MiB
f2db4ec 8.10 MiB 9.16 MiB 1.07 MiB

Previous results on branch: feat/memory-usage

Startup times

Revision Plain With Sentry Diff
e8d8880 1244.51 ms 1264.81 ms 20.30 ms
cf5df45 1245.84 ms 1262.33 ms 16.50 ms
fcbcade 1234.31 ms 1253.57 ms 19.26 ms
1ab1f7e 1244.94 ms 1263.58 ms 18.65 ms

App size

Revision Plain With Sentry Diff
e8d8880 8.33 MiB 9.63 MiB 1.30 MiB
cf5df45 8.33 MiB 9.63 MiB 1.29 MiB
fcbcade 8.33 MiB 9.63 MiB 1.30 MiB
1ab1f7e 8.33 MiB 9.62 MiB 1.29 MiB

Copy link
Contributor

github-actions bot commented Jun 25, 2024

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against ce54ed1

Copy link

codecov bot commented Jun 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.65%. Comparing base (e4d5aa8) to head (ce54ed1).
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2133      +/-   ##
==========================================
- Coverage   88.41%   87.65%   -0.76%     
==========================================
  Files         224       93     -131     
  Lines        7705     3346    -4359     
==========================================
- Hits         6812     2933    -3879     
+ Misses        893      413     -480     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@denrase denrase marked this pull request as ready for review June 25, 2024 14:33
@buenaflor
Copy link
Contributor

We could use these fields if they make sense.

memory_size
Optional. Total system memory available in bytes.

free_memory
Optional. Free system memory in bytes.

usable_memory
Optional. Memory usable for the app in bytes.

see https://develop.sentry.dev/sdk/event-payloads/contexts/

@buenaflor
Copy link
Contributor

app_memory might also be useful

app_memory
Optional. Amount of memory used by the application in bytes.

depending on the meaning of app_memory both current and max rss could fit here. we'd need more clarification for that

@buenaflor
Copy link
Contributor

buenaflor commented Jun 25, 2024

Okay it's supposed to be the memory at the time of the event so currentRss should fit here

Copy link
Contributor

@buenaflor buenaflor left a comment

Choose a reason for hiding this comment

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

left some comments,

I'm not sure though how we should categorize maxRss

CHANGELOG.md Show resolved Hide resolved
Comment on lines 45 to 46
_bytesToHumanReadableFileSize(ProcessInfo.currentRss),
'maxResidentSetSize': _bytesToHumanReadableFileSize(ProcessInfo.maxRss),
Copy link
Contributor

Choose a reason for hiding this comment

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

are there any alternatives for web?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Found this, but there's not much documentation: https://api.dart.dev/stable/2.18.0/dart-html/MemoryInfo/usedJSHeapSize.html

Copy link
Contributor

Choose a reason for hiding this comment

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

this is based on this https://developer.mozilla.org/en-US/docs/Web/API/Performance/memory

it's deprecated and not all browsers support it, dunno if it's worth the effort to add this if we have to remove it again at some point

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, i removed it after reading the docs and added some info.

@@ -40,6 +40,11 @@ class IoEnricherEventProcessor implements EnricherEventProcessor {
);

contexts['dart_context'] = _getDartContext();
contexts['process_info'] = <String, dynamic>{
'currentResidentSetSize':
Copy link
Contributor

Choose a reason for hiding this comment

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

let's add currentRss to app_memory

Copy link
Collaborator

Choose a reason for hiding this comment

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

How does currentRss compare to what the native side sets? Does it override what the native side sets?

Copy link
Collaborator Author

@denrase denrase Jul 1, 2024

Choose a reason for hiding this comment

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

Updated the code and we only set these values if there are no native SDKs

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think android sets it, I know iOS for sure does @denrase

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated so we set appMemory to ProcessInfo.currentRss, it it's not already set, regardless of native integration. The other values are merged, so this is additional information.

On Linux/Windows we now also add free and total system memory, if possible.

@denrase
Copy link
Collaborator Author

denrase commented Jul 1, 2024

@buenaflor Used the mapping below, as these seemed the most appropriate accodring to the documentation. WDYT?

Used

  • app_memory -> currentRss
    Optional. Amount of memory used by the application in bytes.

  • usable_memory -> maxRss
    Optional. Memory usable for the app in bytes.

Values below are not used, as we can't say anything about the system memory as far as I can see.

  • memory_size
    Optional. Total system memory available in bytes.

  • free_memory
    Optional. Free system memory in bytes.

@denrase
Copy link
Collaborator Author

denrase commented Jul 1, 2024

There's a package to get more system info we could look into: https://pub.dev/packages/system_info2

@denrase
Copy link
Collaborator Author

denrase commented Jul 1, 2024

Here's how it checks for physical memory info on different platforms.

https://github.com/onepub-dev/system_info/blob/8a9bf6b8eb7c86a09b3c3df4bf6d7fa5a6b50732/lib/src/platform/memory.dart#L73

@buenaflor
Copy link
Contributor

usable_memory -> maxRss
Optional. Memory usable for the app in bytes.

hm not sure if this completely fits since maxRss captures the highest amount used thus far

@buenaflor
Copy link
Contributor

There's a package to get more system info we could look into: https://pub.dev/packages/system_info2

can those commands be run in production?

Copy link
Contributor

github-actions bot commented Jul 1, 2024

Android Performance metrics 🚀

  Plain With Sentry Diff
Startup time 416.06 ms 507.80 ms 91.74 ms
Size 6.35 MiB 7.35 MiB 1019.03 KiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
0bed04d 382.15 ms 458.33 ms 76.18 ms
9fe67d5 373.80 ms 444.24 ms 70.45 ms
b49bf00 323.46 ms 375.35 ms 51.89 ms
4b5a4f6 394.19 ms 471.81 ms 77.62 ms
457a85b 312.37 ms 376.67 ms 64.31 ms
98d9a4a 385.48 ms 470.42 ms 84.94 ms
cc80714 333.26 ms 388.80 ms 55.54 ms
6572f8d 302.35 ms 348.10 ms 45.75 ms
66e0270 369.04 ms 431.96 ms 62.92 ms
a609134 350.12 ms 404.12 ms 54.00 ms

App size

Revision Plain With Sentry Diff
0bed04d 6.33 MiB 7.30 MiB 987.71 KiB
9fe67d5 6.33 MiB 7.29 MiB 987.27 KiB
b49bf00 6.06 MiB 7.10 MiB 1.04 MiB
4b5a4f6 6.34 MiB 7.28 MiB 962.57 KiB
457a85b 6.06 MiB 7.09 MiB 1.03 MiB
98d9a4a 6.35 MiB 7.35 MiB 1017.84 KiB
cc80714 6.34 MiB 7.28 MiB 966.31 KiB
6572f8d 6.15 MiB 7.13 MiB 999.97 KiB
66e0270 6.35 MiB 7.35 MiB 1017.84 KiB
a609134 5.94 MiB 6.95 MiB 1.01 MiB

Previous results on branch: feat/memory-usage

Startup times

Revision Plain With Sentry Diff
e8d8880 427.13 ms 496.06 ms 68.93 ms
1ab1f7e 387.86 ms 451.34 ms 63.48 ms
cf5df45 405.76 ms 472.82 ms 67.06 ms
fcbcade 407.13 ms 482.32 ms 75.19 ms

App size

Revision Plain With Sentry Diff
e8d8880 6.35 MiB 7.35 MiB 1.00 MiB
1ab1f7e 6.35 MiB 7.35 MiB 1019.02 KiB
cf5df45 6.35 MiB 7.35 MiB 1018.79 KiB
fcbcade 6.35 MiB 7.35 MiB 1.00 MiB

Copy link
Contributor

@buenaflor buenaflor left a comment

Choose a reason for hiding this comment

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

left some comments, regarding maxRss we can also name it ourselves, not sure if usable_memory is the best fit. wdyt?

CHANGELOG.md Outdated Show resolved Hide resolved
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.

Report used memory/max used memory
3 participants