成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

抓狂!這條命令執行完女朋友都跟人跑了!

系統 Linux
對于時間的測試,我們可以用到一個命令:time 。下面我們就詳細看看如何使用 time 命令來對腳本/命令進行測時。

作為程序員,時間是金錢,效率是繩命,萬一遇到產品經理臨時又加需求,我們常常是這個狀態:

[[271707]]

如果是這個狀態,那已經是很好的狀況了。萬一如果因為工作忙碌沒時間陪女朋友,那么就很可能免費獲贈一頂精致的 綠 帽 子……

[[271708]]

其實不僅僅是我們程序員工作忙,很多系統對時間的要求性也非常高。在工作中,還有很多情況下需要測試一個腳本或者程序運行多少時間,特別是對于時間性要求比較高的系統更是如此。

我們在工作中,寫過一個 Shell 腳本,這個腳本可以從 4 個 NTP 服務器輪流獲取時間,然后將最可靠的時間設置為系統時間。

因為我們對于時間的要求比較高,需要在短時間內就獲取到正確的時間。所以我們就需要對這個腳本運行時間進行測試,看看從開始運行到正確設置時間需要花費多少時間。

對于時間的測試,我們可以用到一個命令:time 。下面我們就詳細看看如何使用 time 命令來對腳本/命令進行測時。

[[271709]]

1. time 命令基本用法

time 命令最基本的用法,就是 time + 命令 ,比如:

  1. $ time ping baidu.com 
  2. PING baidu.com (123.125.114.144) 56(84) bytes of data. 
  3. 64 bytes from 123.125.114.144 (123.125.114.144): icmp_seq=1 ttl=56 time=2.83 ms 
  4. 64 bytes from 123.125.114.144 (123.125.114.144): icmp_seq=2 ttl=56 time=2.77 ms 
  5. ………… 
  6. ^C 
  7. --- baidu.com ping statistics --- 
  8. 8 packets transmitted, 8 received, 0% packet loss, time 10818ms 
  9. rtt min/avg/max/mdev = 2.765/2.808/2.862/0.039 ms 
  10.  
  11. real    0m11.173s 
  12. user    0m0.004s 
  13. sys     0m0.002s 

在結果里,real 表示從我們執行 ping 命令到最終按 ctrl+c 終止這段時間所耗費的時間;user 及 sys 分別表示 ping 命令在用戶空間及內核空間所運行的時間。

2. 將時間信息寫入文件

如果我們想把時間信息直接寫入到文件,而不是顯示在屏幕上,那么我們可以使用 -o 選項,并指定寫入的文件路徑。

  1. $ /usr/bin/time -o /home/alvin/time-output.txt ping baidu.com 

執行這個命令后,ping 命令的輸出結果依然會在終端里,而 time 命令的結果就寫入到我們所指定的 time-output.txt 文件里。

-o 選項表示輸出文件不存在就創建,如果存在的話就直接覆蓋重寫。如果我們不想覆蓋重寫,而是想追加在文件后面,我們可以使用 -a 選項。

  1. $ /usr/bin/time -a /home/smart/time-output.txt ping linoxide.com 

[[271710]]

3. 顯示更詳細的時間信息

time 命令不帶選項的話,顯示的信息量比較少,如果我們想獲得更詳細的信息,那么我們可以使用 -v 選項。

  1. $ /usr/bin/time -v ping baidu.com 
  2. PING baidu.com (123.125.114.144) 56(84) bytes of data. 
  3. 64 bytes from 123.125.114.144 (123.125.114.144): icmp_seq=1 ttl=56 time=2.75 ms 
  4. 64 bytes from 123.125.114.144 (123.125.114.144): icmp_seq=2 ttl=56 time=2.76 ms 
  5. 64 bytes from 123.125.114.144 (123.125.114.144): icmp_seq=3 ttl=56 time=2.85 ms 
  6. 64 bytes from 123.125.114.144 (123.125.114.144): icmp_seq=4 ttl=56 time=2.77 ms 
  7. ^C 
  8. --- baidu.com ping statistics --- 
  9. 4 packets transmitted, 4 received, 0% packet loss, time 3300ms 
  10. rtt min/avg/max/mdev = 2.751/2.785/2.851/0.075 ms 
  11.         Command being timed: "ping baidu.com" 
  12.         User time (seconds): 0.00 
  13.         System time (seconds): 0.00 
  14.         Percent of CPU this job got: 0% 
  15.         Elapsed (wall clock) time (h:mm:ss or m:ss): 0:03.64 
  16.         Average shared text size (kbytes): 0 
  17.         Average unshared data size (kbytes): 0 
  18.         Average stack size (kbytes): 0 
  19.         Average total size (kbytes): 0 
  20.         Maximum resident set size (kbytes): 2140 
  21.         Average resident set size (kbytes): 0 
  22.         Major (requiring I/O) page faults: 0 
  23.         Minor (reclaiming a frame) page faults: 626 
  24.         Voluntary context switches: 10 
  25.         Involuntary context switches: 0 
  26.         Swaps: 0 
  27.         File system inputs: 0 
  28.         File system outputs: 0 
  29.         Socket messages sent: 0 
  30.         Socket messages received: 0 
  31.         Signals delivered: 0 
  32.         Page size (bytes): 4096 
  33.         Exit status: 0 

