简体   繁体   English

在每个任务中分析python fabric命令

[英]Profiling python fabric commands in each task

How can I profile python fabric? 我该如何描述python结构? I need to know which command in a task takes most time. 我需要知道任务中的哪个命令占用大部分时间。

Say I have a fabfile.py which has 1 task. 假设我有一个fabfile.py,它有1个任务。 To perform this it passess 10 commands though ssh. 为了执行此操作,它通过ssh传递10个命令。 When I run, it should output the time each command took and sort it. 当我运行时,它应该输出每个命令所花费的时间并对其进行排序。

I searched the fabric documentation. 我搜索了结构文档。 Didn't find any way to write plugin/hook etc. 没有找到任何方法来编写插件/钩子等。

You can use time 你可以用time

for task level duration: 任务级别持续时间:

$time fab command

for command level duration time can be injected in task definition: 对于命令级持续time可以在任务定义中注入:

def status():
""" Is our app live? """
sudo("time forever list")

Apart from that the trivial time duration can be decorated 除此之外,可以装饰琐碎的持续时间

    from timeit import default_timer as timer

    start = timer()
    # ...run('run a command')
    end = timer()
    print(end - start)

Theres hardly any support from fabric wiki and project regarding this, but will be a exciting add-on to develop. 几乎没有来自面料维基和项目的任何支持,但这将是一个令人兴奋的开发附加组件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM