Use sampling rate for timing + code cleanup

This adds sampling support for timer metrics.

I also got rid of the code to use a dynamic buffer to store the metric and opted to use a stack variable. I think it makes the code cleaner without sacrificing any performance.