O que o comando externo 'time' e a palavra reservada 'time' time?

0

O Manual de Referência da Bash diz

The use of time as a reserved word permits the timing of shell builtins, shell functions, and pipelines. An external time command cannot time these easily.

  1. O que pode um comando externo time time?

    Apenas um comando externo simples? Mais nada?

    Qual regra impede o tempo de outras coisas? A regra pertencem ao shell (bash) ou a implementação do external comando time ?

    Btw, eu estou rodando o Ubuntu, então time é do Debian.

  2. A palavra reservada do Bash time time todas as coisas que podem corre? Se não, o que não é o tempo?

  3. Quais são as coisas que o time externo pode acumular, mas a palavra reservada time não pode?

por Tim 16.03.2016 / 06:53

1 resposta

2

Minha resposta é sobre o Linux.

  1. 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

  1. 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

  1. 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
    
por 16.03.2016 / 08:18