Creating a decorator to record metrics
A popular thing to do in professional studios is to record how long something takes and how often it happens. This sort of profiling can be useful for tracking things like program startup time, how long it takes to export meshes, or who is using that deprecated tool that should have been killed a long time ago. We will build a decorator to time how long a function takes to execute.
Generally this sort of recording has the following pattern:
- Get a unique key for a callable item.
- Record the time it takes to invoke the callable item.
- Report the time taken to some other system, identifying the callable through the unique key.
This is perfect for a decorator. We use a decorator instead of a context manager because ...