Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Exporting REPORTTIME data to ENVVARs instead of printing.
- X-seq: zsh-workers 36778
- From: Slava Barinov <rayslava@xxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Exporting REPORTTIME data to ENVVARs instead of printing.
- Date: Mon, 5 Oct 2015 14:23:34 +0300
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type; bh=0A+nYHutyo4V4fCidrGo88w7E87bi9WM4rJheWVbFT4=; b=Rn5fQvkkOnbausq7qx3qGzOZk2xSuH7H+zpe/AXWRs7agIEC9KeVYxoivOQsRF3vAB f7ZNyuQ0q42FMBdukXFvShnYc+2mkiThU3ge6i9CsFynN7fq35w/AecXRMuptdDf4fMz GnjqEjvtd0MqnXYbURLYjVaozSPyjn8uk4damIgmgvLw+b9PY7BYp3u13AuGpW1y5mUI LwI9ToRmab4IJcNZt8tgRqkYnlcfAEv+2iXDn4zEda+v363BREwo8MT4ffjHI/shSHfZ dRCBRtUMep4UN3oC8Rebpmatqq8fo6PLhPckteIanQovkT9dVfkLJmPB21ykto8xBG99 zKMQ==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
Hello,
A while ago I tried to add process timing reports to my ZSH and found that
REPORTTIME feature only can print timings to terminal but I have a great
prompt with much information embedded and still having some space to add this
info.
My suggestion is to add possibility of exporting timings to envvars instead
of printing them to terminal.
My straightforward implementation is attached: while REPORTTIME is switched
on if REPORTTIME_TO_VAR is defined then four variables are set up:
REPORTTIME_USER, REPORTTIME_SYSTEM, REPORTTIME_TOTAL and REPORTTIME_CPU. The
numbers are just summed up for all procs over the job. Don't know if it's a
good idea to extract timing computation to a new function, so I just copied
it from `printtime'.
Will this feature be useful for someone else?
Best Regards,
Slava Barinov.
diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo
index ba2856b..b9fafab 100644
--- a/Doc/Zsh/params.yo
+++ b/Doc/Zsh/params.yo
@@ -1373,6 +1373,12 @@ executed within the line editor, including completion; commands
explicitly marked with the tt(time) keyword still cause the summary
to be printed in this case.
)
+vindex(REPORTTIME_TO_VAR)
+item(tt(REPORTTIME_TO_VAR))(
+If defined, the values of tt(REPORTTIME) are not printed for processes
+but placed into tt(REPORTTIME_USER), tt(REPORTTIME_SYSTEM),
+tt(REPORTTIME_TOTAL) and tt(REPORTTIME_CPU) for the job.
+)
vindex(REPLY)
item(tt(REPLY))(
This parameter is reserved by convention to pass string values between
diff --git a/Src/jobs.c b/Src/jobs.c
index b47ba8c..72c71dc 100644
--- a/Src/jobs.c
+++ b/Src/jobs.c
@@ -864,12 +864,52 @@ dumptime(Job jn)
{
Process pn;
struct timeval dtimeval;
+ char *s = "REPORTTIME_TO_VAR";
if (!jn->procs)
return;
- for (pn = jn->procs; pn; pn = pn->next)
+ if (NULL == getsparam(s))
+ for (pn = jn->procs; pn; pn = pn->next)
printtime(dtime(&dtimeval, &pn->bgtime, &pn->endtime), &pn->ti,
pn->text);
+ else
+ {
+ double user_time = 0.0, system_time = 0.0;
+ double percent = 0.0, total_time = 0.0;
+ mnumber mnval;
+ mnval.type = MN_FLOAT;
+
+ for (pn = jn->procs; pn; pn = pn->next)
+ {
+ const child_times_t *ti = &pn->ti;
+ const struct timeval *real = dtime(&dtimeval, &pn->bgtime,
+ &pn->endtime);
+#ifdef HAVE_GETRUSAGE
+ user_time += ti->ru_utime.tv_sec + ti->ru_utime.tv_usec / 1000000.0;
+ system_time += ti->ru_stime.tv_sec + ti->ru_stime.tv_usec / 1000000.0;
+ total_time += user_time + system_time;
+ percent += 100.0 * total_time
+ / (real->tv_sec + real->tv_usec / 1000000.0);
+#else
+ {
+ long clktck = get_clktck();
+ user_time += ti->ut / (double) clktck;
+ system_time += ti->st / (double) clktck;
+ total_time += user_time + system_time;
+ percent += 100.0 * (ti->ut + ti->st)
+ / (clktck * real->tv_sec + clktck * real->tv_usec / 1000000.0);
+ }
+#endif
+ }
+ mnval.u.d = user_time;
+ setnparam("REPORTTIME_USER", mnval);
+ mnval.u.d = system_time;
+ setnparam("REPORTTIME_SYSTEM", mnval);
+ mnval.u.d = total_time;
+ setnparam("REPORTTIME_TOTAL", mnval);
+ mnval.u.d = percent;
+ setnparam("REPORTTIME_CPU", mnval);
+ }
}
/* Check whether shell should report the amount of time consumed *
Messages sorted by:
Reverse Date,
Date,
Thread,
Author