首页 文章详情

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

生信宝典 | 295 2021-09-02 15:34 0 0 0
UniSMS (合一短信)

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

time sleep 2

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

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

type time
# 这是bash中的time
time 是 shell 关键字
# 这是系统的time
which time
/usr/bin/time

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

# /usr/bin/time -v command
/usr/bin/time -v STAR --runMode genomeGenerate --runThreadN 10 --genomeDir star_GRCh38 --genomeFastaFiles GRCh38.fa --sjdbGTFfile GRCh38.gtf

返回如下信息:

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

good-icon 0
favorite-icon 0
收藏
回复数量: 0
    暂无评论~~
    Ctrl+Enter