Repository navigation
Commit e4bb886
perf(android): Read cpu time via Process.getElapsedCpuTime (#5926)
* perf(android): Read cpu time via Process.getElapsedCpuTime (JAVA-690)
AndroidCpuCollector.collect() runs 10 times per second for the whole
duration of every transaction, and each sample read and parsed
/proc/self/stat: the file reader buffers, the intermediate strings and a
regex split of all 52 fields allocated roughly 25 kB per sample, on top
of five syscalls, to obtain four numbers.
Process.getElapsedCpuTime() is a @CriticalNative wrapper around
clock_gettime(CLOCK_PROCESS_CPUTIME_ID) and returns the same quantity
with no allocation, at millisecond rather than clock-tick resolution. It
excludes the cpu time of reaped child processes, which an app process
does not have. This also drops the Pattern.compile() that ran on the
SentryAndroid.init path whether or not performance collection started.
Measured on a Pixel 3 (Android 12): collect() drops from 33623 to 16
bytes allocated per call, the remainder being the Double boxing of the
result. The reported percentages are unchanged for 1, 4 and 8 of 8 busy
cores.
Also seed lastRealtimeNanos in setup(), so the first sample is measured
against the previous sample instead of against time since boot. Under
full load that sample reported 0.0% before and 92.9% after.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* changelog
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* ref(android): Restore the cpu collector attribution comment
The percentage calculation still follows the linked article; only the
source of the process cpu time changed. Drop the measured allocation
sizes from the comment - they belong in the commit history, not next to
code that no longer allocates.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* ref(android): Drop the stale cpu collector attribution comment
The linked article describes reading and parsing /proc/self/stat, which
this collector no longer does.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>1 parent 69ee9eb commit e4bb886
2 files changed
Lines changed: 16 additions & 54 deletions
File tree
- sentry-android-core/src/main/java/io/sentry/android/core
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
13 | 18 | | |
14 | 19 | | |
15 | 20 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
9 | | - | |
10 | | - | |
11 | 10 | | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | 11 | | |
16 | 12 | | |
17 | 13 | | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
22 | 19 | | |
23 | 20 | | |
24 | 21 | | |
| 22 | + | |
| 23 | + | |
25 | 24 | | |
26 | 25 | | |
27 | 26 | | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | 27 | | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | 28 | | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | 29 | | |
42 | | - | |
43 | 30 | | |
44 | 31 | | |
45 | | - | |
| 32 | + | |
46 | 33 | | |
47 | 34 | | |
48 | 35 | | |
49 | 36 | | |
50 | 37 | | |
51 | | - | |
52 | 38 | | |
53 | | - | |
| 39 | + | |
54 | 40 | | |
55 | 41 | | |
56 | 42 | | |
| |||
74 | 60 | | |
75 | 61 | | |
76 | 62 | | |
77 | | - | |
78 | 63 | | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
| 64 | + | |
108 | 65 | | |
109 | 66 | | |
0 commit comments