|
14 | 14 | -- limitations under the License. |
15 | 15 | -- |
16 | 16 |
|
| 17 | +INCLUDE PERFETTO MODULE android.memory.heap_graph.heap_graph_stats; |
17 | 18 | SELECT RUN_METRIC('android/process_metadata.sql'); |
18 | | -SELECT RUN_METRIC('android/process_mem.sql'); |
19 | 19 |
|
20 | 20 | DROP VIEW IF EXISTS java_heap_stats_output; |
21 | 21 | CREATE PERFETTO VIEW java_heap_stats_output AS |
22 | 22 | WITH |
23 | | --- Base view |
24 | | -base_stat_counts AS ( |
25 | | - SELECT |
26 | | - upid, |
27 | | - graph_sample_ts, |
28 | | - SUM(self_size) AS total_size, |
29 | | - SUM(native_size) AS total_native_size, |
30 | | - COUNT(1) AS total_obj_count, |
31 | | - SUM(IIF(reachable, self_size, 0)) AS reachable_size, |
32 | | - SUM(IIF(reachable, native_size, 0)) AS reachable_native_size, |
33 | | - SUM(IIF(reachable, 1, 0)) AS reachable_obj_count |
34 | | - FROM heap_graph_object |
35 | | - GROUP BY 1, 2 |
36 | | -), |
37 | | -heap_roots AS ( |
38 | | - SELECT |
39 | | - upid, |
40 | | - graph_sample_ts, |
41 | | - root_type, |
42 | | - IFNULL(t.deobfuscated_name, t.name) AS type_name, |
43 | | - COUNT(1) AS obj_count |
44 | | - FROM heap_graph_object o |
45 | | - JOIN heap_graph_class t ON o.type_id = t.id |
46 | | - -- Classes are going to be particularly spammy and uninteresting |
47 | | - -- from a memory analysis perspective (compared e.g. to local jni roots) |
48 | | - WHERE root_type IS NOT NULL AND root_type != 'ROOT_STICKY_CLASS' |
49 | | - GROUP BY 1, 2, 3, 4 |
50 | | - ORDER BY obj_count DESC |
51 | | -), |
52 | | -heap_roots_proto AS ( |
53 | | - SELECT |
54 | | - upid, |
55 | | - graph_sample_ts, |
56 | | - RepeatedField(JavaHeapStats_HeapRoots( |
57 | | - 'root_type', root_type, |
58 | | - 'type_name', type_name, |
59 | | - 'obj_count', obj_count |
60 | | - )) AS roots |
61 | | - FROM heap_roots |
62 | | - GROUP BY 1, 2 |
63 | | -), |
64 | | -base_stats AS ( |
65 | | - SELECT * FROM base_stat_counts JOIN heap_roots_proto USING (upid, graph_sample_ts) |
66 | | -), |
67 | | --- Find closest value |
68 | | -closest_anon_swap_oom AS ( |
69 | | - SELECT |
70 | | - upid, |
71 | | - graph_sample_ts, |
72 | | - ( |
73 | | - SELECT anon_swap_val |
74 | | - FROM ( |
75 | | - SELECT |
76 | | - ts, dur, |
77 | | - CAST(anon_and_swap_val AS INTEGER) AS anon_swap_val, |
78 | | - ABS(ts - base_stats.graph_sample_ts) AS diff |
79 | | - FROM anon_and_swap_span |
80 | | - WHERE upid = base_stats.upid) |
81 | | - WHERE |
82 | | - (graph_sample_ts >= ts AND graph_sample_ts < ts + dur) |
83 | | - -- If the first memory sample for the UPID comes *after* the heap profile |
84 | | - -- accept it if close (500ms) |
85 | | - OR (graph_sample_ts < ts AND diff <= 500 * 1e6) |
86 | | - ORDER BY diff LIMIT 1 |
87 | | - ) AS anon_swap_val, |
88 | | - ( |
89 | | - SELECT oom_score_val |
90 | | - FROM ( |
91 | | - SELECT |
92 | | - ts, dur, |
93 | | - oom_score_val, |
94 | | - ABS(ts - base_stats.graph_sample_ts) AS diff |
95 | | - FROM oom_score_span |
96 | | - WHERE upid = base_stats.upid) |
97 | | - WHERE |
98 | | - (graph_sample_ts >= ts AND graph_sample_ts < ts + dur) |
99 | | - -- If the first memory sample for the UPID comes *after* the heap profile |
100 | | - -- accept it if close (500ms) |
101 | | - OR (graph_sample_ts < ts AND diff <= 500 * 1e6) |
102 | | - ORDER BY diff LIMIT 1 |
103 | | - ) AS oom_score_val |
104 | | - FROM base_stats |
105 | | -), |
106 | 23 | -- Group by upid |
107 | 24 | heap_graph_sample_protos AS ( |
108 | 25 | SELECT |
109 | | - base_stats.upid, |
| 26 | + upid, |
110 | 27 | RepeatedField(JavaHeapStats_Sample( |
111 | 28 | 'ts', graph_sample_ts, |
112 | | - 'process_uptime_ms', |
113 | | - CASE WHEN process.start_ts IS NOT NULL |
114 | | - THEN (graph_sample_ts - process.start_ts) / 1000000 |
115 | | - ELSE NULL |
116 | | - END, |
117 | | - 'heap_size', total_size, |
118 | | - 'heap_native_size', total_native_size, |
| 29 | + 'process_uptime_ms', process_uptime / 1e6, |
| 30 | + 'heap_size', total_heap_size, |
| 31 | + 'heap_native_size', total_native_alloc_registry_size, |
119 | 32 | 'obj_count', total_obj_count, |
120 | | - 'reachable_heap_size', reachable_size, |
121 | | - 'reachable_heap_native_size', reachable_native_size, |
| 33 | + 'reachable_heap_size', reachable_heap_size, |
| 34 | + 'reachable_heap_native_size', reachable_native_alloc_registry_size, |
122 | 35 | 'reachable_obj_count', reachable_obj_count, |
123 | | - 'roots', roots, |
124 | | - 'anon_rss_and_swap_size', closest_anon_swap_oom.anon_swap_val, |
125 | | - 'oom_score_adj', closest_anon_swap_oom.oom_score_val |
| 36 | + 'oom_score_adj', oom_score_adj, |
| 37 | + 'anon_rss_and_swap_size', anon_rss_and_swap_size, |
| 38 | + 'dmabuf_rss_size', dmabuf_rss_size |
126 | 39 | )) AS sample_protos |
127 | | - FROM base_stats |
128 | | - JOIN process USING (upid) |
129 | | - LEFT JOIN closest_anon_swap_oom USING (upid, graph_sample_ts) |
| 40 | + FROM android_heap_graph_stats |
130 | 41 | GROUP BY 1 |
131 | 42 | ) |
132 | 43 | SELECT JavaHeapStats( |
|
0 commit comments