From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 23432 invoked from network); 24 Jan 2023 23:14:52 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 24 Jan 2023 23:14:52 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1674602092; b=kHP4xOWsMou4BCOnw+G+sIHtU2NjkXgBT7dXDZsfaJZRVtyFZqNVugyADAQy9yvuFYMOqgSTR8 WEImt4M8Z3EnidfvKXT0XT476GXp64n4pRfcIz6KzxGs8HPm1kfAQNBk/kEyGRg+asnHmKnJDL J+f+WBQrriJe+yVf6mTFqbL3107mrtbnlU7KKWI+Ekr474inLZUgrZepAWnmElw9AHzmWvJsN0 OUWrYAEfR1+cAs+3oddno5YPXbuTvkJzmRBQg39XN+aOlOvIqO46hDt2sWAX9D5SyHSK5PR9SN MaFIfUB2zxj0hNKLMgsSPiT6QWFz/Tx4RpNQ1h4MNCX+0w==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mout.gmx.net) smtp.remote-ip=212.227.15.19; dkim=pass header.d=gmx.de header.s=s31663417 header.a=rsa-sha256; dmarc=pass header.from=gmx.de; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1674602092; bh=oumErCha1HCbFQjNf7oS2AsaxkVQOU6wdxD/itnsWtc=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:In-Reply-To:Content-Type: MIME-Version:References:Reply-To:Message-ID:Subject:To:From:Date: DKIM-Signature:DKIM-Signature; b=XLuJZice7GTahtAX5pBKXiAHlZMW4+igkaMdZuBRg1UtPiDTONDSkfIHdvsLNCzUQQqnqmdpjt pb7AujLfnlfJXSkcDASk6wPXhWODoAIYHFBa9kKgWz0Q8TJULDMFOdHXWd+XS2VROX7a9kvvhM bg0p/MVwQrrlJjV/wvGlCyNsQDtxLd1qHToBC1qlp0fxrMDSNaIDaqiRCF68y5yEDCNeiZZIZ7 mPnzUA4l+hrMyvJLvTDf2stEu9/wgYm9QJq3AtVio0/fcERvm+k+XTtwsN4FX6ItJvp39K/vTW pbxgANulisJfN6mXd+3iFDm2bHX5IH2QbVSsQdXCETImeg==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Transfer-Encoding:In-Reply-To :Content-Type:MIME-Version:References:Reply-To:Message-ID:Subject:To:From: Date:Cc:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID; bh=IwcBFhdfUCAbmvviAGbUVG0GdaBiR6N+wcEz4tdgfGA=; b=iHyg1T8UrCzHL8PdO4lfo7tQpb 3njlGgvogrhO2Dqh2vpZ+7R6tTMWrxsNgzlF9lYNzVQSEm7gsD1iTEVWVPhVmlrEfee5Rnvur5oYL 8V7tJj7yqDrN0wiXmrZniT7/Vdhr2OxLlk1VAo+oJX5Sey0MlkeZ6UUP4QIbGSnbK/q1odwUA+kbj N1Q/4liNmkpEIvSV+2fGkwnfTfbrmXJx4g2t66YT5FrWDy5ORthydIObSv8ppXH9+E6VP/RmjeHFO X1ENj7Z8feV/fTiRinVqPFvSHM1/9XJz5/00br+5jzb6GZL42WAWR0T+9Q76GkicH5sX6DyvPq3kY PfIYl3vg==; Received: by zero.zsh.org with local id 1pKSV9-0006Cm-6A; Tue, 24 Jan 2023 23:14:51 +0000 Authentication-Results: zsh.org; iprev=pass (mout.gmx.net) smtp.remote-ip=212.227.15.19; dkim=pass header.d=gmx.de header.s=s31663417 header.a=rsa-sha256; dmarc=pass header.from=gmx.de; arc=none Received: from mout.gmx.net ([212.227.15.19]:33237) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1pKSUV-0005PX-OZ; Tue, 24 Jan 2023 23:14:12 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1674602050; bh=oumErCha1HCbFQjNf7oS2AsaxkVQOU6wdxD/itnsWtc=; h=X-UI-Sender-Class:Date:From:To:Subject:Reply-To:References: In-Reply-To; b=NU/V39ujFW/VSRl4/2S3XBkp7mkD3El+FUGJ1rCc+mpoutREJyIAgwPPy5Hglte4G iOp4abXGdqno759Co+JZ2d4ZkkTmheC3ddbtrW6RoikOoFc9L1aatNl5rLHMulalhv WB+/rJYVgbouzO6iBZgV/Yo3S1bHfebbxWxQoUPZm1vG2lsQLpfDPu0lXoxsPCUT+5 1KOxTnMCd438kc12ZKrYghOhOUQIOscHPB/wAXHc8O3BOxSWk5LIkZitO5Vu9mgQaR UTKO/JB3jYnCgGkqrvx4G/NNi/R+YJW8R/dSCMp3/s4abu+BPiLvNoRpMbexEGJeqQ 663htLYvi+i5g== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from limone.obstwiese ([46.223.163.208]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MCbEf-1pU30r3QBf-009h9r for ; Wed, 25 Jan 2023 00:14:10 +0100 Received: from luthien by limone.obstwiese with local (Exim 4.94.2) (envelope-from ) id 1pKSSa-0004q1-Uu; Wed, 25 Jan 2023 00:12:12 +0100 Date: Wed, 25 Jan 2023 00:12:12 +0100 From: Dominik Vogt To: zsh-users@zsh.org Subject: Re: time command with shell builtins Message-ID: Reply-To: dominik.vogt@gmx.de Mail-Followup-To: zsh-users@zsh.org References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Provags-ID: V03:K1:bcquXMpoCvDckPyBoXsS8J94ULMZ2BBUYgUfHQPiK7mKNpv09Ow GvAzg/AVN3EKSxkPX2QMqugDchQ5IxbtYKVHkLt6RSozo6VW6DbFx2h+2IeAt8fm+S0U6wp h7B0tHUzAXnFej5eER0vX2YRTJyQfDPBG7jyHeS+GrxnAOa3Ifgebk48mSUBAyAYOPMoEDN RxrnVfJrh3JR1DOLTzIBw== UI-OutboundReport: notjunk:1;M01:P0:ndNag2eW4gI=;A9rdUas6wyyHog2xc0v1juD0LUx YoG7wJ+MvkbIfVuybymZGy0safMsuwCBH+hOxyopPqMqzJQ+kSXIFfKbzweUBt3ZU6TsnK/Nx ds/HBMQC+NX29jtkg4CUemnN1W/zfSE0cLn2d/iVRb4YVWyQUK7/4jNdgO+SblRex2m3IiEdw gA8GpxdQv/D/BYRfZfLZlL7bcIGz3mjkFG/8cLumOIo7MtpkG159Loai5Y67DsfDOzwVRbx2T HgTsygpKPEf+EK07RGOWELH6AC00F7TYi6Mmvii3loIqu2SuWQ5spTbwifVQVYVbu1hwrFm54 7S4IBEVp0qP+03Dnogo/l/vrN9q8VtxuLYlAmVryBi5uHzwvB+PfeEt3RmXHuAUyZZjW3QWre G+oQU4SEJzF7Qs2czkz6i9Pu85R3NKL5XvROXE1BX/QiULoi8S80SsTVuEd0+UZLhfncn5zQE rpJK/vCszOZXFNDoyGA6OxytFRdyCw2bwflmdnNcAoZ7lTWJa0Fu6poNrcGGz73gRlk910vhl 5gm1rLP8A/aR8P8uXnMnf/g3rg3muSvWdMHtcF3Oa3VR9Vx+pWH27Jtp8DDfRZ23fKnFDTeJC g9GwyzhVyCUoRJQy1dP3lqf0w46RhWmR9LSv6/aeExZfJ/+CV3B+bEYubq1y+mUcfo4/jLCjk iA3vWUfeCVgVXAJCGCY9vhGWGzlBI8pk/leLmMrX5+IEpYtrcaCka3FL3FAbWyuswUQP/cop6 DeM+6OHZB5ka20JkWALkteVPJkaiDdWqudvHZUFYsoWDPPIpPiBa1ttVqt1t1w6TyQ1p6vjlZ dQUSMglZPkrY7zUJqz1g8Xw14G4LXGBmZb7Bpp/amFxZiJfGo11pS6Fi5z7/GZkq3qVTYZezm u8lZo4/rYxnCYSNlXxZB8iZh4S5SKo6zufqBie7ejadHxYRH6TK7tRei+YkW3iNDRpGoEDPQX 8J1ksIIWzvXxfPHRv75xiLJsSrI= Content-Transfer-Encoding: quoted-printable X-Seq: 28772 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: On Tue, Jan 24, 2023 at 11:48:39AM +0100, Dominik Vogt wrote: > On Tue, Jan 24, 2023 at 10:32:35AM +0100, Mikael Magnusson wrote: > > On 1/23/23, Dominik Vogt wrote: > > > On Mon, Jan 23, 2023 at 07:31:12PM +0100, Mikael Magnusson wrote: > > >> On 1/23/23, Dominik Vogt wrote: > > >> > On Mon, Jan 23, 2023 at 02:42:05PM +0100, Roman Perepelitsa wrote= : > > >> >> On Mon, Jan 23, 2023 at 2:40 PM Dominik Vogt > > >> >> wrote: > > >> >> > > > >> >> > Is it possible to get timing statistics of shell builtins too? > > >> >> > Timing "echo" isn't very interesting, but timing loop construc= ts > > >> >> > would be: > > >> >> > > > >> >> > $ time while foo; do bar done > > >> >> > > >> >> This: > > >> >> > > >> >> % time ( while foo; do bar; done ) > > >> > > > >> > That wasn't really the question. Of course I can time a loop by > > >> > writing a different command, or by putting it in a pipe or file. > > >> > > > >> > $ time echo foo | true > > >> > > > >> > I just want to get timing statistics of loops either explicitly b= y > > >> > prepending "time" or implicitly with REPORTTIME. > > >> > > >> As Bart already mentioned, the answer to your question is "no", but > > >> you can avoid some downsides of the subshell (eg, if your loop has > > >> side effects that are relevant to the rest of the script etc), by > > >> using SECONDS: > > >> % () { typeset -F4 SECONDS=3D0; sleep 1; () { typeset -F3 SECONDS= =3D0; > > >> sleep 0.43; echo $SECONDS }; sleep 1; echo $SECONDS } > > >> 0.431 > > >> 2.4329 > > >> (the downside here is obviously that it doesn't split out cpu/syste= m > > >> time for you, only elapsed time). > > > > > > Well, the worst downside for me is that REPORTTIME does not work. > > > The use case is "oh, that command ran a long time, I'd really > > > like to know how long it took". I see no solution for that if > > > re-running the command is no optiuon because it takes too long. > > > > > > At the moment I'm writing some automation scripts that run for > > > hours and print their progress. I might want to kill them after a > > > few hours and see how many seconds they ran and compare it to the > > > progress output. > > > > What you can do at the moment is a) put the time in your prompt (and > > reset the prompt on accept-line), b) save the current time in preexec > > and compare it against the current time in precmd and print it out if > > it exceeds some threshold(, c) or both). > > Good idea. This is what I use now: > > -- snip -- > autoload -Uz add-zsh-hook > zmodload zsh/datetime > > function preexec_recordtime() { > typeset -g _zsh_time > _zsh_time=3D"$EPOCHSECONDS" > } > add-zsh-hook preexec preexec_recordtime > > function __prompt_get_displaytime () { > if ! (( ${+_zsh_time} )); then return 0; fi > if ! (( ${+REPORTTIME} )); then return 0; fi > if (( $EPOCHSECONDS - $_zsh_time > $REPORTTIME )); then > printf " $[EPOCHSECONDS - _zsh_time]s" > fi > unset _zsh_time > } > > PS1=3D"<...>$(__prompt_get_displaytime)<...>" > -- snip -- Hm, any idea how to suppress reporting the run time of interactive commands like vi, emacs, mutt? Not very important, but it's a bit confusing. As far as I understand there's no reliable access to which command is being executed in preexec. I could replace such commands by functions that erase _zsh_time when they start... Ciao Dominik ^_^ ^_^ =2D- Dominik Vogt