O'Reilly logo

Practical Maya Programming with Python by Robert Galanakis

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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:

  1. Get a unique key for a callable item.
  2. Record the time it takes to invoke the callable item.
  3. 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required