简体   繁体   English

对Linux Bash脚本进行基准测试

[英]Benchmark a linux Bash script

Is there a way to benchmark a bash script's performance? 有没有办法对bash脚本的性能进行基准测试? the script downloads a remote file, and then makes calls to multiple commandline programs to manipulate. 该脚本下载远程文件,然后调用多个命令行程序进行操作。 I would like to know (or as much as possible): 我想知道(或尽可能多):

  • Total time 总时间
    • Time spent downloading 下载时间
    • Time spent on each command called 花在每个命令上的时间称为
    • -=[ I think these could be wrapped in "time" calls right? - = [我认为这些可以包含在“时间”通话中吗? ]=- ] = -
  • Average download speed 平均下载速度
    • uses wget 使用wget
  • Total Memory used 使用的总内存
  • Total CPU usage 总CPU使用率
    • CPU usage per command called 每个命令调用的CPU使用率

I'm able to make edits to the bash script to insert any benchmark commands needed at specific points (ie, between app calls). 我能够对bash脚本进行编辑,以插入特定点所需的任何基准命令(即应用程序调用之间)。 Not sure if some "top" ninja-ry could solve this or not. 不确定一些“顶级”忍者是否可以解决这个问题。 Not able to find anything useful (at least to limited understanding) in man file. 在man文件中找不到任何有用的东西(至少是有限的理解)。

Will be running the benchmarks on OSX Terminal as well as Ubuntu (if either matter). 将在OSX终端以及Ubuntu上运行基准测试(如果有任何问题)。

strace -o trace -c -Ttt ./scrip
  1. -c is to trace the time spent by cpu on specific call. -c用于跟踪cpu在特定调用上花费的时间。
  2. -Ttt will tell you time in microseconds at time of each system call running. -Ttt将告诉您每次系统调用运行时的时间(以微秒为单位)。
  3. -o will save output in file "trace". -o将输出保存在文件“trace”中。

You should be able to achieve this a number of ways. 你应该能够通过多种方式实现这一目标。 One way is to use time built-in function for each command of interest and capture the results. 一种方法是为每个感兴趣的命令使用time内置函数并捕获结果。 You may have to be careful about any pipes and redirects; 您可能必须小心任何管道和重定向;

You may also consider trapping SIGCHLD, DEBUG, RETURN, ERR and EXIT signals and putting timing information in there, but you may not get some results. 您也可以考虑捕获SIGCHLD,DEBUG,RETURN,ERR和EXIT信号并在其中放置时序信息,但您可能无法得到一些结果。

This concept of CPU usage of each command won't give you any thing useful, all commands use 100% of cpu. 这个命令的CPU使用概念不会给你任何有用的东西,所有命令都使用100%的cpu。 Memory usage is something you can pull out but you should look at 内存使用是你可以提取的,但你应该看看

If you want to get deep process statistics then you would want to use strace... See strace(1) man page for details. 如果您想获得深入的流程统计信息,那么您可能希望使用strace ...有关详细信息,请参阅strace(1)手册页。 I doubt that -Ttt as it is suggest elsewhere is useful all that tells you are system call times and you want other process trace info. 我怀疑-Ttt,因为它在其他地方的建议是有用的,所有这些都告诉你系统调用时间,你想要其他进程跟踪信息。

You may also want to see ltrace and dstat tools. 您可能还想查看ltrace和dstat工具。

A similar question is answered here Linux benchmarking tools 这里有一个类似的问题Linux基准测试工具

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

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