D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
usr
/
sbin
/
Filename :
cpuwalk.bt
back
Copy
#!/usr/bin/env bpftrace // cpuwalk Sample which CPUs are executing processes. // For Linux, uses bpftrace and eBPF. // // Example of usage: // // # ./cpuwalk.bt // Attaching 2 probes... // Sampling CPU at 99hz... Hit Ctrl-C to end. // ^C // // @cpu: // [0, 1) 130 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | // [1, 2) 137 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | // [2, 3) 99 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | // [3, 4) 99 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | // [4, 5) 82 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | // [5, 6) 34 |@@@@@@@@@@@@ | // [6, 7) 67 |@@@@@@@@@@@@@@@@@@@@@@@@ | // [7, 8) 41 |@@@@@@@@@@@@@@@ | // [8, 9) 97 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | // [9, 10) 140 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@| // [10, 11) 105 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | // [11, 12) 77 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | // [12, 13) 39 |@@@@@@@@@@@@@@ | // [13, 14) 58 |@@@@@@@@@@@@@@@@@@@@@ | // [14, 15) 64 |@@@@@@@@@@@@@@@@@@@@@@@ | // [15, 16) 57 |@@@@@@@@@@@@@@@@@@@@@ | // [16, 17) 99 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | // [17, 18) 56 |@@@@@@@@@@@@@@@@@@@@ | // [18, 19) 44 |@@@@@@@@@@@@@@@@ | // [19, 20) 80 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | // [20, 21) 64 |@@@@@@@@@@@@@@@@@@@@@@@ | // [21, 22) 59 |@@@@@@@@@@@@@@@@@@@@@ | // [22, 23) 88 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | // [23, 24) 84 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | // [24, 25) 29 |@@@@@@@@@@ | // [25, 26) 48 |@@@@@@@@@@@@@@@@@ | // [26, 27) 62 |@@@@@@@@@@@@@@@@@@@@@@@ | // [27, 28) 66 |@@@@@@@@@@@@@@@@@@@@@@@@ | // [28, 29) 57 |@@@@@@@@@@@@@@@@@@@@@ | // [29, 30) 59 |@@@@@@@@@@@@@@@@@@@@@ | // [30, 31) 56 |@@@@@@@@@@@@@@@@@@@@ | // [31, 32) 23 |@@@@@@@@ | // [32, 33) 90 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | // [33, 34) 62 |@@@@@@@@@@@@@@@@@@@@@@@ | // [34, 35) 39 |@@@@@@@@@@@@@@ | // [35, 36) 68 |@@@@@@@@@@@@@@@@@@@@@@@@@ | // // This shows that all 36 CPUs were active, with some busier than others. // // // Compare that output to the following workload from an application: // // # ./cpuwalk.bt // Attaching 2 probes... // Sampling CPU at 99hz... Hit Ctrl-C to end. // ^C // // @cpu: // [6, 7) 243 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@| // [7, 8) 0 | | // [8, 9) 0 | | // [9, 10) 0 | | // [10, 11) 0 | | // [11, 12) 0 | | // [12, 13) 0 | | // [13, 14) 0 | | // [14, 15) 0 | | // [15, 16) 0 | | // [16, 17) 0 | | // [17, 18) 0 | | // [18, 19) 0 | | // [19, 20) 0 | | // [20, 21) 1 | | // // In this case, only a single CPU (6) is really active doing work. Only a single // sample was taken of another CPU (20) running a process. If the workload was // supposed to be making use of multiple CPUs, it isn't, and that can be // investigated (application's configuration, number of threads, CPU binding, etc). // // This is a bpftrace version of the DTraceToolkit tool of the same name. // // Copyright 2018 Netflix, Inc. // // 08-Sep-2018 Brendan Gregg Created this. BEGIN { printf("Sampling CPU at 99hz... Hit Ctrl-C to end.\n"); } profile:hz:99 /pid/ { @cpu = lhist(cpu, 0, 1000, 1); }