Minha resposta é sobre o Linux.
- Which rule prevents it from timing other things?
Eu acho que ele obtém informação de tempo apenas para processos, já que ele realmente usa a chamada de sistema wait4
para obter esta informação de tempo . O primeiro parâmetro de wait4
é o pid de um processo. Então, /usr/bin/time
sempre chama execve
e depois wait4.
A propósito:
execve() executes the program pointed to by filename. filename must be either a binary executable, or a script starting with a line of the form: #! interpreter [optional-arg]
Então / usr / bin / time precisa de algo que possa ser executado por execve
- Can the Bash's reserved word time time all the things that can run?
Eu acho que sim. É implementado como dois grupos de chamadas:
10:06:03 getrusage(RUSAGE_SELF, {ru_utime={0, 152976}, ru_stime={0, 465929}, ru_maxrss=4052, ru_ixrss=0, ru_idrss=0, ru_isrss=0, ru_minflt=6214, ru_majflt=1, ru_nswap=0, ru_inblock=368, ru_oublock=0, ru_msgsnd=0, ru_msgrcv=0, ru_nsignals=0, ru_nvcsw=6349, ru_nivcsw=12}) = 0
10:06:03 getrusage(RUSAGE_CHILDREN, {ru_utime={2, 259656}, ru_stime={1, 888712}, ru_maxrss=21176, ru_ixrss=0, ru_idrss=0, ru_isrss=0, ru_minflt=64297, ru_majflt=4, ru_nswap=0, ru_inblock=272, ru_oublock=368, ru_msgsnd=0, ru_msgrcv=0, ru_nsignals=0, ru_nvcsw=56077, ru_nivcsw=386}) = 0
executar um comando ou builtin
10:06:04 getrusage(RUSAGE_SELF, {ru_utime={0, 152976}, ru_stime={0, 476927}, ru_maxrss=4052, ru_ixrss=0, ru_idrss=0, ru_isrss=0, ru_minflt=6243, ru_majflt=1, ru_nswap=0, ru_inblock=368, ru_oublock=0, ru_msgsnd=0, ru_msgrcv=0, ru_nsignals=0, ru_nvcsw=6399, ru_nivcsw=13}) = 0
10:06:04 getrusage(RUSAGE_CHILDREN, {ru_utime={2, 271654}, ru_stime={1, 903710}, ru_maxrss=21176, ru_ixrss=0, ru_idrss=0, ru_isrss=0, ru_minflt=64514, ru_majflt=4, ru_nswap=0, ru_inblock=272, ru_oublock=368, ru_msgsnd=0, ru_msgrcv=0, ru_nsignals=0, ru_nvcsw=56079, ru_nivcsw=406}) = 0
Então, eu acho que bash
calcula uma diferença e imprime. Dessa forma, ele pode medir qualquer coisa como próprio builtins ou processo filho
- What are the things that the external time can time but the reserved word time can't?
Na verdade, ambas as chamadas de sistema getrusage
e wait4
obtêm de um uso de struct struct rusage . No entanto bash time
imprime número limitado de campos dessa estrutura. Isso é de man 1 time
:
Note: some shells (e.g., bash(1)) have a built-in time command that provides less functionality than the command described here.
$/usr/bin/time -v seq 10000
Command being timed: "seq 10000"
User time (seconds): 0.01
System time (seconds): 0.01
Percent of CPU this job got: 24%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.12
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 2640
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 0
Minor (reclaiming a frame) page faults: 199
Voluntary context switches: 8
Involuntary context switches: 24
Swaps: 0
File system inputs: 0
File system outputs: 8
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0