1DROP VIEW IF EXISTS fastrpc_timeline; 2CREATE VIEW fastrpc_timeline AS 3SELECT 4 ts, 5 LEAD(ts, 1, (SELECT end_ts FROM trace_bounds)) 6 OVER(PARTITION BY track_id ORDER BY ts) - ts AS dur, 7 RTRIM(SUBSTR(name, 13), ']') AS subsystem_name, 8 track_id, 9 value 10FROM counter JOIN counter_track 11 ON counter.track_id = counter_track.id 12WHERE (name GLOB 'mem.fastrpc[[]*'); 13 14DROP VIEW IF EXISTS fastrpc_subsystem_stats; 15CREATE VIEW fastrpc_subsystem_stats AS 16SELECT 17 subsystem_name, 18 SUM(value * dur) / SUM(dur) AS avg_size, 19 MIN(value) AS min_size, 20 MAX(value) AS max_size 21FROM fastrpc_timeline 22GROUP BY 1; 23 24DROP VIEW IF EXISTS fastrpc_raw_allocs; 25CREATE VIEW fastrpc_raw_allocs AS 26SELECT 27 RTRIM(SUBSTR(name, 20), ']') AS subsystem_name, 28 ts, 29 value AS instant_value, 30 SUM(value) OVER win AS value 31FROM counter c JOIN thread_counter_track t ON c.track_id = t.id 32WHERE name GLOB 'mem.fastrpc_change*' AND value > 0 33WINDOW win AS ( 34 PARTITION BY name ORDER BY ts 35 ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW 36); 37 38DROP VIEW IF EXISTS fastrpc_alloc_stats; 39CREATE VIEW fastrpc_alloc_stats AS 40SELECT 41 subsystem_name, 42 SUM(instant_value) AS total_alloc_size_bytes 43FROM fastrpc_raw_allocs 44GROUP BY 1; 45 46-- We need to group by ts here as we can have two events from 47-- different processes occurring at the same timestamp. We take the 48-- max as this will take both allocations into account at that 49-- timestamp. 50DROP VIEW IF EXISTS android_fastrpc_event; 51CREATE VIEW android_fastrpc_event AS 52SELECT 53 'counter' AS track_type, 54 printf('fastrpc allocations (subsystem: %s)', subsystem_name) AS track_name, 55 ts, 56 MAX(value) AS value 57FROM fastrpc_raw_allocs 58GROUP BY 1, 2, 3; 59 60DROP VIEW IF EXISTS android_fastrpc_output; 61CREATE VIEW android_fastrpc_output AS 62SELECT AndroidFastrpcMetric( 63 'subsystem', RepeatedField( 64 AndroidFastrpcMetric_Subsystem( 65 'name', subsystem_name, 66 'avg_size_bytes', avg_size, 67 'min_size_bytes', min_size, 68 'max_size_bytes', max_size, 69 'total_alloc_size_bytes', total_alloc_size_bytes 70 ) 71 )) 72FROM fastrpc_subsystem_stats JOIN fastrpc_alloc_stats USING (subsystem_name); 73