1-- 2-- Copyright 2023 The Android Open Source Project 3-- 4-- Licensed under the Apache License, Version 2.0 (the "License"); 5-- you may not use this file except in compliance with the License. 6-- You may obtain a copy of the License at 7-- 8-- https://www.apache.org/licenses/LICENSE-2.0 9-- 10-- Unless required by applicable law or agreed to in writing, software 11-- distributed under the License is distributed on an "AS IS" BASIS, 12-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13-- See the License for the specific language governing permissions and 14-- limitations under the License. 15 16-- TODO(b/329344794): Rewrite to fetch data from other tables than `raw`. 17 18-- Aggregates f2fs IO and latency stats by counter name. 19CREATE PERFETTO VIEW _android_io_f2fs_counter_stats( 20 -- Counter name on which all the other values are aggregated on. 21 name STRING, 22 -- Sum of all counter values for the counter name. 23 sum INT, 24 -- Max of all counter values for the counter name. 25 max INT, 26 -- Min of all counter values for the counter name. 27 min INT, 28 -- Duration between the first and last counter value for the counter name. 29 dur INT, 30 -- Count of all the counter values for the counter name. 31 count INT, 32 -- Avergate of all the counter values for the counter name. 33 avg DOUBLE 34) AS 35SELECT 36 STR_SPLIT(counter_track.name, '].', 1) AS name, 37 SUM(counter.value) AS sum, 38 MAX(counter.value) AS max, 39 MIN(counter.value) AS min, 40 MAX(ts) - MIN(ts) AS dur, 41 COUNT(ts) AS count, 42 AVG(counter.value) AS avg 43FROM counter 44JOIN counter_track 45 ON counter_track.id = counter.track_id AND counter_track.name GLOB '*f2fs*' 46GROUP BY name 47ORDER BY sum DESC; 48 49-- Aggregates f2fs_write stats by inode and thread. 50CREATE PERFETTO VIEW _android_io_f2fs_write_stats( 51 -- Utid of the thread. 52 utid INT, 53 -- Tid of the thread. 54 tid INT, 55 -- Name of the thread. 56 thread_name STRING, 57 -- Upid of the process. 58 upid INT, 59 -- Pid of the process. 60 pid INT, 61 -- Name of the thread. 62 process_name STRING, 63 -- Inode number of the file being written. 64 ino INT, 65 -- Device node number of the file being written. 66 dev INT, 67 -- Total number of bytes written on this file by the |utid|. 68 bytes BYTES, 69 -- Total count of write requests for this file. 70 write_count INT 71) AS 72WITH 73 f2fs_write_end AS ( 74 SELECT 75 *, 76 EXTRACT_ARG(arg_set_id, 'len') AS len, 77 EXTRACT_ARG(arg_set_id, 'dev') AS dev, 78 EXTRACT_ARG(arg_set_id, 'ino') AS ino, 79 EXTRACT_ARG(arg_set_id, 'copied') AS copied 80 FROM raw 81 WHERE name GLOB 'f2fs_write_end*' 82 ) 83SELECT 84 thread.utid, 85 thread.tid, 86 thread.name AS thread_name, 87 process.upid, 88 process.pid, 89 process.name AS process_name, 90 f.ino, 91 f.dev, 92 SUM(copied) AS bytes, 93 COUNT(len) AS write_count 94FROM f2fs_write_end f 95JOIN thread 96 USING (utid) 97JOIN process 98 USING (upid) 99GROUP BY utid, ino, dev 100ORDER BY bytes DESC; 101 102-- Aggregates f2fs write stats. Counts distinct datapoints, total write operations, 103-- and bytes written 104CREATE PERFETTO VIEW _android_io_f2fs_aggregate_write_stats( 105 -- Total number of writes in the trace. 106 total_write_count INT, 107 -- Number of distinct processes. 108 distinct_processes INT, 109 -- Total number of bytes written. 110 total_bytes_written INT, 111 -- Count of distinct devices written to. 112 distinct_device_count INT, 113 -- Count of distinct inodes written to. 114 distinct_inode_count INT, 115 -- Count of distinct threads writing. 116 distinct_thread_count INT 117) AS 118select SUM(write_count) as total_write_count, 119 COUNT(DISTINCT pid) distinct_processes, 120 SUM(bytes) as total_bytes_written, 121 COUNT(DISTINCT dev) as distinct_device_count, 122 COUNT(DISTINCT ino) distinct_inode_count, 123 COUNT(DISTINCT tid) distinct_thread_count 124from _android_io_f2fs_write_stats;