From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: [bug] times builtin output wrong
Date: Thu, 29 May 2014 20:45:30 +0100 [thread overview]
Message-ID: <20140529204530.368db399@pws-pc.ntlworld.com> (raw)
In-Reply-To: <20140526201318.GA10886@chaz.gmail.com>
On Mon, 26 May 2014 21:13:18 +0100
Stephane Chazelas <stephane.chazelas@gmail.com> wrote:
> $ times
> 0m3.36s 0m1.95s
> 0m12.23s 0m0.15s
> $ time
> shell 2.02s user 1.17s system 1% cpu 3:36.66 total
> children 7.34s user 0.10s system 3% cpu 3:36.66 total
> $ echo $((7.34*100/60))
> 12.233333333333333
>
> It looks like they're expressed in 60/100th of seconds.
This looks better.
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -6095,8 +6095,9 @@ bin_test(char *name, char **argv, UNUSED(Options ops), int func)
}
/* display a time, provided in units of 1/60s, as minutes and seconds */
-#define pttime(X) printf("%ldm%ld.%02lds",((long) (X))/3600,\
- ((long) (X))/60%60,((long) (X))*100/60%100)
+#define pttime(X) printf("%ldm%ld.%02lds",((long) (X))/(60 * clktck),\
+ ((long) (X))/clktck%clktck,\
+ ((long) (X))*100/clktck%100)
/* times: display, in a two-line format, the times provided by times(3) */
@@ -6105,6 +6106,7 @@ int
bin_times(UNUSED(char *name), UNUSED(char **argv), UNUSED(Options ops), UNUSED(int func))
{
struct tms buf;
+ long clktck = get_clktck();
/* get time accounting information */
if (times(&buf) == -1)
diff --git a/Src/jobs.c b/Src/jobs.c
index 8719465..c4a0707 100644
--- a/Src/jobs.c
+++ b/Src/jobs.c
@@ -618,13 +618,11 @@ setprevjob(void)
}
/**/
-#ifndef HAVE_GETRUSAGE
-static long clktck = 0;
-
-/**/
-static void
-set_clktck(void)
+long
+get_clktck(void)
{
+ static long clktck;
+
#ifdef _SC_CLK_TCK
if (!clktck)
/* fetch clock ticks per second from *
@@ -646,9 +644,9 @@ set_clktck(void)
# endif
# endif
#endif
+
+ return clktck;
}
-/**/
-#endif
/**/
static void
@@ -698,11 +696,13 @@ printtime(struct timeval *real, child_times_t *ti, char *desc)
percent = 100.0 * total_time
/ (real->tv_sec + real->tv_usec / 1000000.0);
#else
- set_clktck();
- user_time = ti->ut / (double) clktck;
- system_time = ti->st / (double) clktck;
- percent = 100.0 * (ti->ut + ti->st)
- / (clktck * real->tv_sec + clktck * real->tv_usec / 1000000.0);
+ {
+ long clktck = get_clktck();
+ user_time = ti->ut / (double) clktck;
+ system_time = ti->st / (double) clktck;
+ percent = 100.0 * (ti->ut + ti->st)
+ / (clktck * real->tv_sec + clktck * real->tv_usec / 1000000.0);
+ }
#endif
queue_signals();
@@ -910,8 +910,10 @@ should_report_time(Job j)
reporttime--;
return reporttime <= 0;
#else
- set_clktck();
- return ((j->procs->ti.ut + j->procs->ti.st) / clktck >= reporttime);
+ {
+ clktck = get_clktck();
+ return ((j->procs->ti.ut + j->procs->ti.st) / clktck >= reporttime);
+ }
#endif
}
--
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/
prev parent reply other threads:[~2014-05-29 19:51 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-26 20:13 Stephane Chazelas
2014-05-29 19:45 ` Peter Stephenson [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140529204530.368db399@pws-pc.ntlworld.com \
--to=p.w.stephenson@ntlworld.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).