-
Notifications
You must be signed in to change notification settings - Fork 19
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 use 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:
![Screenshot 2024-04-23 at 4 27 18 PM](https://private-user-images.githubusercontent.com/2982494/324985193-7180569f-aca6-4076-b853-1316acc12c4d.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkxNjMyOTcsIm5iZiI6MTczOTE2Mjk5NywicGF0aCI6Ii8yOTgyNDk0LzMyNDk4NTE5My03MTgwNTY5Zi1hY2E2LTQwNzYtYjg1My0xMzE2YWNjMTJjNGQucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIxMCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTBUMDQ0OTU3WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NzA4MzE0MTVmZjk1MzEzNDZlYjZkNjRlNmQxMDUxY2M5NDljODhlZmZhNTAzNTFmM2I5MjZkMGJlNzU1YTljMCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.8u1OTWjghPNYM6HVxQkSg74EzrCL2RIYjaeQSIcScek)
The longer the bar, the longer the time to compile. In the example above, it matches the CLI output for the tall poles.