vendredi 31 décembre 2021

See what takes time in kernel compilation

Makefile projects can be profiled and debugged with the remake project. You need a recent version of remake that supports --profile=json (see --help).

This works with parallel builds as well (I've use -j8 here but use whatever you have).

  • "name" is the makefile target
  • "len" is the duration in seconds


$ cd linux-git
$ mkdir -p json && remake --profile=json --profile-directory=$PWD/json -j8
$ cd json
 
# Look at items sorted by total time (time taken by all dependencies + the recipe length)
$ jq -s '[.[] |.targets[]|select(.recipe!=null)|{ name: .name, len: (.end-.start) }]|sort_by(-.len)' *.json
[
{
"name": "bzImage",
"len": 77.26787257194519
},
{
"name": "vmlinux",
"len": 76.33200693130493
},
{
"name": "arch/x86/kernel/vmlinux.lds",
"len": 75.16884279251099
},
{
"name": "drivers",
"len": 75.013343334198
},
{
"name": "arch/x86/lib/lib.a",
"len": 75.01327657699585
},
....


# Or look at item sorted by recipe time only (without the dependencies)
$ jq -s '[.[] |.targets[]|select(.recipe!=null)|{ name: .name, len: (.end-.recipe) }]|sort_by(-.len)' *json
[
{
"name": "drivers",
"len": 47.737035512924194
},
{
"name": "fs",
"len": 45.02375769615173
},
{
"name": "net",
"len": 40.28609848022461
},
{
"name": "net/ipv4",
"len": 31.197179794311523
},
...