I am programming some custom samplers (specifically adaptive MALT with manual gradients) for a model in R/C++ and comparing efficiency to Stan. Comparing min(ESS)/second is easy but I also want to compare min(ESS) per gradient evaluation, for which I need to be able to extract the number of leapfrog steps per transition/iteration for each chain for the (Stan variation of) the NUTS sampler.
If the result from the call to $sample() was stored in a variable fit, then type fit$ and rstudio will auto-suggest elements/functions, one of which is hmc_diagnostics(), which acts like draws() in returning the draw by draw HMC diagnostic quantities, including number of leapfrog steps, with options for the return format (df, array, rvar, etc)