Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: profile prompt rendering time
- X-seq: zsh-users 21768
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: profile prompt rendering time
- Date: Wed, 13 Jul 2016 14:29:59 -0700
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:in-reply-to:comments:references:to:subject :mime-version; bh=5/4WMPYD7daGj0tqGuV+d8gjCB5MRxKXFQne2COqCsU=; b=BYN/KX5iym8jbYEyZPExPyLSEt0NxdPPOliFJ9+b+RzY2qH97yXuqYNwiVulSwzOmo d7FOPA+11f+9QhGuQ3osEvBqpBJalGdTR1qpjUzpTf2tpo4MZsVMPlrAvAniP9I3OM9Z gk986yy7/fefm01bSVyDGJcvz9iB5zeNgoGYV1omm1BoaAaPu2B+ztxmjH83r/Ew9+Ko vpkWm7c0eleTVRzu1xc8bnor59w2DOJadf1CQ7KxB1SUH7UAfCdJdqkZbifhGMNnAb7D I6bSHznpWoDzzpiYTF03L8VbFuEccWWX4dJRt9qOj/tSPGu9RmxqWeOHLPxAd5qATDab QT+g==
- In-reply-to: <CAEwkUWOPpAuSfj=XVzb9gOQ8oKg4o2uqhborLuT8GCVwSYt0Xg@mail.gmail.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CAEwkUWO7yrxptZChw7Q3F=u=0+Uwf+Frmzo24py3xvrK1=cTtA@mail.gmail.com> <160713110843.ZM21443@torch.brasslantern.com> <CAEwkUWOPpAuSfj=XVzb9gOQ8oKg4o2uqhborLuT8GCVwSYt0Xg@mail.gmail.com>
On Jul 13, 4:31pm, Filipe Silva wrote:
}
} Hi, Bart. thanks for the help. I can work with the execution time of ls
} included, no problem.
If you use precmd + zle-line-init then you don't need to. Just saying.
} But I did not really understand where I have to declare SECONDS.
Anywhere in your .zshrc or similar init file, or at the command line,
as long as it happens before the first event for which you want to
get the timings.
} See if I understand correctly. I'll open my zshrc and type this:
}
} ```
} preexec() {
} float SECONDS
} }
} precmd() {
} print $SECONDS
} }
} ```
}
} is that right?
Not quite. To spell out the example:
float SECONDS
preexec() { print BEFORE COMMAND: $SECONDS }
precmd() { print BEFORE PROMPT: $SECONDS }
zle-line-init() { zle -M "AFTER PROMPT: $SECONDS" }
zle -N zle-line-init
This will give e.g.:
torch% echo hello
BEFORE COMMAND: 7.365769200e+01
hello
BEFORE PROMPT: 7.365787900e+01
torch%
AFTER PROMPT: 7.365904200e+01
You don't really need both preexec and precmd, I included them to
show the difference. You DO need zle-line-init, there's no other
place to read the clock immediately after the prompt is displayed.
} Also, is 4.800e+2 = 480 milliseconds?
$SECONDS is the elapsed time in seconds since the shell started. So
you have to subtract to get the delta. Maybe this is better:
float START SECONDS
precmd() { START=$SECONDS }
zle-line-init() { zle -M "ELAPSED: $((SECONDS - START)) seconds" }
Silly example to demonstrate:
torch% setopt promptsubst; PS1='$(sleep 3)'"$PS1"
torch%
ELAPSED: 3.015070000000037 seconds
Messages sorted by:
Reverse Date,
Date,
Thread,
Author