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

[PLAT-8706] Capture app memory stats #1435

Merged
merged 1 commit into from
Jul 15, 2022
Merged

Conversation

nickdowell
Copy link
Contributor

@nickdowell nickdowell commented Jul 14, 2022

Goal

Capture richer information to help developers understand the app's memory usage at the time a crash or other error occurrs.

Design

Adds freeMemory, memoryLimit and memoryUsage to metaData.app for all kinds of errors.

Makes device.freeMemory always report the number of free bytes available on the device, as it was prior to #851 (release v6.2.3), and includes it in OOM errors.

Changeset

Polls task_info instead of os_proc_available_memory so that we have the footprint as well as available bytes, allowing the memory limit to be computed.

Moves all "live" memory stats to BSGRunContext and updates crash report writing and error payload generation to read from bsg_runContext.

Polls host_statistics to have reasonably accurate device.freeMemory values in OOM errors.

Testing

Adds basic unit tests to verify memory stats are as expected.

Amends E2E scenarios to verify the presence of memory stats.

Performance

Since task_info and host_statistics are more expensive than os_proc_available_memory some benchmarking was performed with an iPhone SE (2020).

The average measured execution times were:.

  • 0.739 µs for task_info + host_statistics.
  • 0.159 µs for os_proc_available_memory.

With the default polling rate (2 Hz) CPU usage was not measurable by Xcode or Instruments, including on older hardware such as an iPad 3rd generation.

To understand the relative impact of this change, measurements were taken with an increased polling rate of 1000 Hz:

  • 10% CPU usage when using task_info + host_statistics.
  • 8% CPU usage when using os_proc_available_memory.
  • 7% CPU usage when no memory stats are polled (i.e. overhead of dispatch_timer + updating timestamp).

@github-actions
Copy link

github-actions bot commented Jul 14, 2022

Bugsnag.framework binary size decreased by 56 bytes from 814,536 to 814,480 🎉

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.1%    +260  +0.1%    +260    __TEXT,__text
  [ = ]       0  +1.2%     +56    [__LINKEDIT]
  [ = ]       0  +0.5%     +48    __DATA,__bss
  +0.0%     +32  +0.0%     +32    String Table
  +0.2%     +32  +0.2%     +32    __DATA,__cfstring
  +0.1%     +15  +0.1%     +15    __TEXT,__objc_methname
  +0.1%     +13  +0.1%     +13    __TEXT,__cstring
  +0.1%      +8  +0.1%      +8    Export Info
  -0.3%      -8  -0.3%      -8    Binding Info
  -1.0%     -16  -1.0%     -16    Indirect Symbol Table
  -0.0%     -16  -0.0%     -16    Symbol Table
  -1.1%     -16  -1.1%     -16    __DATA,__la_symbol_ptr
  -1.1%     -24  -1.1%     -24    __TEXT,__stub_helper
  -1.1%     -24  -1.1%     -24    __TEXT,__stubs
  -1.3%     -56  -1.3%     -56    Lazy Binding Info
  -0.2%     -16  -0.4%     -64    [__DATA]
  -1.1%    -240  -1.1%    -240    [__TEXT]
  -0.0%     -56  [ = ]       0    TOTAL

Generated by 🚫 Danger

@nickdowell nickdowell marked this pull request as ready for review July 15, 2022 08:01
@nickdowell nickdowell merged commit 59aef42 into next Jul 15, 2022
@nickdowell nickdowell deleted the nickdowell/app-memory-stats branch July 15, 2022 10:34
@nickdowell nickdowell mentioned this pull request Jul 20, 2022
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.

2 participants