1*387f9dfdSAndroid Build Coastguard WorkerDemonstrations of profile, the Linux eBPF/bcc version. 2*387f9dfdSAndroid Build Coastguard Worker 3*387f9dfdSAndroid Build Coastguard Worker 4*387f9dfdSAndroid Build Coastguard WorkerThis is a CPU profiler. It works by taking samples of stack traces at timed 5*387f9dfdSAndroid Build Coastguard Workerintervals, and frequency counting them in kernel context for efficiency. 6*387f9dfdSAndroid Build Coastguard Worker 7*387f9dfdSAndroid Build Coastguard WorkerExample output: 8*387f9dfdSAndroid Build Coastguard Worker 9*387f9dfdSAndroid Build Coastguard Worker# ./profile 10*387f9dfdSAndroid Build Coastguard WorkerSampling at 49 Hertz of all threads by user + kernel stack... Hit Ctrl-C to end. 11*387f9dfdSAndroid Build Coastguard Worker^C 12*387f9dfdSAndroid Build Coastguard Worker ffffffff81189249 filemap_map_pages 13*387f9dfdSAndroid Build Coastguard Worker ffffffff811bd3f5 handle_mm_fault 14*387f9dfdSAndroid Build Coastguard Worker ffffffff81065990 __do_page_fault 15*387f9dfdSAndroid Build Coastguard Worker ffffffff81065caf do_page_fault 16*387f9dfdSAndroid Build Coastguard Worker ffffffff817ce228 page_fault 17*387f9dfdSAndroid Build Coastguard Worker 00007fed989afcc0 [unknown] 18*387f9dfdSAndroid Build Coastguard Worker - cp (9036) 19*387f9dfdSAndroid Build Coastguard Worker 1 20*387f9dfdSAndroid Build Coastguard Worker 21*387f9dfdSAndroid Build Coastguard Worker 00007f31d76c3251 [unknown] 22*387f9dfdSAndroid Build Coastguard Worker 47a2c1e752bf47f7 [unknown] 23*387f9dfdSAndroid Build Coastguard Worker - sign-file (8877) 24*387f9dfdSAndroid Build Coastguard Worker 1 25*387f9dfdSAndroid Build Coastguard Worker 26*387f9dfdSAndroid Build Coastguard Worker ffffffff813d0af8 __clear_user 27*387f9dfdSAndroid Build Coastguard Worker ffffffff813d5277 iov_iter_zero 28*387f9dfdSAndroid Build Coastguard Worker ffffffff814ec5f2 read_iter_zero 29*387f9dfdSAndroid Build Coastguard Worker ffffffff8120be9d __vfs_read 30*387f9dfdSAndroid Build Coastguard Worker ffffffff8120c385 vfs_read 31*387f9dfdSAndroid Build Coastguard Worker ffffffff8120d786 sys_read 32*387f9dfdSAndroid Build Coastguard Worker ffffffff817cc076 entry_SYSCALL_64_fastpath 33*387f9dfdSAndroid Build Coastguard Worker 00007fc5652ad9b0 read 34*387f9dfdSAndroid Build Coastguard Worker - dd (25036) 35*387f9dfdSAndroid Build Coastguard Worker 4 36*387f9dfdSAndroid Build Coastguard Worker 37*387f9dfdSAndroid Build Coastguard Worker 0000000000400542 func_a 38*387f9dfdSAndroid Build Coastguard Worker 0000000000400598 main 39*387f9dfdSAndroid Build Coastguard Worker 00007f12a133e830 __libc_start_main 40*387f9dfdSAndroid Build Coastguard Worker 083e258d4c544155 [unknown] 41*387f9dfdSAndroid Build Coastguard Worker - func_ab (13549) 42*387f9dfdSAndroid Build Coastguard Worker 5 43*387f9dfdSAndroid Build Coastguard Worker 44*387f9dfdSAndroid Build Coastguard Worker[...] 45*387f9dfdSAndroid Build Coastguard Worker 46*387f9dfdSAndroid Build Coastguard Worker ffffffff8105eb66 native_safe_halt 47*387f9dfdSAndroid Build Coastguard Worker ffffffff8103659e default_idle 48*387f9dfdSAndroid Build Coastguard Worker ffffffff81036d1f arch_cpu_idle 49*387f9dfdSAndroid Build Coastguard Worker ffffffff810bba5a default_idle_call 50*387f9dfdSAndroid Build Coastguard Worker ffffffff810bbd07 cpu_startup_entry 51*387f9dfdSAndroid Build Coastguard Worker ffffffff817bf4a7 rest_init 52*387f9dfdSAndroid Build Coastguard Worker ffffffff81d65f58 start_kernel 53*387f9dfdSAndroid Build Coastguard Worker ffffffff81d652db x86_64_start_reservations 54*387f9dfdSAndroid Build Coastguard Worker ffffffff81d65418 x86_64_start_kernel 55*387f9dfdSAndroid Build Coastguard Worker - swapper/0 (0) 56*387f9dfdSAndroid Build Coastguard Worker 72 57*387f9dfdSAndroid Build Coastguard Worker 58*387f9dfdSAndroid Build Coastguard Worker ffffffff8105eb66 native_safe_halt 59*387f9dfdSAndroid Build Coastguard Worker ffffffff8103659e default_idle 60*387f9dfdSAndroid Build Coastguard Worker ffffffff81036d1f arch_cpu_idle 61*387f9dfdSAndroid Build Coastguard Worker ffffffff810bba5a default_idle_call 62*387f9dfdSAndroid Build Coastguard Worker ffffffff810bbd07 cpu_startup_entry 63*387f9dfdSAndroid Build Coastguard Worker ffffffff8104df55 start_secondary 64*387f9dfdSAndroid Build Coastguard Worker - swapper/1 (0) 65*387f9dfdSAndroid Build Coastguard Worker 75 66*387f9dfdSAndroid Build Coastguard Worker 67*387f9dfdSAndroid Build Coastguard WorkerThe output was long; I truncated some lines ("[...]"). 68*387f9dfdSAndroid Build Coastguard Worker 69*387f9dfdSAndroid Build Coastguard WorkerThis default output prints stack traces as two columns (raw addresses, and 70*387f9dfdSAndroid Build Coastguard Workerthen translated symbol names), followed by a line to describe the process (a 71*387f9dfdSAndroid Build Coastguard Workerdash, the process name, and a PID in parenthesis), and then an integer count 72*387f9dfdSAndroid Build Coastguard Workerof how many times this stack trace was sampled. 73*387f9dfdSAndroid Build Coastguard Worker 74*387f9dfdSAndroid Build Coastguard WorkerThe output above shows the most frequent stack was from the "swapper/1" 75*387f9dfdSAndroid Build Coastguard Workerprocess (PID 0), running the native_safe_halt() function, which was called 76*387f9dfdSAndroid Build Coastguard Workerby default_idle(), which was called by arch_cpu_idle(), and so on. This is 77*387f9dfdSAndroid Build Coastguard Workerthe idle thread. Stacks can be read top-down, to follow ancestry: child, 78*387f9dfdSAndroid Build Coastguard Workerparent, grandparent, etc. 79*387f9dfdSAndroid Build Coastguard Worker 80*387f9dfdSAndroid Build Coastguard WorkerThe func_ab process is running the func_a() function, called by main(), 81*387f9dfdSAndroid Build Coastguard Workercalled by __libc_start_main(), and called by "[unknown]" with what looks 82*387f9dfdSAndroid Build Coastguard Workerlike a bogus address (1st column). That's evidence of a broken stack trace. 83*387f9dfdSAndroid Build Coastguard WorkerIt's common for user-level software that hasn't been compiled with frame 84*387f9dfdSAndroid Build Coastguard Workerpointers (in this case, libc). 85*387f9dfdSAndroid Build Coastguard Worker 86*387f9dfdSAndroid Build Coastguard WorkerThe dd process has called read(), and then enters the kernel via 87*387f9dfdSAndroid Build Coastguard Workerentry_SYSCALL_64_fastpath(), calling sys_read(), and so on. Yes, I'm now 88*387f9dfdSAndroid Build Coastguard Workerreading it bottom up. That way follows the code flow. 89*387f9dfdSAndroid Build Coastguard Worker 90*387f9dfdSAndroid Build Coastguard Worker 91*387f9dfdSAndroid Build Coastguard WorkerThe dd process is actually "dd if=/dev/zero of=/dev/null": it's a simple 92*387f9dfdSAndroid Build Coastguard Workerworkload to analyze that just moves bytes from /dev/zero to /dev/null. 93*387f9dfdSAndroid Build Coastguard WorkerProfiling just that process: 94*387f9dfdSAndroid Build Coastguard Worker 95*387f9dfdSAndroid Build Coastguard Worker# ./profile -p 25036 96*387f9dfdSAndroid Build Coastguard WorkerSampling at 49 Hertz of PID 25036 by user + kernel stack... Hit Ctrl-C to end. 97*387f9dfdSAndroid Build Coastguard Worker^C 98*387f9dfdSAndroid Build Coastguard Worker 0000000000402748 [unknown] 99*387f9dfdSAndroid Build Coastguard Worker 00007fc56561422c [unknown] 100*387f9dfdSAndroid Build Coastguard Worker - dd (25036) 101*387f9dfdSAndroid Build Coastguard Worker 1 102*387f9dfdSAndroid Build Coastguard Worker 103*387f9dfdSAndroid Build Coastguard Worker 00007fc5652ada0e __write 104*387f9dfdSAndroid Build Coastguard Worker - dd (25036) 105*387f9dfdSAndroid Build Coastguard Worker 1 106*387f9dfdSAndroid Build Coastguard Worker 107*387f9dfdSAndroid Build Coastguard Worker 00007fc5652ad9b0 read 108*387f9dfdSAndroid Build Coastguard Worker - dd (25036) 109*387f9dfdSAndroid Build Coastguard Worker 1 110*387f9dfdSAndroid Build Coastguard Worker 111*387f9dfdSAndroid Build Coastguard Worker[...] 112*387f9dfdSAndroid Build Coastguard Worker 113*387f9dfdSAndroid Build Coastguard Worker 00000000004047b2 [unknown] 114*387f9dfdSAndroid Build Coastguard Worker 00007fc56561422c [unknown] 115*387f9dfdSAndroid Build Coastguard Worker - dd (25036) 116*387f9dfdSAndroid Build Coastguard Worker 2 117*387f9dfdSAndroid Build Coastguard Worker 118*387f9dfdSAndroid Build Coastguard Worker ffffffff817cc060 entry_SYSCALL_64_fastpath 119*387f9dfdSAndroid Build Coastguard Worker 00007fc5652ada10 __write 120*387f9dfdSAndroid Build Coastguard Worker 00007fc56561422c [unknown] 121*387f9dfdSAndroid Build Coastguard Worker - dd (25036) 122*387f9dfdSAndroid Build Coastguard Worker 3 123*387f9dfdSAndroid Build Coastguard Worker 124*387f9dfdSAndroid Build Coastguard Worker ffffffff817cc060 entry_SYSCALL_64_fastpath 125*387f9dfdSAndroid Build Coastguard Worker 00007fc5652ad9b0 read 126*387f9dfdSAndroid Build Coastguard Worker - dd (25036) 127*387f9dfdSAndroid Build Coastguard Worker 3 128*387f9dfdSAndroid Build Coastguard Worker 129*387f9dfdSAndroid Build Coastguard Worker ffffffff813d0af8 __clear_user 130*387f9dfdSAndroid Build Coastguard Worker ffffffff813d5277 iov_iter_zero 131*387f9dfdSAndroid Build Coastguard Worker ffffffff814ec5f2 read_iter_zero 132*387f9dfdSAndroid Build Coastguard Worker ffffffff8120be9d __vfs_read 133*387f9dfdSAndroid Build Coastguard Worker ffffffff8120c385 vfs_read 134*387f9dfdSAndroid Build Coastguard Worker ffffffff8120d786 sys_read 135*387f9dfdSAndroid Build Coastguard Worker ffffffff817cc076 entry_SYSCALL_64_fastpath 136*387f9dfdSAndroid Build Coastguard Worker 00007fc5652ad9b0 read 137*387f9dfdSAndroid Build Coastguard Worker 00007fc56561422c [unknown] 138*387f9dfdSAndroid Build Coastguard Worker - dd (25036) 139*387f9dfdSAndroid Build Coastguard Worker 3 140*387f9dfdSAndroid Build Coastguard Worker 141*387f9dfdSAndroid Build Coastguard Worker ffffffff813d0af8 __clear_user 142*387f9dfdSAndroid Build Coastguard Worker ffffffff813d5277 iov_iter_zero 143*387f9dfdSAndroid Build Coastguard Worker ffffffff814ec5f2 read_iter_zero 144*387f9dfdSAndroid Build Coastguard Worker ffffffff8120be9d __vfs_read 145*387f9dfdSAndroid Build Coastguard Worker ffffffff8120c385 vfs_read 146*387f9dfdSAndroid Build Coastguard Worker ffffffff8120d786 sys_read 147*387f9dfdSAndroid Build Coastguard Worker ffffffff817cc076 entry_SYSCALL_64_fastpath 148*387f9dfdSAndroid Build Coastguard Worker 00007fc5652ad9b0 read 149*387f9dfdSAndroid Build Coastguard Worker - dd (25036) 150*387f9dfdSAndroid Build Coastguard Worker 7 151*387f9dfdSAndroid Build Coastguard Worker 152*387f9dfdSAndroid Build Coastguard WorkerAgain, I've truncated some lines. Now we're just analyzing the dd process. 153*387f9dfdSAndroid Build Coastguard WorkerThe filtering is performed in kernel context, for efficiency. 154*387f9dfdSAndroid Build Coastguard Worker 155*387f9dfdSAndroid Build Coastguard WorkerThis output has some "[unknown]" frames that probably have valid addresses, 156*387f9dfdSAndroid Build Coastguard Workerbut we're lacking the symbol translation. This is a common for all profilers 157*387f9dfdSAndroid Build Coastguard Workeron Linux, and is usually fixable. See the DEBUGGING section of the profile(8) 158*387f9dfdSAndroid Build Coastguard Workerman page. 159*387f9dfdSAndroid Build Coastguard Worker 160*387f9dfdSAndroid Build Coastguard Worker 161*387f9dfdSAndroid Build Coastguard WorkerLets add delimiters between the user and kernel stacks, using -d: 162*387f9dfdSAndroid Build Coastguard Worker 163*387f9dfdSAndroid Build Coastguard Worker# ./profile -p 25036 -d 164*387f9dfdSAndroid Build Coastguard Worker^C 165*387f9dfdSAndroid Build Coastguard Worker ffffffff8120b385 __vfs_write 166*387f9dfdSAndroid Build Coastguard Worker ffffffff8120d826 sys_write 167*387f9dfdSAndroid Build Coastguard Worker ffffffff817cc076 entry_SYSCALL_64_fastpath 168*387f9dfdSAndroid Build Coastguard Worker -- 169*387f9dfdSAndroid Build Coastguard Worker 00007fc5652ada10 __write 170*387f9dfdSAndroid Build Coastguard Worker - dd (25036) 171*387f9dfdSAndroid Build Coastguard Worker 1 172*387f9dfdSAndroid Build Coastguard Worker 173*387f9dfdSAndroid Build Coastguard Worker -- 174*387f9dfdSAndroid Build Coastguard Worker 00007fc565255ef3 [unknown] 175*387f9dfdSAndroid Build Coastguard Worker 00007fc56561422c [unknown] 176*387f9dfdSAndroid Build Coastguard Worker - dd (25036) 177*387f9dfdSAndroid Build Coastguard Worker 1 178*387f9dfdSAndroid Build Coastguard Worker 179*387f9dfdSAndroid Build Coastguard Worker ffffffff813d4569 iov_iter_init 180*387f9dfdSAndroid Build Coastguard Worker ffffffff8120be8e __vfs_read 181*387f9dfdSAndroid Build Coastguard Worker ffffffff8120c385 vfs_read 182*387f9dfdSAndroid Build Coastguard Worker ffffffff8120d786 sys_read 183*387f9dfdSAndroid Build Coastguard Worker ffffffff817cc076 entry_SYSCALL_64_fastpath 184*387f9dfdSAndroid Build Coastguard Worker -- 185*387f9dfdSAndroid Build Coastguard Worker 00007fc5652ad9b0 read 186*387f9dfdSAndroid Build Coastguard Worker - dd (25036) 187*387f9dfdSAndroid Build Coastguard Worker 1 188*387f9dfdSAndroid Build Coastguard Worker 189*387f9dfdSAndroid Build Coastguard Worker[...] 190*387f9dfdSAndroid Build Coastguard Worker 191*387f9dfdSAndroid Build Coastguard Worker ffffffff813d0af8 __clear_user 192*387f9dfdSAndroid Build Coastguard Worker ffffffff813d5277 iov_iter_zero 193*387f9dfdSAndroid Build Coastguard Worker ffffffff814ec5f2 read_iter_zero 194*387f9dfdSAndroid Build Coastguard Worker ffffffff8120be9d __vfs_read 195*387f9dfdSAndroid Build Coastguard Worker ffffffff8120c385 vfs_read 196*387f9dfdSAndroid Build Coastguard Worker ffffffff8120d786 sys_read 197*387f9dfdSAndroid Build Coastguard Worker ffffffff817cc076 entry_SYSCALL_64_fastpath 198*387f9dfdSAndroid Build Coastguard Worker -- 199*387f9dfdSAndroid Build Coastguard Worker 00007fc5652ad9b0 read 200*387f9dfdSAndroid Build Coastguard Worker - dd (25036) 201*387f9dfdSAndroid Build Coastguard Worker 9 202*387f9dfdSAndroid Build Coastguard Worker 203*387f9dfdSAndroid Build Coastguard WorkerIn this mode, the delimiters are "--". 204*387f9dfdSAndroid Build Coastguard Worker 205*387f9dfdSAndroid Build Coastguard Worker 206*387f9dfdSAndroid Build Coastguard Worker 207*387f9dfdSAndroid Build Coastguard WorkerHere's another example, a func_ab program that runs two functions, func_a() and 208*387f9dfdSAndroid Build Coastguard Workerfunc_b(). Profiling it for 5 seconds: 209*387f9dfdSAndroid Build Coastguard Worker 210*387f9dfdSAndroid Build Coastguard Worker# ./profile -p `pgrep -n func_ab` 5 211*387f9dfdSAndroid Build Coastguard WorkerSampling at 49 Hertz of PID 2930 by user + kernel stack for 5 secs. 212*387f9dfdSAndroid Build Coastguard Worker 213*387f9dfdSAndroid Build Coastguard Worker 000000000040053e func_a 214*387f9dfdSAndroid Build Coastguard Worker 0000000000400598 main 215*387f9dfdSAndroid Build Coastguard Worker 00007f0458819830 __libc_start_main 216*387f9dfdSAndroid Build Coastguard Worker 083e258d4c544155 [unknown] 217*387f9dfdSAndroid Build Coastguard Worker - func_ab (2930) 218*387f9dfdSAndroid Build Coastguard Worker 2 219*387f9dfdSAndroid Build Coastguard Worker 220*387f9dfdSAndroid Build Coastguard Worker 0000000000400566 func_b 221*387f9dfdSAndroid Build Coastguard Worker 00000000004005ac main 222*387f9dfdSAndroid Build Coastguard Worker 00007f0458819830 __libc_start_main 223*387f9dfdSAndroid Build Coastguard Worker 083e258d4c544155 [unknown] 224*387f9dfdSAndroid Build Coastguard Worker - func_ab (2930) 225*387f9dfdSAndroid Build Coastguard Worker 3 226*387f9dfdSAndroid Build Coastguard Worker 227*387f9dfdSAndroid Build Coastguard Worker 000000000040053a func_a 228*387f9dfdSAndroid Build Coastguard Worker 0000000000400598 main 229*387f9dfdSAndroid Build Coastguard Worker 00007f0458819830 __libc_start_main 230*387f9dfdSAndroid Build Coastguard Worker 083e258d4c544155 [unknown] 231*387f9dfdSAndroid Build Coastguard Worker - func_ab (2930) 232*387f9dfdSAndroid Build Coastguard Worker 5 233*387f9dfdSAndroid Build Coastguard Worker 234*387f9dfdSAndroid Build Coastguard Worker 0000000000400562 func_b 235*387f9dfdSAndroid Build Coastguard Worker 00000000004005ac main 236*387f9dfdSAndroid Build Coastguard Worker 00007f0458819830 __libc_start_main 237*387f9dfdSAndroid Build Coastguard Worker 083e258d4c544155 [unknown] 238*387f9dfdSAndroid Build Coastguard Worker - func_ab (2930) 239*387f9dfdSAndroid Build Coastguard Worker 12 240*387f9dfdSAndroid Build Coastguard Worker 241*387f9dfdSAndroid Build Coastguard Worker 000000000040056a func_b 242*387f9dfdSAndroid Build Coastguard Worker 00000000004005ac main 243*387f9dfdSAndroid Build Coastguard Worker 00007f0458819830 __libc_start_main 244*387f9dfdSAndroid Build Coastguard Worker 083e258d4c544155 [unknown] 245*387f9dfdSAndroid Build Coastguard Worker - func_ab (2930) 246*387f9dfdSAndroid Build Coastguard Worker 19 247*387f9dfdSAndroid Build Coastguard Worker 248*387f9dfdSAndroid Build Coastguard Worker 0000000000400542 func_a 249*387f9dfdSAndroid Build Coastguard Worker 0000000000400598 main 250*387f9dfdSAndroid Build Coastguard Worker 00007f0458819830 __libc_start_main 251*387f9dfdSAndroid Build Coastguard Worker 083e258d4c544155 [unknown] 252*387f9dfdSAndroid Build Coastguard Worker - func_ab (2930) 253*387f9dfdSAndroid Build Coastguard Worker 22 254*387f9dfdSAndroid Build Coastguard Worker 255*387f9dfdSAndroid Build Coastguard Worker 0000000000400571 func_b 256*387f9dfdSAndroid Build Coastguard Worker 00000000004005ac main 257*387f9dfdSAndroid Build Coastguard Worker 00007f0458819830 __libc_start_main 258*387f9dfdSAndroid Build Coastguard Worker 083e258d4c544155 [unknown] 259*387f9dfdSAndroid Build Coastguard Worker - func_ab (2930) 260*387f9dfdSAndroid Build Coastguard Worker 64 261*387f9dfdSAndroid Build Coastguard Worker 262*387f9dfdSAndroid Build Coastguard Worker 0000000000400549 func_a 263*387f9dfdSAndroid Build Coastguard Worker 0000000000400598 main 264*387f9dfdSAndroid Build Coastguard Worker 00007f0458819830 __libc_start_main 265*387f9dfdSAndroid Build Coastguard Worker 083e258d4c544155 [unknown] 266*387f9dfdSAndroid Build Coastguard Worker - func_ab (2930) 267*387f9dfdSAndroid Build Coastguard Worker 72 268*387f9dfdSAndroid Build Coastguard Worker 269*387f9dfdSAndroid Build Coastguard WorkerNote that the same stack (2nd column) seems to be repeated. Weren't we doing 270*387f9dfdSAndroid Build Coastguard Workerfrequency counting and only printing unique stacks? We are, but in terms of 271*387f9dfdSAndroid Build Coastguard Workerthe raw addresses, not the symbols. See the 1st column: those stacks are 272*387f9dfdSAndroid Build Coastguard Workerall unique. 273*387f9dfdSAndroid Build Coastguard Worker 274*387f9dfdSAndroid Build Coastguard Worker 275*387f9dfdSAndroid Build Coastguard WorkerWe can output in "folded format", which puts the stack trace on one line, 276*387f9dfdSAndroid Build Coastguard Workerseparating frames with semi-colons. Eg: 277*387f9dfdSAndroid Build Coastguard Worker 278*387f9dfdSAndroid Build Coastguard Worker# ./profile -f -p `pgrep -n func_ab` 5 279*387f9dfdSAndroid Build Coastguard Workerfunc_ab;[unknown];__libc_start_main;main;func_a 2 280*387f9dfdSAndroid Build Coastguard Workerfunc_ab;[unknown];__libc_start_main;main;func_b 2 281*387f9dfdSAndroid Build Coastguard Workerfunc_ab;[unknown];__libc_start_main;main;func_a 11 282*387f9dfdSAndroid Build Coastguard Workerfunc_ab;[unknown];__libc_start_main;main;func_b 12 283*387f9dfdSAndroid Build Coastguard Workerfunc_ab;[unknown];__libc_start_main;main;func_a 23 284*387f9dfdSAndroid Build Coastguard Workerfunc_ab;[unknown];__libc_start_main;main;func_b 28 285*387f9dfdSAndroid Build Coastguard Workerfunc_ab;[unknown];__libc_start_main;main;func_b 57 286*387f9dfdSAndroid Build Coastguard Workerfunc_ab;[unknown];__libc_start_main;main;func_a 64 287*387f9dfdSAndroid Build Coastguard Worker 288*387f9dfdSAndroid Build Coastguard WorkerI find this pretty useful for writing to files and later grepping. 289*387f9dfdSAndroid Build Coastguard Worker 290*387f9dfdSAndroid Build Coastguard Worker 291*387f9dfdSAndroid Build Coastguard WorkerFolded format can also be used by flame graph stack visualizers, including 292*387f9dfdSAndroid Build Coastguard Workerthe original implementation: 293*387f9dfdSAndroid Build Coastguard Worker 294*387f9dfdSAndroid Build Coastguard Worker https://github.com/brendangregg/FlameGraph 295*387f9dfdSAndroid Build Coastguard Worker 296*387f9dfdSAndroid Build Coastguard WorkerI'd include delimiters, -d. For example: 297*387f9dfdSAndroid Build Coastguard Worker 298*387f9dfdSAndroid Build Coastguard Worker# ./profile -df -p `pgrep -n func_ab` 5 > out.profile 299*387f9dfdSAndroid Build Coastguard Worker# git clone https://github.com/brendangregg/FlameGraph 300*387f9dfdSAndroid Build Coastguard Worker# ./FlameGraph/flamegraph.pl < out.profile > out.svg 301*387f9dfdSAndroid Build Coastguard Worker 302*387f9dfdSAndroid Build Coastguard Worker(Yes, I could pipe profile directly into flamegraph.pl, however, I like to 303*387f9dfdSAndroid Build Coastguard Workerkeep the raw folded profiles around: can be useful for regenerating flamegraphs 304*387f9dfdSAndroid Build Coastguard Workerwith different options, and, for differential flame graphs.) 305*387f9dfdSAndroid Build Coastguard Worker 306*387f9dfdSAndroid Build Coastguard Worker 307*387f9dfdSAndroid Build Coastguard WorkerSome flamegraph.pl palettes recognize kernel annotations, which can be added 308*387f9dfdSAndroid Build Coastguard Workerwith -a. It simply adds a "_[k]" at the end of kernel function names. 309*387f9dfdSAndroid Build Coastguard WorkerFor example: 310*387f9dfdSAndroid Build Coastguard Worker 311*387f9dfdSAndroid Build Coastguard Worker# ./profile -adf -p `pgrep -n dd` 10 312*387f9dfdSAndroid Build Coastguard Workerdd;[unknown] 1 313*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];[unknown] 1 314*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];[unknown] 1 315*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];rw_verify_area_[k];security_file_permission_[k];__fsnotify_parent_[k] 1 316*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];__write;-;entry_SYSCALL_64_fastpath_[k];sys_write_[k];vfs_write_[k];__fsnotify_parent_[k] 1 317*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];__fdget_pos_[k] 1 318*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];rw_verify_area_[k];apparmor_file_permission_[k] 1 319*387f9dfdSAndroid Build Coastguard Workerdd;[unknown] 1 320*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];[unknown] 1 321*387f9dfdSAndroid Build Coastguard Workerdd;__write;-;entry_SYSCALL_64_fastpath_[k];sys_write_[k];vfs_write_[k] 1 322*387f9dfdSAndroid Build Coastguard Workerdd;[unknown] 1 323*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];__fget_light_[k] 1 324*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];rw_verify_area_[k];__fsnotify_parent_[k] 1 325*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];__vfs_read_[k];read_iter_zero_[k];iov_iter_zero_[k] 1 326*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];__write;-;entry_SYSCALL_64_fastpath_[k];sys_write_[k];__fget_light_[k] 1 327*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];[unknown] 1 328*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k] 1 329*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];[unknown] 1 330*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];__vfs_read_[k];read_iter_zero_[k];iov_iter_zero_[k] 1 331*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];__vfs_read_[k];read_iter_zero_[k];iov_iter_zero_[k] 1 332*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];read_iter_zero_[k] 1 333*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];__fsnotify_parent_[k] 1 334*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];[unknown] 1 335*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];rw_verify_area_[k];security_file_permission_[k];apparmor_file_permission_[k];common_file_perm_[k] 1 336*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];__fsnotify_parent_[k] 1 337*387f9dfdSAndroid Build Coastguard Workerdd;__write;-;entry_SYSCALL_64_fastpath_[k];sys_write_[k];vfs_write_[k];fsnotify_[k] 1 338*387f9dfdSAndroid Build Coastguard Workerdd;__write;-;entry_SYSCALL_64_fastpath_[k];sys_write_[k];vfs_write_[k];rw_verify_area_[k];security_file_permission_[k] 1 339*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];__write;-;entry_SYSCALL_64_fastpath_[k];sys_write_[k];__fdget_pos_[k] 1 340*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];__write;-;entry_SYSCALL_64_fastpath_[k] 1 341*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];[unknown] 1 342*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];rw_verify_area_[k];security_file_permission_[k] 1 343*387f9dfdSAndroid Build Coastguard Workerdd;__write;-;entry_SYSCALL_64_fastpath_[k];sys_write_[k];vfs_write_[k] 1 344*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];__fget_light_[k] 1 345*387f9dfdSAndroid Build Coastguard Workerdd;[unknown] 1 346*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];__write;-;entry_SYSCALL_64_fastpath_[k];sys_write_[k];vfs_write_[k] 1 347*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];rw_verify_area_[k];security_file_permission_[k];apparmor_file_permission_[k] 1 348*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];[unknown] 1 349*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];rw_verify_area_[k];security_file_permission_[k] 1 350*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];rw_verify_area_[k];__fsnotify_parent_[k] 1 351*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];__vfs_read_[k];read_iter_zero_[k];iov_iter_zero_[k] 1 352*387f9dfdSAndroid Build Coastguard Workerdd;__write;-;entry_SYSCALL_64_fastpath_[k];sys_write_[k];vfs_write_[k];rw_verify_area_[k];security_file_permission_[k] 1 353*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];__vfs_read_[k];read_iter_zero_[k];iov_iter_zero_[k];__clear_user_[k] 1 354*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];[unknown] 1 355*387f9dfdSAndroid Build Coastguard Workerdd;__write;-;entry_SYSCALL_64_fastpath_[k];sys_write_[k];vfs_write_[k] 1 356*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];[unknown] 1 357*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];rw_verify_area_[k];security_file_permission_[k];apparmor_file_permission_[k];common_file_perm_[k] 1 358*387f9dfdSAndroid Build Coastguard Workerdd;read 1 359*387f9dfdSAndroid Build Coastguard Workerdd;__write;-;entry_SYSCALL_64_fastpath_[k];sys_write_[k];vfs_write_[k];security_file_permission_[k] 1 360*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];fsnotify_[k] 1 361*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];fsnotify_[k] 1 362*387f9dfdSAndroid Build Coastguard Workerdd;__write;-;entry_SYSCALL_64_fastpath_[k];sys_write_[k];vfs_write_[k];rw_verify_area_[k];apparmor_file_permission_[k] 1 363*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];__write;-;entry_SYSCALL_64_fastpath_[k];sys_write_[k];vfs_write_[k];__fsnotify_parent_[k] 1 364*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];__write;-;entry_SYSCALL_64_fastpath_[k];sys_write_[k];vfs_write_[k];rw_verify_area_[k];apparmor_file_permission_[k] 1 365*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k] 1 366*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];__vfs_read_[k];iov_iter_init_[k] 1 367*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];rw_verify_area_[k];security_file_permission_[k];__fsnotify_parent_[k] 1 368*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];__write;-;entry_SYSCALL_64_fastpath_[k];sys_write_[k];vfs_write_[k];__vfs_write_[k];write_null_[k] 1 369*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];__vfs_read_[k];read_iter_zero_[k];__clear_user_[k] 1 370*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];security_file_permission_[k] 1 371*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];rw_verify_area_[k];security_file_permission_[k];apparmor_file_permission_[k];common_file_perm_[k] 1 372*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];__vfs_read_[k];read_iter_zero_[k] 1 373*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];__write;-;entry_SYSCALL_64_fastpath_[k];sys_write_[k];vfs_write_[k] 1 374*387f9dfdSAndroid Build Coastguard Workerdd;__write;-;entry_SYSCALL_64_fastpath_[k];sys_write_[k];vfs_write_[k] 1 375*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];rw_verify_area_[k] 1 376*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];__fget_light_[k] 1 377*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];__write;-;entry_SYSCALL_64_fastpath_[k];sys_write_[k];vfs_write_[k];rw_verify_area_[k] 1 378*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];__vfs_read_[k] 1 379*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];__vfs_read_[k] 1 380*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];__write;-;entry_SYSCALL_64_fastpath_[k];sys_write_[k];vfs_write_[k];__vfs_write_[k] 1 381*387f9dfdSAndroid Build Coastguard Workerdd;[unknown] 1 382*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];__vfs_read_[k];read_iter_zero_[k];iov_iter_zero_[k] 1 383*387f9dfdSAndroid Build Coastguard Workerdd;[unknown] 1 384*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];__vfs_read_[k] 1 385*387f9dfdSAndroid Build Coastguard Workerdd;__write;-;entry_SYSCALL_64_fastpath_[k];sys_write_[k];__fsnotify_parent_[k] 1 386*387f9dfdSAndroid Build Coastguard Workerdd;__write;-;entry_SYSCALL_64_fastpath_[k];sys_write_[k];vfs_write_[k] 1 387*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];[unknown] 1 388*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];__vfs_read_[k];read_iter_zero_[k];iov_iter_zero_[k] 1 389*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];__vfs_read_[k];read_iter_zero_[k];iov_iter_zero_[k] 1 390*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];__write;-;sys_write_[k] 1 391*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];__fsnotify_parent_[k] 1 392*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];rw_verify_area_[k];security_file_permission_[k];common_file_perm_[k] 1 393*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];__vfs_read_[k];read_iter_zero_[k];iov_iter_zero_[k] 1 394*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];[unknown] 1 395*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];__vfs_read_[k];read_iter_zero_[k];iov_iter_zero_[k];__clear_user_[k] 1 396*387f9dfdSAndroid Build Coastguard Workerdd;__write;-;entry_SYSCALL_64_fastpath_[k];sys_write_[k];vfs_write_[k];rw_verify_area_[k];security_file_permission_[k];apparmor_file_permission_[k] 1 397*387f9dfdSAndroid Build Coastguard Workerdd;__write;-;entry_SYSCALL_64_fastpath_[k];sys_write_[k];__fget_light_[k] 1 398*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k] 1 399*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];vfs_read_[k] 1 400*387f9dfdSAndroid Build Coastguard Workerdd;__write 1 401*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];vfs_read_[k] 1 402*387f9dfdSAndroid Build Coastguard Workerdd;__write;-;entry_SYSCALL_64_fastpath_[k];sys_write_[k];vfs_write_[k];rw_verify_area_[k];security_file_permission_[k];apparmor_file_permission_[k];common_file_perm_[k] 1 403*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];__vfs_read_[k];read_iter_zero_[k];iov_iter_zero_[k] 1 404*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];__write;-;entry_SYSCALL_64_fastpath_[k];sys_write_[k];__fget_light_[k] 1 405*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];[unknown] 1 406*387f9dfdSAndroid Build Coastguard Workerdd;[unknown] 1 407*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];__vfs_read_[k];read_iter_zero_[k];iov_iter_zero_[k] 1 408*387f9dfdSAndroid Build Coastguard Workerdd;[unknown] 1 409*387f9dfdSAndroid Build Coastguard Workerdd;[unknown] 1 410*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];[unknown] 1 411*387f9dfdSAndroid Build Coastguard Workerdd;__write;-;entry_SYSCALL_64_fastpath_[k];sys_write_[k];vfs_write_[k] 1 412*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];__vfs_read_[k];read_iter_zero_[k];iov_iter_zero_[k] 1 413*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k] 1 414*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];__vfs_read_[k];read_iter_zero_[k] 1 415*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k] 1 416*387f9dfdSAndroid Build Coastguard Workerdd;__write;-;entry_SYSCALL_64_fastpath_[k];sys_write_[k];vfs_write_[k];rw_verify_area_[k];security_file_permission_[k];apparmor_file_permission_[k];common_file_perm_[k] 1 417*387f9dfdSAndroid Build Coastguard Workerdd;__write 1 418*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];__fget_light_[k] 1 419*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];rw_verify_area_[k];security_file_permission_[k] 1 420*387f9dfdSAndroid Build Coastguard Workerdd;__write;-;entry_SYSCALL_64_fastpath_[k];sys_write_[k] 1 421*387f9dfdSAndroid Build Coastguard Workerdd;[unknown] 1 422*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];__fget_light_[k] 1 423*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];__vfs_read_[k];read_iter_zero_[k] 1 424*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];[unknown] 1 425*387f9dfdSAndroid Build Coastguard Workerdd;__write;-;entry_SYSCALL_64_fastpath_[k];sys_write_[k];__fdget_pos_[k] 1 426*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];__vfs_read_[k];read_iter_zero_[k] 1 427*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];__vfs_read_[k];read_iter_zero_[k] 1 428*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];__vfs_read_[k];_cond_resched_[k] 1 429*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];iov_iter_init_[k] 1 430*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];rw_verify_area_[k];security_file_permission_[k];__fsnotify_parent_[k] 1 431*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];__vfs_read_[k] 1 432*387f9dfdSAndroid Build Coastguard Workerdd;__write;-;entry_SYSCALL_64_fastpath_[k];sys_write_[k];rw_verify_area_[k] 1 433*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];rw_verify_area_[k];apparmor_file_permission_[k] 1 434*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];__vfs_read_[k];read_iter_zero_[k];iov_iter_zero_[k] 1 435*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k] 1 436*387f9dfdSAndroid Build Coastguard Workerdd;[unknown] 1 437*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];rw_verify_area_[k];security_file_permission_[k];fsnotify_[k] 1 438*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];__vfs_read_[k] 1 439*387f9dfdSAndroid Build Coastguard Workerdd;__write;-;entry_SYSCALL_64_fastpath_[k];sys_write_[k];__fdget_pos_[k] 1 440*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];rw_verify_area_[k];security_file_permission_[k] 1 441*387f9dfdSAndroid Build Coastguard Workerdd;__write;-;entry_SYSCALL_64_fastpath_[k];sys_write_[k];vfs_write_[k] 1 442*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];__write;-;entry_SYSCALL_64_fastpath_[k];sys_write_[k];vfs_write_[k];__vfs_write_[k] 1 443*387f9dfdSAndroid Build Coastguard Workerdd;__write;-;entry_SYSCALL_64_fastpath_[k];sys_write_[k];vfs_write_[k];rw_verify_area_[k];apparmor_file_permission_[k] 1 444*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];rw_verify_area_[k];security_file_permission_[k] 1 445*387f9dfdSAndroid Build Coastguard Workerdd;__write;-;entry_SYSCALL_64_fastpath_[k];sys_write_[k];vfs_write_[k];rw_verify_area_[k];security_file_permission_[k];apparmor_file_permission_[k];common_file_perm_[k] 1 446*387f9dfdSAndroid Build Coastguard Workerdd;__write;-;entry_SYSCALL_64_fastpath_[k];sys_write_[k];vfs_write_[k] 1 447*387f9dfdSAndroid Build Coastguard Workerdd;__write;-;entry_SYSCALL_64_fastpath_[k];sys_write_[k];vfs_write_[k] 1 448*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];__fget_light_[k] 1 449*387f9dfdSAndroid Build Coastguard Workerdd;[unknown] 1 450*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];__write;-;entry_SYSCALL_64_fastpath_[k];sys_write_[k];vfs_write_[k];fsnotify_[k] 1 451*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];__write;-;entry_SYSCALL_64_fastpath_[k];sys_write_[k];vfs_write_[k];rw_verify_area_[k];security_file_permission_[k];apparmor_file_permission_[k];common_file_perm_[k] 1 452*387f9dfdSAndroid Build Coastguard Workerdd;__write;-;entry_SYSCALL_64_fastpath_[k];sys_write_[k];vfs_write_[k];rw_verify_area_[k] 1 453*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];__vfs_read_[k];read_iter_zero_[k];iov_iter_zero_[k] 1 454*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];fsnotify_[k] 1 455*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];__write;-;entry_SYSCALL_64_fastpath_[k];sys_write_[k];vfs_write_[k] 1 456*387f9dfdSAndroid Build Coastguard Workerdd;__write;-;entry_SYSCALL_64_fastpath_[k];vfs_write_[k] 1 457*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];rw_verify_area_[k] 1 458*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];__vfs_read_[k] 1 459*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];rw_verify_area_[k];security_file_permission_[k];apparmor_file_permission_[k];common_file_perm_[k] 1 460*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];__vfs_read_[k];read_iter_zero_[k] 1 461*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];rw_verify_area_[k];fsnotify_[k] 1 462*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];__write;-;entry_SYSCALL_64_fastpath_[k];sys_write_[k];vfs_write_[k];rw_verify_area_[k];apparmor_file_permission_[k] 2 463*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];__fdget_pos_[k] 2 464*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];[unknown] 2 465*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];__fdget_pos_[k] 2 466*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];rw_verify_area_[k];security_file_permission_[k];apparmor_file_permission_[k];common_file_perm_[k] 2 467*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];[unknown] 2 468*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];[unknown] 2 469*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];[unknown] 2 470*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k] 2 471*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];[unknown] 2 472*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];__vfs_read_[k];read_iter_zero_[k];__clear_user_[k] 2 473*387f9dfdSAndroid Build Coastguard Workerdd;__write;-;entry_SYSCALL_64_fastpath_[k];__fdget_pos_[k] 2 474*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];__vfs_read_[k] 2 475*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];__vfs_read_[k] 2 476*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];__vfs_read_[k];read_iter_zero_[k];iov_iter_zero_[k];__clear_user_[k] 2 477*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];__vfs_read_[k];read_iter_zero_[k];iov_iter_zero_[k];__clear_user_[k] 2 478*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];[unknown] 2 479*387f9dfdSAndroid Build Coastguard Workerdd;__write;-;entry_SYSCALL_64_fastpath_[k];sys_write_[k];__fget_light_[k] 2 480*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];rw_verify_area_[k];security_file_permission_[k];fsnotify_[k] 2 481*387f9dfdSAndroid Build Coastguard Workerdd;__write;-;sys_write_[k] 2 482*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];fsnotify_[k] 2 483*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];[unknown] 2 484*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];__vfs_read_[k] 2 485*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];__vfs_read_[k];read_iter_zero_[k];iov_iter_zero_[k] 2 486*387f9dfdSAndroid Build Coastguard Workerdd;read;-;SyS_read_[k] 2 487*387f9dfdSAndroid Build Coastguard Workerdd;[unknown] 2 488*387f9dfdSAndroid Build Coastguard Workerdd;__write;-;entry_SYSCALL_64_fastpath_[k];sys_write_[k];vfs_write_[k];rw_verify_area_[k] 2 489*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];__write;-;entry_SYSCALL_64_fastpath_[k];sys_write_[k];__fget_light_[k] 2 490*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];__vfs_read_[k] 2 491*387f9dfdSAndroid Build Coastguard Workerdd;__write;-;entry_SYSCALL_64_fastpath_[k];sys_write_[k];vfs_write_[k];rw_verify_area_[k];security_file_permission_[k];apparmor_file_permission_[k] 2 492*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];__vfs_read_[k];read_iter_zero_[k];__clear_user_[k] 2 493*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];__write;-;entry_SYSCALL_64_fastpath_[k];sys_write_[k];rw_verify_area_[k] 2 494*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];[unknown] 3 495*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];rw_verify_area_[k] 3 496*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];[unknown] 3 497*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];__vfs_read_[k];read_iter_zero_[k];iov_iter_zero_[k];__clear_user_[k] 3 498*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];__vfs_read_[k];read_iter_zero_[k];iov_iter_zero_[k] 3 499*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];[unknown] 3 500*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];__vfs_read_[k];read_iter_zero_[k];iov_iter_zero_[k] 3 501*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];[unknown] 3 502*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];[unknown] 3 503*387f9dfdSAndroid Build Coastguard Workerdd;__write;-;entry_SYSCALL_64_fastpath_[k];sys_write_[k];vfs_write_[k] 3 504*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k] 3 505*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];__vfs_read_[k];read_iter_zero_[k];iov_iter_zero_[k];__clear_user_[k] 3 506*387f9dfdSAndroid Build Coastguard Workerdd;[unknown] 4 507*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k] 4 508*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];[unknown] 4 509*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k] 4 510*387f9dfdSAndroid Build Coastguard Workerdd;[unknown] 4 511*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];[unknown] 4 512*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k] 4 513*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];__vfs_read_[k];read_iter_zero_[k];iov_iter_zero_[k];__clear_user_[k] 5 514*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];__write;-;entry_SYSCALL_64_fastpath_[k];sys_write_[k];vfs_write_[k] 5 515*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];[unknown] 5 516*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];[unknown] 5 517*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];__vfs_read_[k];read_iter_zero_[k];iov_iter_zero_[k] 6 518*387f9dfdSAndroid Build Coastguard Workerdd;read 15 519*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];__vfs_read_[k];read_iter_zero_[k];iov_iter_zero_[k];__clear_user_[k] 19 520*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];__write;-;entry_SYSCALL_64_fastpath_[k] 20 521*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k] 23 522*387f9dfdSAndroid Build Coastguard Workerdd;read;-;entry_SYSCALL_64_fastpath_[k];SyS_read_[k];vfs_read_[k];__vfs_read_[k];read_iter_zero_[k];iov_iter_zero_[k];__clear_user_[k] 24 523*387f9dfdSAndroid Build Coastguard Workerdd;__write;-;entry_SYSCALL_64_fastpath_[k] 25 524*387f9dfdSAndroid Build Coastguard Workerdd;__write 29 525*387f9dfdSAndroid Build Coastguard Workerdd;[unknown];read;-;entry_SYSCALL_64_fastpath_[k] 31 526*387f9dfdSAndroid Build Coastguard Worker 527*387f9dfdSAndroid Build Coastguard WorkerThis can be made into a flamegraph. Eg: 528*387f9dfdSAndroid Build Coastguard Worker 529*387f9dfdSAndroid Build Coastguard Worker# ./profile -adf -p `pgrep -n func_ab` 10 > out.profile 530*387f9dfdSAndroid Build Coastguard Worker# git clone https://github.com/brendangregg/FlameGraph 531*387f9dfdSAndroid Build Coastguard Worker# ./FlameGraph/flamegraph.pl --color=java < out.profile > out.svg 532*387f9dfdSAndroid Build Coastguard Worker 533*387f9dfdSAndroid Build Coastguard WorkerIt will highlight the kernel frames in orange, and user-level in red (and Java 534*387f9dfdSAndroid Build Coastguard Workerin green, and C++ in yellow). If you copy-n-paste the above output into a 535*387f9dfdSAndroid Build Coastguard Workerout.profile file, you can try it out. 536*387f9dfdSAndroid Build Coastguard Worker 537*387f9dfdSAndroid Build Coastguard Worker 538*387f9dfdSAndroid Build Coastguard WorkerYou can increase or decrease the sample frequency. Eg, sampling at 9 Hertz: 539*387f9dfdSAndroid Build Coastguard Worker 540*387f9dfdSAndroid Build Coastguard Worker# ./profile -F 9 541*387f9dfdSAndroid Build Coastguard WorkerSampling at 9 Hertz of all threads by user + kernel stack... Hit Ctrl-C to end. 542*387f9dfdSAndroid Build Coastguard Worker^C 543*387f9dfdSAndroid Build Coastguard Worker 000000000040056a func_b 544*387f9dfdSAndroid Build Coastguard Worker 00000000004005ac main 545*387f9dfdSAndroid Build Coastguard Worker 00007f0458819830 __libc_start_main 546*387f9dfdSAndroid Build Coastguard Worker 083e258d4c544155 [unknown] 547*387f9dfdSAndroid Build Coastguard Worker - func_ab (2930) 548*387f9dfdSAndroid Build Coastguard Worker 1 549*387f9dfdSAndroid Build Coastguard Worker 550*387f9dfdSAndroid Build Coastguard Worker[...] 551*387f9dfdSAndroid Build Coastguard Worker 552*387f9dfdSAndroid Build Coastguard Worker ffffffff8105eb66 native_safe_halt 553*387f9dfdSAndroid Build Coastguard Worker ffffffff8103659e default_idle 554*387f9dfdSAndroid Build Coastguard Worker ffffffff81036d1f arch_cpu_idle 555*387f9dfdSAndroid Build Coastguard Worker ffffffff810bba5a default_idle_call 556*387f9dfdSAndroid Build Coastguard Worker ffffffff810bbd07 cpu_startup_entry 557*387f9dfdSAndroid Build Coastguard Worker ffffffff8104df55 start_secondary 558*387f9dfdSAndroid Build Coastguard Worker - swapper/3 (0) 559*387f9dfdSAndroid Build Coastguard Worker 8 560*387f9dfdSAndroid Build Coastguard Worker 561*387f9dfdSAndroid Build Coastguard Worker ffffffff8105eb66 native_safe_halt 562*387f9dfdSAndroid Build Coastguard Worker ffffffff8103659e default_idle 563*387f9dfdSAndroid Build Coastguard Worker ffffffff81036d1f arch_cpu_idle 564*387f9dfdSAndroid Build Coastguard Worker ffffffff810bba5a default_idle_call 565*387f9dfdSAndroid Build Coastguard Worker ffffffff810bbd07 cpu_startup_entry 566*387f9dfdSAndroid Build Coastguard Worker ffffffff817bf497 rest_init 567*387f9dfdSAndroid Build Coastguard Worker ffffffff81d65f58 start_kernel 568*387f9dfdSAndroid Build Coastguard Worker ffffffff81d652db x86_64_start_reservations 569*387f9dfdSAndroid Build Coastguard Worker ffffffff81d65418 x86_64_start_kernel 570*387f9dfdSAndroid Build Coastguard Worker - swapper/0 (0) 571*387f9dfdSAndroid Build Coastguard Worker 8 572*387f9dfdSAndroid Build Coastguard Worker 573*387f9dfdSAndroid Build Coastguard Worker 574*387f9dfdSAndroid Build Coastguard WorkerYou can also restrict profiling to just kernel stacks (-K) or user stacks (-U). 575*387f9dfdSAndroid Build Coastguard WorkerFor example, just user stacks: 576*387f9dfdSAndroid Build Coastguard Worker 577*387f9dfdSAndroid Build Coastguard Worker# ./profile -U 578*387f9dfdSAndroid Build Coastguard WorkerSampling at 49 Hertz of all threads by user stack... Hit Ctrl-C to end. 579*387f9dfdSAndroid Build Coastguard Worker^C 580*387f9dfdSAndroid Build Coastguard Worker 0000000000402ccc [unknown] 581*387f9dfdSAndroid Build Coastguard Worker 00007f45a624422c [unknown] 582*387f9dfdSAndroid Build Coastguard Worker - dd (2931) 583*387f9dfdSAndroid Build Coastguard Worker 1 584*387f9dfdSAndroid Build Coastguard Worker 585*387f9dfdSAndroid Build Coastguard Worker 0000000000404b80 [unknown] 586*387f9dfdSAndroid Build Coastguard Worker 00007f45a624422c [unknown] 587*387f9dfdSAndroid Build Coastguard Worker - dd (2931) 588*387f9dfdSAndroid Build Coastguard Worker 1 589*387f9dfdSAndroid Build Coastguard Worker 590*387f9dfdSAndroid Build Coastguard Worker 0000000000404d77 [unknown] 591*387f9dfdSAndroid Build Coastguard Worker 00007f45a624422c [unknown] 592*387f9dfdSAndroid Build Coastguard Worker - dd (2931) 593*387f9dfdSAndroid Build Coastguard Worker 1 594*387f9dfdSAndroid Build Coastguard Worker 595*387f9dfdSAndroid Build Coastguard Worker 00007f45a5e85e5e [unknown] 596*387f9dfdSAndroid Build Coastguard Worker 00007f45a624422c [unknown] 597*387f9dfdSAndroid Build Coastguard Worker - dd (2931) 598*387f9dfdSAndroid Build Coastguard Worker 1 599*387f9dfdSAndroid Build Coastguard Worker 600*387f9dfdSAndroid Build Coastguard Worker 0000000000402d12 [unknown] 601*387f9dfdSAndroid Build Coastguard Worker 00007f45a624422c [unknown] 602*387f9dfdSAndroid Build Coastguard Worker - dd (2931) 603*387f9dfdSAndroid Build Coastguard Worker 1 604*387f9dfdSAndroid Build Coastguard Worker 605*387f9dfdSAndroid Build Coastguard Worker 0000000000400562 func_b 606*387f9dfdSAndroid Build Coastguard Worker 00000000004005ac main 607*387f9dfdSAndroid Build Coastguard Worker 00007f0458819830 __libc_start_main 608*387f9dfdSAndroid Build Coastguard Worker 083e258d4c544155 [unknown] 609*387f9dfdSAndroid Build Coastguard Worker - func_ab (2930) 610*387f9dfdSAndroid Build Coastguard Worker 1 611*387f9dfdSAndroid Build Coastguard Worker 612*387f9dfdSAndroid Build Coastguard Worker 0000000000404805 [unknown] 613*387f9dfdSAndroid Build Coastguard Worker - dd (2931) 614*387f9dfdSAndroid Build Coastguard Worker 1 615*387f9dfdSAndroid Build Coastguard Worker 616*387f9dfdSAndroid Build Coastguard Worker 00000000004047de [unknown] 617*387f9dfdSAndroid Build Coastguard Worker - dd (2931) 618*387f9dfdSAndroid Build Coastguard Worker 1 619*387f9dfdSAndroid Build Coastguard Worker 620*387f9dfdSAndroid Build Coastguard Worker 0000000000400542 func_a 621*387f9dfdSAndroid Build Coastguard Worker 0000000000400598 main 622*387f9dfdSAndroid Build Coastguard Worker 00007f0458819830 __libc_start_main 623*387f9dfdSAndroid Build Coastguard Worker 083e258d4c544155 [unknown] 624*387f9dfdSAndroid Build Coastguard Worker - func_ab (2930) 625*387f9dfdSAndroid Build Coastguard Worker 3 626*387f9dfdSAndroid Build Coastguard Worker 627*387f9dfdSAndroid Build Coastguard Worker 00007f45a5edda10 __write 628*387f9dfdSAndroid Build Coastguard Worker 00007f45a624422c [unknown] 629*387f9dfdSAndroid Build Coastguard Worker - dd (2931) 630*387f9dfdSAndroid Build Coastguard Worker 3 631*387f9dfdSAndroid Build Coastguard Worker 632*387f9dfdSAndroid Build Coastguard Worker 000000000040053a func_a 633*387f9dfdSAndroid Build Coastguard Worker 0000000000400598 main 634*387f9dfdSAndroid Build Coastguard Worker 00007f0458819830 __libc_start_main 635*387f9dfdSAndroid Build Coastguard Worker 083e258d4c544155 [unknown] 636*387f9dfdSAndroid Build Coastguard Worker - func_ab (2930) 637*387f9dfdSAndroid Build Coastguard Worker 4 638*387f9dfdSAndroid Build Coastguard Worker 639*387f9dfdSAndroid Build Coastguard Worker 000000000040056a func_b 640*387f9dfdSAndroid Build Coastguard Worker 00000000004005ac main 641*387f9dfdSAndroid Build Coastguard Worker 00007f0458819830 __libc_start_main 642*387f9dfdSAndroid Build Coastguard Worker 083e258d4c544155 [unknown] 643*387f9dfdSAndroid Build Coastguard Worker - func_ab (2930) 644*387f9dfdSAndroid Build Coastguard Worker 7 645*387f9dfdSAndroid Build Coastguard Worker 646*387f9dfdSAndroid Build Coastguard Worker - swapper/6 (0) 647*387f9dfdSAndroid Build Coastguard Worker 10 648*387f9dfdSAndroid Build Coastguard Worker 649*387f9dfdSAndroid Build Coastguard Worker 0000000000400571 func_b 650*387f9dfdSAndroid Build Coastguard Worker 00000000004005ac main 651*387f9dfdSAndroid Build Coastguard Worker 00007f0458819830 __libc_start_main 652*387f9dfdSAndroid Build Coastguard Worker 083e258d4c544155 [unknown] 653*387f9dfdSAndroid Build Coastguard Worker - func_ab (2930) 654*387f9dfdSAndroid Build Coastguard Worker 10 655*387f9dfdSAndroid Build Coastguard Worker 656*387f9dfdSAndroid Build Coastguard Worker 00007f45a5edda10 __write 657*387f9dfdSAndroid Build Coastguard Worker - dd (2931) 658*387f9dfdSAndroid Build Coastguard Worker 10 659*387f9dfdSAndroid Build Coastguard Worker 660*387f9dfdSAndroid Build Coastguard Worker 0000000000400549 func_a 661*387f9dfdSAndroid Build Coastguard Worker 0000000000400598 main 662*387f9dfdSAndroid Build Coastguard Worker 00007f0458819830 __libc_start_main 663*387f9dfdSAndroid Build Coastguard Worker 083e258d4c544155 [unknown] 664*387f9dfdSAndroid Build Coastguard Worker - func_ab (2930) 665*387f9dfdSAndroid Build Coastguard Worker 11 666*387f9dfdSAndroid Build Coastguard Worker 667*387f9dfdSAndroid Build Coastguard Worker 00007f45a5edd9b0 read 668*387f9dfdSAndroid Build Coastguard Worker - dd (2931) 669*387f9dfdSAndroid Build Coastguard Worker 12 670*387f9dfdSAndroid Build Coastguard Worker 671*387f9dfdSAndroid Build Coastguard Worker 00007f45a5edd9b0 read 672*387f9dfdSAndroid Build Coastguard Worker 00007f45a624422c [unknown] 673*387f9dfdSAndroid Build Coastguard Worker - dd (2931) 674*387f9dfdSAndroid Build Coastguard Worker 14 675*387f9dfdSAndroid Build Coastguard Worker 676*387f9dfdSAndroid Build Coastguard Worker - swapper/7 (0) 677*387f9dfdSAndroid Build Coastguard Worker 46 678*387f9dfdSAndroid Build Coastguard Worker 679*387f9dfdSAndroid Build Coastguard Worker - swapper/0 (0) 680*387f9dfdSAndroid Build Coastguard Worker 46 681*387f9dfdSAndroid Build Coastguard Worker 682*387f9dfdSAndroid Build Coastguard Worker - swapper/2 (0) 683*387f9dfdSAndroid Build Coastguard Worker 46 684*387f9dfdSAndroid Build Coastguard Worker 685*387f9dfdSAndroid Build Coastguard Worker - swapper/1 (0) 686*387f9dfdSAndroid Build Coastguard Worker 46 687*387f9dfdSAndroid Build Coastguard Worker 688*387f9dfdSAndroid Build Coastguard Worker - swapper/3 (0) 689*387f9dfdSAndroid Build Coastguard Worker 46 690*387f9dfdSAndroid Build Coastguard Worker 691*387f9dfdSAndroid Build Coastguard Worker - swapper/4 (0) 692*387f9dfdSAndroid Build Coastguard Worker 46 693*387f9dfdSAndroid Build Coastguard Worker 694*387f9dfdSAndroid Build Coastguard Worker 695*387f9dfdSAndroid Build Coastguard WorkerIf there are too many unique stack traces for the kernel to save, a warning 696*387f9dfdSAndroid Build Coastguard Workerwill be printed. Eg: 697*387f9dfdSAndroid Build Coastguard Worker 698*387f9dfdSAndroid Build Coastguard Worker# ./profile 699*387f9dfdSAndroid Build Coastguard Worker[...] 700*387f9dfdSAndroid Build Coastguard WorkerWARNING: 8 stack traces could not be displayed. Consider increasing --stack-storage-size. 701*387f9dfdSAndroid Build Coastguard Worker 702*387f9dfdSAndroid Build Coastguard WorkerRun ./profile -h to see the default. 703*387f9dfdSAndroid Build Coastguard Worker 704*387f9dfdSAndroid Build Coastguard Worker 705*387f9dfdSAndroid Build Coastguard WorkerThere is a -S option to skip kernel frames. You probably don't need to mess 706*387f9dfdSAndroid Build Coastguard Workerwith this. Here's why it exists: consider the following kernel stack trace, 707*387f9dfdSAndroid Build Coastguard Workerand IP: 708*387f9dfdSAndroid Build Coastguard Worker 709*387f9dfdSAndroid Build Coastguard Worker ffffffff81174e78 perf_swevent_hrtimer 710*387f9dfdSAndroid Build Coastguard Worker ffffffff810e6984 __hrtimer_run_queues 711*387f9dfdSAndroid Build Coastguard Worker ffffffff810e70f8 hrtimer_interrupt 712*387f9dfdSAndroid Build Coastguard Worker ffffffff81022c69 xen_timer_interrupt 713*387f9dfdSAndroid Build Coastguard Worker ffffffff810d2942 handle_irq_event_percpu 714*387f9dfdSAndroid Build Coastguard Worker ffffffff810d62da handle_percpu_irq 715*387f9dfdSAndroid Build Coastguard Worker ffffffff810d1f52 generic_handle_irq 716*387f9dfdSAndroid Build Coastguard Worker ffffffff814a5137 evtchn_2l_handle_events 717*387f9dfdSAndroid Build Coastguard Worker ffffffff814a2853 __xen_evtchn_do_upcall 718*387f9dfdSAndroid Build Coastguard Worker ffffffff814a4740 xen_evtchn_do_upcall 719*387f9dfdSAndroid Build Coastguard Worker ffffffff817cd50c xen_hvm_callback_vector 720*387f9dfdSAndroid Build Coastguard Worker ffffffff8103663e default_idle 721*387f9dfdSAndroid Build Coastguard Worker ffffffff81036dbf arch_cpu_idle 722*387f9dfdSAndroid Build Coastguard Worker ffffffff810bb8ea default_idle_call 723*387f9dfdSAndroid Build Coastguard Worker ffffffff810bbb97 cpu_startup_entry 724*387f9dfdSAndroid Build Coastguard Worker ffffffff8104df85 start_secondary 725*387f9dfdSAndroid Build Coastguard Worker 726*387f9dfdSAndroid Build Coastguard WorkerIP: ffffffff8105eb66 native_safe_halt 727*387f9dfdSAndroid Build Coastguard Worker 728*387f9dfdSAndroid Build Coastguard WorkerThis is the idle thread. The first function is native_safe_halt(), and its 729*387f9dfdSAndroid Build Coastguard Workerparent is default_idle(). But what you see there is really what we are 730*387f9dfdSAndroid Build Coastguard Workerprofiling. All that stuff above default_idle()? Interrupt framework stack. 731*387f9dfdSAndroid Build Coastguard Worker 732*387f9dfdSAndroid Build Coastguard WorkerSo we have to exclude those interrupt frames. I do this by fetching the ret IP 733*387f9dfdSAndroid Build Coastguard Workerfrom the kernel stack, and then scanning for it in user-level: in this case 734*387f9dfdSAndroid Build Coastguard Workerit would be default_idle(). Ok. 735*387f9dfdSAndroid Build Coastguard Worker 736*387f9dfdSAndroid Build Coastguard WorkerIf this doesn't work on your architecture (and your kernel stacks are a 737*387f9dfdSAndroid Build Coastguard Workersingle line, the IP), then you might consider setting a fixed skip count, 738*387f9dfdSAndroid Build Coastguard Workerwhich avoids this ret IP logic. For the above stack, I'd set "-S 11", and 739*387f9dfdSAndroid Build Coastguard Workerit would slice off those 11 interrupt frames nicely. It also does this in 740*387f9dfdSAndroid Build Coastguard Workerkernel context for efficiency. 741*387f9dfdSAndroid Build Coastguard Worker 742*387f9dfdSAndroid Build Coastguard WorkerSo how do you figure out what number to use? 11? 14? 5? Well.. Try "-S 1", 743*387f9dfdSAndroid Build Coastguard Workerand then see how much higher you need to set it. Remember on the real 744*387f9dfdSAndroid Build Coastguard Workerprofile output that the IP line is printed on top of the sliced stack. 745*387f9dfdSAndroid Build Coastguard Worker 746*387f9dfdSAndroid Build Coastguard Worker 747*387f9dfdSAndroid Build Coastguard WorkerUSAGE message: 748*387f9dfdSAndroid Build Coastguard Worker 749*387f9dfdSAndroid Build Coastguard Worker# ./profile -h 750*387f9dfdSAndroid Build Coastguard Workerusage: profile [-h] [-p PID] [-U | -K] [-F FREQUENCY] [-d] [-a] [-f] 751*387f9dfdSAndroid Build Coastguard Worker [--stack-storage-size STACK_STORAGE_SIZE] [-S KERNEL_SKIP] 752*387f9dfdSAndroid Build Coastguard Worker [duration] 753*387f9dfdSAndroid Build Coastguard Worker 754*387f9dfdSAndroid Build Coastguard WorkerProfile CPU stack traces at a timed interval 755*387f9dfdSAndroid Build Coastguard Worker 756*387f9dfdSAndroid Build Coastguard Workerpositional arguments: 757*387f9dfdSAndroid Build Coastguard Worker duration duration of trace, in seconds 758*387f9dfdSAndroid Build Coastguard Worker 759*387f9dfdSAndroid Build Coastguard Workeroptional arguments: 760*387f9dfdSAndroid Build Coastguard Worker -h, --help show this help message and exit 761*387f9dfdSAndroid Build Coastguard Worker -p PID, --pid PID profile this PID only 762*387f9dfdSAndroid Build Coastguard Worker -U, --user-stacks-only 763*387f9dfdSAndroid Build Coastguard Worker show stacks from user space only (no kernel space 764*387f9dfdSAndroid Build Coastguard Worker stacks) 765*387f9dfdSAndroid Build Coastguard Worker -K, --kernel-stacks-only 766*387f9dfdSAndroid Build Coastguard Worker show stacks from kernel space only (no user space 767*387f9dfdSAndroid Build Coastguard Worker stacks) 768*387f9dfdSAndroid Build Coastguard Worker -F FREQUENCY, --frequency FREQUENCY 769*387f9dfdSAndroid Build Coastguard Worker sample frequency, Hertz (default 49) 770*387f9dfdSAndroid Build Coastguard Worker -d, --delimited insert delimiter between kernel/user stacks 771*387f9dfdSAndroid Build Coastguard Worker -a, --annotations add _[k] annotations to kernel frames 772*387f9dfdSAndroid Build Coastguard Worker -f, --folded output folded format, one line per stack (for flame 773*387f9dfdSAndroid Build Coastguard Worker graphs) 774*387f9dfdSAndroid Build Coastguard Worker --stack-storage-size STACK_STORAGE_SIZE 775*387f9dfdSAndroid Build Coastguard Worker the number of unique stack traces that can be stored 776*387f9dfdSAndroid Build Coastguard Worker and displayed (default 2048) 777*387f9dfdSAndroid Build Coastguard Worker -S KERNEL_SKIP, --kernel-skip KERNEL_SKIP 778*387f9dfdSAndroid Build Coastguard Worker skip this many kernel frames (default 3) 779*387f9dfdSAndroid Build Coastguard Worker 780*387f9dfdSAndroid Build Coastguard Workerexamples: 781*387f9dfdSAndroid Build Coastguard Worker ./profile # profile stack traces at 49 Hertz until Ctrl-C 782*387f9dfdSAndroid Build Coastguard Worker ./profile -F 99 # profile stack traces at 99 Hertz 783*387f9dfdSAndroid Build Coastguard Worker ./profile 5 # profile at 49 Hertz for 5 seconds only 784*387f9dfdSAndroid Build Coastguard Worker ./profile -f 5 # output in folded format for flame graphs 785*387f9dfdSAndroid Build Coastguard Worker ./profile -p 185 # only profile threads for PID 185 786*387f9dfdSAndroid Build Coastguard Worker ./profile -U # only show user space stacks (no kernel) 787*387f9dfdSAndroid Build Coastguard Worker ./profile -K # only show kernel space stacks (no user) 788*387f9dfdSAndroid Build Coastguard Worker ./profile -S 11 # always skip 11 frames of kernel stack 789