Perfwatch is a python package that allows you to monitor the performance of your code. It is designed to be used in a Jupyter notebook, but can also be used in a Python script.
To install perfwatch, run the following command:
pip install perfwatch
To install perfwatch for development, clone the repository and run the following command:
poetry install
To setup pre-commit hooks, run the following command:
poetry run pre-commit install
To run the tests, run the following command:
poetry run pytest
The profiler supports the following profiler types:
cpu
: Profiles CPU usage using thecProfile
module.memory
: Profiles memory usage using thememory_profiler
module.thread
: Profiles thread creation and usage.io
: Profiles I/O operations.network
: Profiles network traffic using theNetworkProfiler
class.gpu
: Profiles GPU usage using theGPUProfiler
class.cache
: Profiles cache performance (not implemented).exception
: Profiles exception handling (not implemented).system
: Profiles system performance (not implemented).distributed
: Profiles distributed system performance (not implemented).line
: Profiles line-by-line execution using theline_profiler
module.time
: Profiles execution time.
from perfwatch import watch
@watch(["line", "cpu", "time"])
def test():
for _ in range(1000000):
pass
if __name__ == "__main__":
test()
You can customize the profiling behavior by passing additional keyword arguments to the watch
decorator. For example:
@watch("network", packet_src="localhost")
def my_function(x, y):
# function implementation
pass
The Profiler Service uses a logger to output profiling results. You can specify a log file path using the log_file_path keyword argument:
@watch("cpu", log_file_path="profiling.log")
def my_function(x, y):
# function implementation
pass
This project is licensed under the MIT License - see the LICENSE file for details.