Counting customized likelihood (or its gradient) being evaluated

Is there any build-in function of counting how many times of customized likelihood (or its gradient) being evaluated? What is the efficient way to achieve this? I have seen a similar post but cannot fully understand.

It’s a bit hard to say, it depending on what sampler you are using, what is the implementation of custom likelihood etc. I think in NUTS it is usually evaluate once or twice per sample.