time
是我们比较常用的一个在bash终端监控程序运行的小工具,如
time sleep 2
real 0m2.003s 整个程序运行耗时,从运行开始到运行结束
user 0m0.002s 程序运行过程中用户占用的cpu时间
sys 0m0.001s 程序运行过程中系统占用的CPU时间
那如果我们想监控程序的运行内存怎么办?我们可以调用系统的time
,而不是bash
的time
,什么区别呢?
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
有了这个工具,下一步就可以愉快的评估不同的软件、数据量所使用的计算资源多少,进而指导电脑装机了。