Skip to content

Commit

Permalink
updated docs for timeit
Browse files Browse the repository at this point in the history
  • Loading branch information
seanshahkarami committed Dec 10, 2021
1 parent 65a2b85 commit 80a9efd
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions docs/writing-a-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,28 @@ camera = Camera(format=BGR)
camera = ImageFolder(format=BGR)
```

### Advanced: Timing a block

The Plugin class provides a simple utility for timing how long a block of code takes.

The following example shows how we can instrument our code using a typical AI/ML example plugin.

```python
from waggle.plugin import Plugin
with Plugin() as plugin:
with plugin.timeit("plugin.duration.input"):
# get inputs...
with plugin.timeit("plugin.duration.inference"):
# do inference...
with plugin.timeit("plugin.duration.publish"):
# publish results...
```

In the example above, the duration of the input, inference and publish steps are measured and then the plugin publishes the duration in nanoseconds to the name provided to `plugin.timeit` as each block finishes.

## Seeing the internal details

If we run the basic example, the only thing we'll see is the message "publishing a value!" every second. If you need to see more details, pywaggle is designed to easily interface with Python's standard logging module. To enable debug logging, simply make the following additions:
Expand Down

0 comments on commit 80a9efd

Please sign in to comment.