一个运行时步骤分析器-用于python。
totalrecall的Python项目详细描述
totalrecall
a运行时步骤探查器-用于python。
简介
聚合运行时统计信息和/或在代码中发现瓶颈是作为软件工程师最常见的挑战之一。这是一个图书馆来帮助你。与大多数现有的库相比,这一个库集中在^ {STR 1 } $步骤剖析< /强>;在由键/标签/标签和可选元数据标记的步骤中聚合运行时信息,用于创建事务形式的所有步骤的摘要。另外,它还支持装饰代码contexts和^{str1}$functions。
这是一个mvp,很可能会使用更多的分析功能进行扩展。
安装
使用pip安装
非常基本的example: 克隆源代码:$ pip install totalrecall
使用
importtotalrecallfromtimeimportsleep# ---------------------------------------------------# EXAMPLE: runtime step profiler# ------------------------------------------------profiler=totalrecall.timer('profile something - using timer',begin=False)profiler.begin('task 1')sleep(0.1)profiler.begin('task 2')sleep(0.2)profiler.begin('task 3')sleep(0.3)profiler.end()print('[profiler.time / basic]: TIME: {0}'.format(profiler.time))print('[profiler.time / basic]: STEPS: {0}'.format(profiler.steps))# ---------------------------------------------------# EXAMPLE: runtime step profiler (detailed)# ------------------------------------------------profiler=totalrecall.timer('profile something - using timer',begin=False,enabled=True,verbose=True,colors=True,)profiler.begin('task 1')sleep(0.1)profiler.begin('task 2')sleep(0.2)profiler.begin('task 3')sleep(0.3)profiler.end()print('[profiler.time / detailed]: TIME: {0}'.format(profiler.time))print('[profiler.time / detailed]: STEPS: {0}'.format(profiler.steps))# ---------------------------------------------------# EXAMPLE: runtime context profiler# ------------------------------------------------profiler=totalrecall.context('profile something 2 - using context')withprofiler:sleep(1)print('[profiler.context / basic]: TIME: {0}'.format(profiler.time))print('[profiler.context / basic]: STEPS: {0}'.format(profiler.steps))# ---------------------------------------------------# EXAMPLE: runtime function profiler# ------------------------------------------------profiler=totalrecall.function('profile something 2 - using context')@profilerdeffoo():sleep(1)print('[profiler.function / basic]: TIME: {0}'.format(profiler.time))print('[profiler.function / basic]: STEPS: {0}'.format(profiler.steps))
测试
$ make install
<>运行^ ^ {STR 1 } $多彩测试>,只使用本地环境(依赖沙箱向上):
$ make test
使用multi environment(使用tox)运行less colorgy测试:
$ make test-tox
关于
这个项目主要是在缺乏现有的替代方案的情况下使用的,在我们的工作中使用^ {STR 1 } $Markable.ai在各种编程环境之间有共同的代码约定,其中{STR 1 } $ Python (研究,CV,AI)被大量使用。
学分
感谢op-bk对命名此库的创造性帮助。
许可证
在麻省理工学院的许可下发布。