Agnostic_baker: Add profiling
What
Parent MR: !16968 (merged)
We plug the profiler in the agnostic baker with this MR.
Why
To showcase that the agnostic baker logic does not add sensible overhead to the baking mechanism.
How
By creating an agnostic baker profiler (independent of the protocol code of course) which outputs in the same client directory (it made sense to put it there since this is where baking_profiling is located) and by profiling all calls that could be costly (RPC ones + retrieving protocol plugin + stopping/spawning bakers).
I decided to profile everything as Notice as there is not a lot of calls being made anyways.
Manually testing the MR
To showcase the interesting part, which is when we have a protocol migration, one can tweak the tezt code a bit:
- in
tezt/lib_tezos/agnostic_baker.mlrunfunction, add the environment variables meant to trigger profiling (PROFILING=Debug PROFILING_BACKEND=txt) by adding the~envparameter to the daemonrunfunction at the end:
run
~env:
(String_map.of_list
[("PROFILING", "Debug"); ("PROFILING_BACKEND", "txt")])
?event_level
?event_sections_levels
agnostic_baker
{ready = false}
arguments
~on_terminate
?runner
Now, go to any of the tests from tezt/tests/protocol_migration.ml or tezt/tests/agnostic_baker_test.ml and add a big sleep to the tests and then while the tests are running, go into the client directories used by the agnostic bakers to get the profiling reports. This is what I got for the protocol_migration one:
TEZOS_PPX_PROFILER=profiling make
dune exec tezt/tests/main.exe -- --file protocol_migration.ml -v --title 'agnostic baker forked migration blocks from r022 to alpha'
As you can see, the resources needed are very small (not impactful at all).
This is what I got for the agnostic_baker_test.ml:
2025-03-21T13:45:54.016-00:00
BLiu1Nb7fvEPviHUJfhxXLdvKfDAN5wL7LvBPqcrBLYCKMLNWmU ............................ 1 1000.299ms 4%
get_current_period ........................................................... 1 1.378ms 135%
maybe_kill_old_baker ......................................................... 1 0.001ms 210%
get_next_protocol_hash ....................................................... 1 1.890ms 43%
get_block_hash ............................................................... 1 2.175ms 28%
2025-03-21T13:45:55.016-00:00
BLMuNk2XT7bxxNBV2pkF467Sp2HwjEbSNjPNXDyRM8Ro5K55nqB ............................ 1 998.101ms 5%
get_current_period ........................................................... 1 1.053ms 31%
maybe_kill_old_baker ......................................................... 1 0.002ms 94%
get_next_protocol_hash ....................................................... 1 1.691ms 44%
get_level .................................................................... 1 0.558ms 30%
hot_swap_baker ............................................................... 1 1.293ms 115%
proto_plugin_for_protocol .................................................. 1 0.003ms 162%
get_block_hash ............................................................... 1 1.417ms 130%
2025-03-21T13:45:56.015-00:00
BLzozs8odZznq9RNayrXPbL5EB4vWwoPwcmJFm2QLprWE59eTEV ............................ 1 1003.608ms 4%
get_current_period ........................................................... 1 2.235ms 36%
maybe_kill_old_baker ......................................................... 1 2.763ms 72%
get_level .................................................................. 1 2.761ms 72%
get_next_protocol_hash ....................................................... 1 2.167ms 26%
get_block_hash ............................................................... 1 3.035ms 107%
2025-03-21T13:45:57.018-00:00
BKx2DQHrYszPmBRXCR5Sdm4JPnros2HMauVXXAWAwHWWTyqyRjR ............................ 1 1002.172ms 6%
get_current_period ........................................................... 1 5.969ms 104%
maybe_kill_old_baker ......................................................... 1 3.380ms 57%
get_level .................................................................. 1 3.376ms 57%
get_next_protocol_hash ....................................................... 1 2.289ms 32%
get_block_hash ............................................................... 1 4.110ms 107%
2025-03-21T13:45:58.020-00:00
BMctQ4DsgRc8yyf1ozxuCASDu3yfm9c5tpBbUCy3vsbFaWEY42V ............................ 1 1010.376ms 7%
get_current_period ........................................................... 1 3.797ms 103%
maybe_kill_old_baker ......................................................... 1 3.918ms 76%
get_level .................................................................. 1 2.261ms 61%
kill old baker ............................................................. 1 1.053ms 96%
get_next_protocol_hash ....................................................... 1 2.843ms 109%
get_block_hash ............................................................... 1 6.115ms 69%
2025-03-21T13:45:59.031-00:00
BKsJdp8kEG1kebMKkPFPKdHNSw5mbjUfp7ufbqEm7SNmu42HoAp ............................ 1 1001.792ms 5%
get_current_period ........................................................... 1 2.934ms 80%
maybe_kill_old_baker ......................................................... 1 0.001ms 210%
get_next_protocol_hash ....................................................... 1 1.267ms 119%
get_block_hash ............................................................... 1 7.764ms 77%
Checklist
-
Document the interface of any function added or modified (see the coding guidelines) -
Document any change to the user interface, including configuration parameters (see node configuration) -
Provide automatic testing (see the testing guide). -
For new features and bug fixes, add an item in the appropriate changelog ( docs/protocols/alpha.rstfor the protocol and the environment,CHANGES.rstat the root of the repository for everything else). -
Select suitable reviewers using the Reviewersfield below. -
Select as Assigneethe next person who should take action on that MR