前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Time除了监控程序运行时间还能干这个?

Time除了监控程序运行时间还能干这个?

作者头像
生信宝典
发布2022-01-18 21:02:40
2860
发布2022-01-18 21:02:40
举报
文章被收录于专栏:生信宝典

time是我们比较常用的一个在bash终端监控程序运行的小工具,如

代码语言:javascript
复制
time sleep 2

real    0m2.003s 整个程序运行耗时,从运行开始到运行结束
user    0m0.002s 程序运行过程中用户占用的cpu时间
sys    0m0.001s 程序运行过程中系统占用的CPU时间

那如果我们想监控程序的运行内存怎么办?我们可以调用系统的time,而不是bashtime,什么区别呢?

代码语言:javascript
复制
type time
# 这是bash中的time
time 是 shell 关键字
代码语言:javascript
复制
# 这是系统的time
which time
/usr/bin/time

这时我们通常需要全路径去调用,例如

代码语言:javascript
复制
# /usr/bin/time -v command
/usr/bin/time -v STAR --runMode genomeGenerate --runThreadN 10 --genomeDir star_GRCh38 --genomeFastaFiles GRCh38.fa --sjdbGTFfile GRCh38.gtf

返回如下信息:

代码语言:javascript
复制
Aug 31 16:51:51 ..... started STAR run
Aug 31 16:51:51 ... starting to generate Genome files
Aug 31 16:51:52 ..... processing annotations GTF
Aug 31 16:51:53 ... starting to sort Suffix Array. This may take a long time...
Aug 31 16:51:54 ... sorting Suffix Array chunks and saving them to disk...
Aug 31 16:52:10 ... loading chunks from disk, packing SA...
Aug 31 16:52:13 ... finished generating suffix array
Aug 31 16:52:13 ... generating Suffix Array index
Aug 31 16:52:45 ... completed Suffix Array index
Aug 31 16:52:45 ..... inserting junctions into the genome indices
Aug 31 16:53:05 ... writing Genome to disk ...
Aug 31 16:53:06 ... writing Suffix Array to disk ...
Aug 31 16:53:09 ... writing SAindex to disk
Aug 31 16:53:21 ..... finished successfully

    Command being timed: "STAR --runMode genomeGenerate --runThreadN 10 --genomeDir star_GRCh38 --genomeFastaFiles GRCh38.fa --sjdbGTFfile GRCh38.gtf"
    # 用户占用CPU的时间
    User time (seconds): 191.97
    # 系统占用CPU的时间
    System time (seconds): 11.18
    # 用户额CPU使用率;虽然指定了10个线程,但只达到了双核效率,快了2倍
    Percent of CPU this job got: 223%
    # 程序从开始运行到结束的时间,人为感觉到的运行了多久
    Elapsed (wall clock) time (h:mm:ss or m:ss): 1:30.93 

    # 下面5项未做统计,都给予了0
    Average shared text size (kbytes): 0
    Average unshared data size (kbytes): 0
    Average stack size (kbytes): 0
    Average total size (kbytes): 0
    Average resident set size (kbytes): 0
    # 该进程占用的最大物理内存, 2.3G
    Maximum resident set size (kbytes): 2306644

    # 数据未读入内存,从硬盘读取后缓存入内存
    Major (requiring I/O) page faults: 0
    # 已读入内存缓存区的数据
    Minor (reclaiming a frame) page faults: 2451338

    # 程序自动放弃CPU使用权的次数
    Voluntary context switches: 293

    # 程序被动放弃CPU使用权的次数
    Involuntary context switches: 434
    Swaps: 0

    # 总的读写字符数
    File system inputs: 0
    File system outputs: 6246432
    Socket messages sent: 0
    Socket messages received: 0
    Signals delivered: 0
    Page size (bytes): 4096
    Exit status: 0

有了这个工具,下一步就可以愉快的评估不同的软件、数据量所使用的计算资源多少,进而指导电脑装机了。

References

  1. https://stackoverflow.com/questions/60779173/what-does-maximum-resident-set-size-mean
  2. https://www.gnu.org/software/time/
  3. https://ftp.gnu.org/gnu/time/
  4. https://stackoverflow.com/questions/998517/problem-with-the-gnu-time-command-to-measure-memory-usage
  5. https://superuser.com/questions/480928/is-there-any-command-like-time-but-for-memory-usage
  6. https://stackoverflow.com/questions/131303/how-can-i-measure-the-actual-memory-usage-of-an-application-or-process
  7. https://stackoverflow.com/questions/774556/peak-memory-usage-of-a-linux-unix-process/774601#774601
  8. https://bugzilla.redhat.com/show_bug.cgi?id=702826
  9. https://www.slashroot.in/linux-system-io-monitoring
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2021-09-01,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 生信宝典 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • References
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档