-
Notifications
You must be signed in to change notification settings - Fork 18
Profiling MAPL Builds
Profiling MAPL builds is fairly simple but requires a non-standard build, namely a Ninja build. First, clone MAPL per usual:
mepo clone [email protected]:GEOS-ESM/MAPL.git
and checkout your favorite branch. Then run CMake:
cmake -B build -S . --install-prefix=$(pwd)/install -DCMAKE_BUILD_TYPE=Debug -G Ninja
Then you can build and install with:
cmake --build build --target install -j 8
To look at the build times on the CLI, you can use this script:
#!/usr/bin/env gawk -f
!/^#/ {
TIMES[$4] += ($2 - $1)/1000
COUNT[$4] += 1
}
END {
for (TGT in TIMES)
AVG[TGT]=TIMES[TGT]/COUNT[TGT]
asorti(AVG, SORTED, "@val_num_desc")
for (num in SORTED)
print AVG[SORTED[num]] " " SORTED[num]
}
If saved as show-ninja-build-stats
, you can run:
$ show-ninja-build-stats build/.ninja_log | grep -v 'mod$' | head
34.786 gridcomps/ExtData2G/CMakeFiles/MAPL.ExtData2G.dir/ExtDataGridCompNG.F90.o
33.706 base/CMakeFiles/MAPL.base.dir/Base.F90.o
28.799 gridcomps/History/CMakeFiles/MAPL.history.dir/MAPL_HistoryGridComp.F90.o
25.658 Apps/CMakeFiles/Regrid_Util.x.dir/Regrid_Util.F90.o
25.497 gridcomps/ExtData/CMakeFiles/MAPL.ExtData.dir/ExtDataGridCompMod.F90.o
20.136 gridcomps/History/CMakeFiles/MAPL.history.dir/MAPL_HistoryCollection.F90.o
15.395 gridcomps/History/CMakeFiles/MAPL.history.dir/Sampler/MAPL_EpochSwathMod.F90.o
14.97 base/CMakeFiles/MAPL.base.dir/MAPL_CFIO.F90.o
14.644 generic/CMakeFiles/MAPL.generic.dir/MAPL_Generic.F90.o
13.423 gridcomps/History/CMakeFiles/MAPL.history.dir/Sampler/MAPL_TrajectoryMod_smod.F90.o
These are the top 10 files in time of compilation.
To get the profile trace, we will rely on the ninjatracing code by @nico:
https://github.com/nico/ninjatracing
This code can convert .ninja_log
files into a format that can be read by Chromium's trace format.
If you don't already have it, clone the repo and then run:
ninjatracing build/.ninja_log > trace.json
or wherever your build from above is.
To display the trace, copy your JSON file to your local machine, go to https://ui.perfetto.dev/ and click "Open Trace File". Navigate to your trace file and open it. You'll see something like:
The longer the bar, the longer the time to compile. In the example above, it matches the CLI output for the tall poles.