-
-
Notifications
You must be signed in to change notification settings - Fork 258
Add memory usage to contexts #2133
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
Changes from 4 commits
cf5df45
eeb797f
7c05a02
d3302e8
b210da5
37ea59c
d10dbbe
6088536
89657ee
ba8a048
e8d8880
fcbcade
eae3175
e2d07f0
1ab1f7e
f880f63
ce54ed1
3a2ce0a
c1d87f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,11 @@ | |
); | ||
|
||
contexts['dart_context'] = _getDartContext(); | ||
contexts['process_info'] = <String, dynamic>{ | ||
'currentResidentSetSize': | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's add currentRss to app_memory There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How does There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated so we set On Linux/Windows we now also add free and total system memory, if possible. |
||
_bytesToHumanReadableFileSize(ProcessInfo.currentRss), | ||
'maxResidentSetSize': _bytesToHumanReadableFileSize(ProcessInfo.maxRss), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are there any alternatives for web? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, i removed it after reading the docs and added some info. |
||
}; | ||
|
||
return event.copyWith( | ||
contexts: contexts, | ||
|
@@ -116,4 +121,34 @@ | |
timezone: culture?.timezone ?? DateTime.now().timeZoneName, | ||
); | ||
} | ||
|
||
// Reference: | ||
// https://github.com/erdbeerschnitzel/filesize.dart/blob/4f7c54dc06647b8368078f6febb83149494698c1/lib/filesize.dart | ||
String _bytesToHumanReadableFileSize(num size) { | ||
const List<String> affixes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB']; | ||
|
||
int round = 2; | ||
num divider = 1024; | ||
|
||
num runningDivider = divider; | ||
num runningPreviousDivider = 0; | ||
int affix = 0; | ||
|
||
while (size >= runningDivider && affix < affixes.length - 1) { | ||
runningPreviousDivider = runningDivider; | ||
runningDivider *= divider; | ||
affix++; | ||
} | ||
|
||
String result = | ||
(runningPreviousDivider == 0 ? size : size / runningPreviousDivider) | ||
.toStringAsFixed(round); | ||
|
||
// Remove trailing zeros if needed | ||
if (result.endsWith("0" * round)) { | ||
result = result.substring(0, result.length - round - 1); | ||
} | ||
|
||
return "$result ${affixes[affix]}"; | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.