Tracing code

When talking about tracing in this section, we will refer to something more general that has to do with dealing with the execution of a function that we wish to monitor. This could refer to scenarios in which we want to:

  • Actually trace the execution of a function (for example, by logging the lines it executes)
  • Monitor some metrics over a function (such as CPU usage or memory footprint)
  • Measure the running time of a function
  • Log when a function was called, and the parameters that were passed to it

In the next section, we will explore a simple example of a decorator that logs the execution of a function, including its name and the time it took to run.

Get Clean Code in Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.