sistema_progs

Programas para customizar o meu entorno de traballo nos meus equipos persoais
Log | Files | Refs

prompt-elapsed.bash (2395B)


      1 # blesh/contrib/prompt-elapsed.bash (C) 2022, Koichi Murase <myoga.murase@gmail.com>
      2 
      3 function ble/contrib/prompt-elapsed/output-sec.ps {
      4   local sec=$1 min
      5   ((min=sec/60,sec%=60))
      6   if ((min<100)); then
      7     ble/prompt/print "${min}m${sec}s"
      8     return 0
      9   fi
     10 
     11   local hour; ((hour=min/60,min%=60))
     12   if ((hour<100)); then
     13     ble/prompt/print "${hour}h${min}m${sec}s"
     14     return 0
     15   fi
     16 
     17   local day; ((day=hour/24,hour%=24))
     18   if ((day<365)); then
     19     ble/prompt/print "${day}d${hour}h${min}m"
     20     return 0
     21   fi
     22 
     23   local year; ((year=day/365,day%=365))
     24   ble/prompt/print "${year}y${day}d${hour}h"
     25   return 0
     26 }
     27 
     28 function ble/contrib/prompt-elapsed/output-time-format.ps {
     29   local msec=$1
     30   local d=${#msec}
     31   if ((d<=3)); then
     32     ble/prompt/print "${msec}msec"
     33     return 0
     34   elif ((d<=5)); then
     35     ble/prompt/print "${msec::d-3}.${msec:d-36-d}sec"
     36     return 0
     37   fi
     38 
     39   local sec=$((msec/1000)) min
     40   ((msec%=1000,min=sec/60,sec%=60))
     41   msec=000${msec}; msec=${msec:${#msec}-3}
     42   if ((min<100)); then
     43     ble/prompt/print "${min}m${sec}.${msec}s"
     44     return 0
     45   fi
     46 
     47   ble/contrib/prompt-elapsed/output-sec.ps "$((min*60+sec))"
     48 }
     49 
     50 function ble/prompt/backslash:contrib/elapsed {
     51   [[ $_ble_exec_time_ata ]] || return 1
     52 
     53   local ata=$_ble_exec_time_ata
     54   local d=${#ata}
     55   if ((d<=3)); then
     56     ble/prompt/print "${ata}usec"
     57     return 0
     58   elif ((d<=6)); then
     59     if ((d<=5)); then
     60       ble/prompt/print "${ata::d-3}.${ata:d-3:6-d}msec"
     61     else
     62       ble/prompt/print "${ata::3}msec"
     63     fi
     64     return 0
     65   elif ((d<=8)); then
     66     ble/prompt/print "${ata::d-6}.${ata:d-6:3}sec"
     67     return 0
     68   fi
     69 
     70   ble/contrib/prompt-elapsed/output-sec.ps "$((ata/1000000))"
     71 }
     72 
     73 function ble/prompt/backslash:contrib/elapsed-real {
     74   [[ $_ble_exec_time_ata ]] || return 1
     75   ble/contrib/prompt-elapsed/output-time-format.ps "$_ble_exec_time_tot"
     76 }
     77 function ble/prompt/backslash:contrib/elapsed-user {
     78   [[ $_ble_exec_time_ata ]] || return 1
     79   ble/contrib/prompt-elapsed/output-time-format.ps "$_ble_exec_time_usr"
     80 }
     81 function ble/prompt/backslash:contrib/elapsed-sys {
     82   [[ $_ble_exec_time_ata ]] || return 1
     83   ble/contrib/prompt-elapsed/output-time-format.ps "$_ble_exec_time_sys"
     84 }
     85 function ble/prompt/backslash:contrib/elapsed-cpu {
     86   ((_ble_exec_time_tot)) || return 1
     87 
     88   local pk=$(((_ble_exec_time_usr+_ble_exec_time_sys)*1000/_ble_exec_time_tot))
     89   ble/prompt/print "$((pk/10)).$((pk%10))%"
     90   return 0
     91 }