這個結果信息就相當詳細了,我們可以獲取到足夠多我們所需要的信息。

4. 自定義輸出格式

默認情況下,time 命令只輸出 real,usr,sys 三個內容,如果我們想要個性化一些,算定義它的輸出格式,time 命令也是支持的。time 命令支持的格式有很多,如下所示:

  1. C - Name and command line arguments used 
  2. D - Average size of the process's unshared data area in kilobytes 
  3. E - Elapsed time in a clock format 
  4. F - Number of page faults 
  5. I - Number of file system inputs by the process 
  6. K - Average total memory use of the process in kilobytes 
  7. M - Maximum resident set the size of the process during the lifetime in Kilobytes 
  8. O - Number of file system outputs by the process 
  9. P - Percentage of CPU that the job received 
  10. R - Number of minor or recoverable page faults 
  11. S - Total number of CPU seconds used by the system in kernel mode 
  12. U - Total number of CPU seconds used by user mode 
  13. W - Number of times the process was swapped out of main memory 
  14. X - Average amount of shared text in the process 
  15. Z - System's page size in kilobytes 
  16. c - Number of times the process was context-switched 
  17. e - Elapsed real time used by the process in seconds 
  18. k - Number of signals delivered to the process 
  19. p - Average unshared stack size of the process in kilobytes 
  20. r - Number of socket messages received by the process 
  21. s - Number of socket messages sent by the process 
  22. t - Average resident set size of the process in kilobytes 
  23. w - Number of time the process was context-switched voluntarily 
  24. x - Exit status of the command 

如果我們想要輸出以下這樣的格式:

  1. Elapsed Time = 0:01:00, Inputs 2, Outputs 1 

我們可以這樣自定義:

  1. $ /usr/bin/time -f "Elapsed Time = %E, Inputs %I, Outputs %O" ping baidu.com 
  2. PING baidu.com (220.181.38.148) 56(84) bytes of data. 
  3. 64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=1 ttl=54 time=1.82 ms 
  4. 64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=2 ttl=54 time=1.86 ms 
  5. ^C 
  6. --- baidu.com ping statistics --- 
  7. 4 packets transmitted, 4 received, 0% packet loss, time 3003ms 
  8. rtt min/avg/max/mdev = 1.825/1.859/1.879/0.056 ms 
  9. Elapsed Time = 0:03.92, Inputs 0, Outputs 0 

如果你想讓輸出的結果有換行,可以在對應的地方添加 \n ,比如:

  1. $ /usr/bin/time -f "Elapsed Time = %E \n Inputs %I \n Outputs %O" ping baidu.com 

這樣輸出的結果就類似于這樣:

  1. Elapsed Time = 0:03.92 
  2. Inputs 0 
  3. Outputs 0 
責任編輯:趙寧寧 來源: 良許Linux
相關推薦

2018-08-23 13:04:48

Python月薪支出

2015-08-26 10:17:29

程序員女朋友

2020-04-21 11:45:04

技巧單一責任鏈開閉原則

2020-10-15 09:35:27

亂碼UTF-8GBK

2021-10-21 08:31:31

Spring循環依賴面試

2019-03-12 09:43:14

反向代理正向代理服務器

2020-12-14 10:25:08

DNS通信IP

2020-10-21 08:59:50

刪庫程序員虛擬機

2015-08-21 09:48:11

女朋友編程學習編程

2020-09-08 08:55:52

Dubbo服務全鏈路

2020-09-08 08:57:30

區塊鏈

2020-03-18 09:31:47

設計模式軟件

2021-09-06 08:50:49

服務Dubbo參數

2021-04-06 06:23:18

MVCC并發事務

2019-04-09 09:40:23

2019-11-04 10:14:35

區塊鏈幣圈鏈圈

2020-03-04 09:46:25

Linux桌面端服務器

2020-03-16 14:08:59

線程熔斷限流

2012-07-18 02:13:30

文字圖片應用小應用

2020-01-02 09:14:23

Kubernetes內部容器
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 谁有毛片| 欧美一级做性受免费大片免费 | 黑人巨大精品欧美一区二区一视频 | 亚洲欧美自拍偷拍视频 | 日韩一区二区三区四区五区 | 午夜免费观看网站 | 91大片 | 国产亚洲一区精品 | 精品亚洲一区二区 | 亚洲精品中文字幕在线 | 欧美激情欧美激情在线五月 | 久久涩涩 | 亚洲免费精品 | 狠狠爱网址 | 亚洲视频免费一区 | 欧美久久一级特黄毛片 | 高清免费在线 | 精品福利在线视频 | 四虎海外 | a级大片免费观看 | 国产精品夜间视频香蕉 | 在线成人免费视频 | 欧美激情国产日韩精品一区18 | 中文字幕电影在线观看 | 网站国产 | 国产乱人伦 | 福利片在线观看 | 青久草视频 | 区一区二在线观看 | 99综合 | 国产1区2区3区 | 黄视频免费观看 | 欧美亚洲国产日韩 | 亚洲在线久久 | 九九热在线视频 | 一区二区三区视频免费观看 | 国产成人精品一区二区三 | 狠狠操狠狠操 | 国产激情视频 | 成人字幕网zmw | 国内精品一区二区 |