Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: ltratt/multitime
base: 718296a49f
...
head fork: ltratt/multitime
compare: 0811aac9b0
  • 2 commits
  • 5 files changed
  • 0 commit comments
  • 1 contributor
Commits on Aug 28, 2012
@ltratt Print out (nearly) everything in rusage.
Also finish the breaking out of the format code.
7d4262c
@ltratt Rename "maximal" formatting to "rusage".
This seems somehow more appropriate.
0811aac
Showing with 155 additions and 219 deletions.
  1. +1 −1  .gitignore
  2. +1 −1  Makefile.in
  3. +145 −52 format.c
  4. +7 −164 multitime.c
  5. +1 −1  multitime.h
View
2  .gitignore
@@ -6,4 +6,4 @@ config.log
config.status
configure
multitime
-multitime.o
+*.o
View
2  Makefile.in
@@ -6,7 +6,7 @@ exec_prefix = @exec_prefix@
bindir = @bindir@
INSTALL = @INSTALL@
-MULTITIME_OBJS = multitime.o
+MULTITIME_OBJS = format.o multitime.o
multitime: ${MULTITIME_OBJS}
${CC} -o multitime ${LIBS} ${MULTITIME_OBJS}
View
197 format.c
@@ -94,82 +94,175 @@ int cmp_rusage_stime(const void *x, const void *y)
+#define RUSAGE_CMP(n) int cmp_rusage_ ## n(const void *x, const void *y) \
+ { \
+ const long *l1 = &(*((const struct rusage **) x))->ru_ ## n; \
+ const long *l2 = &(*((const struct rusage **) y))->ru_ ## n; \
+ if (*l1 < *l2) \
+ return -1; \
+ else if (*l1 == *l2) \
+ return 0; \
+ return 1; \
+ }
+
+RUSAGE_CMP(maxrss)
+RUSAGE_CMP(minflt)
+RUSAGE_CMP(majflt)
+RUSAGE_CMP(nswap)
+RUSAGE_CMP(inblock)
+RUSAGE_CMP(oublock)
+RUSAGE_CMP(msgsnd)
+RUSAGE_CMP(msgrcv)
+RUSAGE_CMP(nsignals)
+RUSAGE_CMP(nvcsw)
+RUSAGE_CMP(nivcsw)
+
+
+
void format_other(Conf *conf)
{
fprintf(stderr,
- " Min Max Mean Std.Dev. Median\n");
+ " Min Max Mean Std.Dev. Median\n");
- struct timeval real_mean_tv, user_mean_tv, sys_mean_tv;
- timerclear(&real_mean_tv);
- timerclear(&user_mean_tv);
- timerclear(&sys_mean_tv);
+ // Means
+
+ struct timeval mean_real_tv, mean_user_tv, mean_sys_tv;
+ timerclear(&mean_real_tv);
+ timerclear(&mean_user_tv);
+ timerclear(&mean_sys_tv);
for (unsigned int i = 0; i < conf->num_runs; i += 1) {
- timeradd(&real_mean_tv, conf->timevals[0][i], &real_mean_tv);
- timeradd(&user_mean_tv, &conf->rusages[0][i]->ru_utime, &user_mean_tv);
- timeradd(&sys_mean_tv, &conf->rusages[0][i]->ru_stime, &sys_mean_tv);
+ timeradd(&mean_real_tv, conf->timevals[0][i], &mean_real_tv);
+ timeradd(&mean_user_tv, &conf->rusages[0][i]->ru_utime, &mean_user_tv);
+ timeradd(&mean_sys_tv, &conf->rusages[0][i]->ru_stime, &mean_sys_tv);
}
- double real_mean =
- TIMEVAL_TO_DOUBLE(&real_mean_tv) / (double) conf->num_runs;
- double user_mean =
- TIMEVAL_TO_DOUBLE(&user_mean_tv) / (double) conf->num_runs;
- double sys_mean =
- TIMEVAL_TO_DOUBLE(&sys_mean_tv) / (double) conf->num_runs;
+ double mean_real = (double)
+ TIMEVAL_TO_DOUBLE(&mean_real_tv) / conf->num_runs;
+ double mean_user = (double)
+ TIMEVAL_TO_DOUBLE(&mean_user_tv) / conf->num_runs;
+ double mean_sys = (double)
+ TIMEVAL_TO_DOUBLE(&mean_sys_tv) / conf->num_runs;
+
+ // Standard deviations
double real_stddev = 0, user_stddev = 0, sys_stddev = 0;
for (unsigned int i = 0; i < conf->num_runs; i += 1) {
- real_stddev +=
- pow(TIMEVAL_TO_DOUBLE(conf->timevals[0][i]) - real_mean, 2);
- user_stddev +=
- pow(TIMEVAL_TO_DOUBLE(&conf->rusages[0][i]->ru_utime) - user_mean, 2);
- sys_stddev +=
- pow(TIMEVAL_TO_DOUBLE(&conf->rusages[0][i]->ru_stime) - sys_mean, 2);
+ real_stddev +=
+ pow(TIMEVAL_TO_DOUBLE(conf->timevals[0][i]) - mean_real, 2);
+ user_stddev +=
+ pow(TIMEVAL_TO_DOUBLE(&conf->rusages[0][i]->ru_utime) - mean_user, 2);
+ sys_stddev +=
+ pow(TIMEVAL_TO_DOUBLE(&conf->rusages[0][i]->ru_stime) - mean_sys, 2);
}
+ // Mins and maxes
+
+ unsigned int mdl, mdr;
+ if (conf->num_runs % 2 == 0) {
+ mdl = conf->num_runs / 2 - 1; // Median left
+ mdr = conf->num_runs / 2; // Median right
+ }
+ else {
+ mdl = conf->num_runs / 2;
+ mdr = 0; // Unused
+ }
+
+ double min_real, max_real, md_real;
qsort(conf->timevals[0], conf->num_runs,
sizeof(struct timeval *), cmp_timeval);
- qsort(conf->rusages[0], conf->num_runs,
- sizeof(struct rusage *), cmp_rusage_utime);
- qsort(conf->rusages[0], conf->num_runs,
- sizeof(struct rusage *), cmp_rusage_stime);
-
- double md_real, md_user, md_sys;
+ min_real = TIMEVAL_TO_DOUBLE(conf->timevals[0][0]);
+ max_real = TIMEVAL_TO_DOUBLE(conf->timevals[0][conf->num_runs - 1]);
if (conf->num_runs % 2 == 0) {
- int mdl = conf->num_runs / 2 - 1; // Median left
- int mdr = conf->num_runs / 2; // Median right
struct timeval t;
timeradd(conf->timevals[0][mdl],
conf->timevals[0][mdr], &t);
md_real = TIMEVAL_TO_DOUBLE(&t) / 2;
+ }
+ else
+ md_real = TIMEVAL_TO_DOUBLE(conf->timevals[0][mdl]);
+
+ double min_user, max_user, md_user;
+ qsort(conf->rusages[0], conf->num_runs,
+ sizeof(struct rusage *), cmp_rusage_utime);
+ min_user = TIMEVAL_TO_DOUBLE(&conf->rusages[0][0]->ru_utime);
+ max_user = TIMEVAL_TO_DOUBLE(&conf->rusages[0][conf->num_runs - 1]->ru_utime);
+ if (conf->num_runs % 2 == 0) {
+ struct timeval t;
timeradd(&conf->rusages[0][mdl]->ru_utime,
&conf->rusages[0][mdr]->ru_utime, &t);
md_user = TIMEVAL_TO_DOUBLE(&t) / 2;
+ }
+ else
+ md_user = TIMEVAL_TO_DOUBLE(&conf->rusages[0][mdl]->ru_utime);
+
+ double min_sys, max_sys, md_sys;
+ qsort(conf->rusages[0], conf->num_runs,
+ sizeof(struct rusage *), cmp_rusage_stime);
+ min_sys = TIMEVAL_TO_DOUBLE(&conf->rusages[0][0]->ru_stime);
+ max_sys = TIMEVAL_TO_DOUBLE(&conf->rusages[0][conf->num_runs - 1]->ru_stime);
+ if (conf->num_runs % 2 == 0) {
+ struct timeval t;
timeradd(&conf->rusages[0][mdl]->ru_stime,
&conf->rusages[0][mdr]->ru_stime, &t);
md_sys = TIMEVAL_TO_DOUBLE(&t) / 2;
}
- else {
- int md = conf->num_runs / 2;
- md_real = TIMEVAL_TO_DOUBLE(conf->timevals[0][md]);
- md_user = TIMEVAL_TO_DOUBLE(&conf->rusages[0][md]->ru_utime);
- md_sys = TIMEVAL_TO_DOUBLE(&conf->rusages[0][md]->ru_stime);
- }
+ else
+ md_sys = TIMEVAL_TO_DOUBLE(&conf->rusages[0][mdl]->ru_stime);
+
+ // Print everything out
+
+ fprintf(stderr, "real %-11.3f%-11.3f%-11.3f%-11.3f%-11.3f\n",
+ min_real, max_real, mean_real,
+ sqrt(real_stddev / conf->num_runs), md_real);
+ fprintf(stderr, "user %-11.3f%-11.3f%-11.3f%-11.3f%-11.3f\n",
+ min_user, max_user, mean_user,
+ sqrt(user_stddev / conf->num_runs), md_user);
+ fprintf(stderr, "sys %-11.3f%-11.3f%-11.3f%-11.3f%-11.3f\n",
+ min_sys, max_sys, mean_sys,
+ sqrt(sys_stddev / conf->num_runs), md_sys);
+
+ if (conf->format_style == FORMAT_NORMAL)
+ return;
+
+ //
+ // rusage output.
+ //
+
+#define RUSAGE_STAT(n) \
+ long sum_##n = 0; \
+ for (unsigned int i = 0; i < conf->num_runs; i += 1) \
+ sum_##n += conf->rusages[0][i]->ru_##n; \
+ long mean_##n = (double) sum_##n / conf->num_runs; \
+ double stddev_##n = 0; \
+ for (unsigned int i = 0; i < conf->num_runs; i += 1) \
+ stddev_##n += pow(conf->rusages[0][i]->ru_##n - mean_##n, 2); \
+ long min_##n, max_##n, md_##n; \
+ qsort(conf->rusages[0], conf->num_runs, \
+ sizeof(struct rusage *), cmp_rusage_##n); \
+ min_##n = conf->rusages[0][0]->ru_##n; \
+ max_##n = conf->rusages[0][conf->num_runs - 1]->ru_##n; \
+ if (conf->num_runs % 2 == 0) \
+ md_##n = (conf->rusages[0][mdl]->ru_##n + conf->rusages[0][mdr]->ru_##n) / 2; \
+ else \
+ md_##n = conf->rusages[0][mdl]->ru_##n; \
+ fprintf(stderr, #n); \
+ for (unsigned int i = 0; i < 12 - strlen(#n); i += 1) \
+ fprintf(stderr, " "); \
+ fprintf(stderr, "%-11ld%-11ld%-11ld%-11ld%-11ld\n", \
+ min_##n, \
+ max_##n, \
+ mean_##n, \
+ (long) sqrt(stddev_##n / conf->num_runs), \
+ md_##n);
- fprintf(stderr, "real %-11.3f%-11.3f%-11.3f%-11.3f%-11.3f\n",
- TIMEVAL_TO_DOUBLE(conf->timevals[0][0]),
- TIMEVAL_TO_DOUBLE(conf->timevals[0][conf->num_runs - 1]),
- real_mean,
- sqrt(real_stddev / conf->num_runs),
- md_real);
- fprintf(stderr, "user %-11.3f%-11.3f%-11.3f%-11.3f%-11.3f\n",
- TIMEVAL_TO_DOUBLE(&conf->rusages[0][0]->ru_utime),
- TIMEVAL_TO_DOUBLE(&conf->rusages[0][conf->num_runs - 1]->ru_utime),
- user_mean,
- sqrt(user_stddev / conf->num_runs),
- md_user);
- fprintf(stderr, "sys %-11.3f%-11.3f%-11.3f%-11.3f%-11.3f\n",
- TIMEVAL_TO_DOUBLE(&conf->rusages[0][0]->ru_stime),
- TIMEVAL_TO_DOUBLE(&conf->rusages[0][conf->num_runs - 1]->ru_stime),
- sys_mean,
- sqrt(sys_stddev / conf->num_runs),
- md_sys);
+ RUSAGE_STAT(maxrss)
+ RUSAGE_STAT(minflt)
+ RUSAGE_STAT(majflt)
+ RUSAGE_STAT(nswap)
+ RUSAGE_STAT(inblock)
+ RUSAGE_STAT(oublock)
+ RUSAGE_STAT(msgsnd)
+ RUSAGE_STAT(msgrcv)
+ RUSAGE_STAT(nsignals)
+ RUSAGE_STAT(nvcsw)
+ RUSAGE_STAT(nivcsw)
}
View
171 multitime.c
@@ -35,31 +35,15 @@
#include <sys/wait.h>
#include <unistd.h>
+#include "multitime.h"
+#include "format.h"
-enum Format_Style {FORMAT_LIKE_TIME, FORMAT_NORMAL, FORMAT_MAXIMAL};
-
-typedef struct {
- enum Format_Style format_style;
- unsigned int num_cmds; // How many commands the user has specified.
- char ***cmds; // The pre-processed execvp'able arguments for
- // each command.
- struct timeval ***timevals; // The wall clock time for each command run.
- struct rusage ***rusages; // The rusage each command run.
- unsigned int num_runs; // How many times to run each command.
-} Conf;
extern char* __progname;
void usage(int, char *);
void run_cmd(Conf *, unsigned int, unsigned int);
-int cmp_timeval(const void *, const void *);
-void format_like_time(Conf *);
-void format_normal(Conf *);
-
-#define TIMEVAL_TO_DOUBLE(t) \
- ((double) (t)->tv_sec + (double) (t)->tv_usec / 1000000)
-
@@ -106,146 +90,6 @@ void run_cmd(Conf *conf, unsigned int cmd_num, unsigned int cmd_i)
-void format_like_time(Conf *conf)
-{
- // Formatting like /usr/bin/time only makes sense if a single command is run.
- assert(conf->num_cmds == 1);
-
- struct timeval real, user, sys;
- timerclear(&real);
- timerclear(&user);
- timerclear(&sys);
- for (unsigned int i = 0; i < conf->num_runs; i += 1) {
- timeradd(&real, conf->timevals[0][i], &real);
- timeradd(&user, &conf->rusages[0][i]->ru_utime, &user);
- timeradd(&sys, &conf->rusages[0][i]->ru_stime, &sys);
- }
- fprintf(stderr, "real %9ld.%02ld\n",
- real.tv_sec / conf->num_runs, (real.tv_usec / 10000) / conf->num_runs);
- fprintf(stderr, "user %9ld.%02ld\n",
- user.tv_sec / conf->num_runs, (user.tv_usec / 10000) / conf->num_runs);
- fprintf(stderr, "sys %9ld.%02ld\n",
- sys.tv_sec / conf->num_runs, (sys.tv_usec / 10000) / conf->num_runs);
-}
-
-
-
-int cmp_timeval(const void *x, const void *y)
-{
- const struct timeval *t1 = *((const struct timeval **) x);
- const struct timeval *t2 = *((const struct timeval **) y);
-
- if (t1->tv_sec < t2->tv_sec
- || (t1->tv_sec == t2->tv_sec && t1->tv_usec < t2->tv_usec))
- return -1;
- else if (t1->tv_sec == t2->tv_sec && t1->tv_usec == t2->tv_usec)
- return 0;
- else
- return 1;
-}
-
-
-
-int cmp_rusage_utime(const void *x, const void *y)
-{
- const struct timeval *t1 = &(*((const struct rusage **) x))->ru_utime;
- const struct timeval *t2 = &(*((const struct rusage **) y))->ru_utime;
-
- return cmp_timeval(&t1, &t2);
-}
-
-
-
-int cmp_rusage_stime(const void *x, const void *y)
-{
- const struct timeval *t1 = &(*((const struct rusage **) x))->ru_stime;
- const struct timeval *t2 = &(*((const struct rusage **) y))->ru_stime;
-
- return cmp_timeval(&t1, &t2);
-}
-
-
-
-void format_normal(Conf *conf)
-{
- fprintf(stderr,
- " Min Max Mean Std.Dev. Median\n");
-
- struct timeval real_mean_tv, user_mean_tv, sys_mean_tv;
- timerclear(&real_mean_tv);
- timerclear(&user_mean_tv);
- timerclear(&sys_mean_tv);
- for (unsigned int i = 0; i < conf->num_runs; i += 1) {
- timeradd(&real_mean_tv, conf->timevals[0][i], &real_mean_tv);
- timeradd(&user_mean_tv, &conf->rusages[0][i]->ru_utime, &user_mean_tv);
- timeradd(&sys_mean_tv, &conf->rusages[0][i]->ru_stime, &sys_mean_tv);
- }
- double real_mean =
- TIMEVAL_TO_DOUBLE(&real_mean_tv) / (double) conf->num_runs;
- double user_mean =
- TIMEVAL_TO_DOUBLE(&user_mean_tv) / (double) conf->num_runs;
- double sys_mean =
- TIMEVAL_TO_DOUBLE(&sys_mean_tv) / (double) conf->num_runs;
-
- double real_stddev = 0, user_stddev = 0, sys_stddev = 0;
- for (unsigned int i = 0; i < conf->num_runs; i += 1) {
- real_stddev +=
- pow(TIMEVAL_TO_DOUBLE(conf->timevals[0][i]) - real_mean, 2);
- user_stddev +=
- pow(TIMEVAL_TO_DOUBLE(&conf->rusages[0][i]->ru_utime) - user_mean, 2);
- sys_stddev +=
- pow(TIMEVAL_TO_DOUBLE(&conf->rusages[0][i]->ru_stime) - sys_mean, 2);
- }
-
- qsort(conf->timevals[0], conf->num_runs,
- sizeof(struct timeval *), cmp_timeval);
- qsort(conf->rusages[0], conf->num_runs,
- sizeof(struct rusage *), cmp_rusage_utime);
- qsort(conf->rusages[0], conf->num_runs,
- sizeof(struct rusage *), cmp_rusage_stime);
-
- double md_real, md_user, md_sys;
- if (conf->num_runs % 2 == 0) {
- int mdl = conf->num_runs / 2 - 1; // Median left
- int mdr = conf->num_runs / 2; // Median right
- struct timeval t;
- timeradd(conf->timevals[0][mdl],
- conf->timevals[0][mdr], &t);
- md_real = TIMEVAL_TO_DOUBLE(&t) / 2;
- timeradd(&conf->rusages[0][mdl]->ru_utime,
- &conf->rusages[0][mdr]->ru_utime, &t);
- md_user = TIMEVAL_TO_DOUBLE(&t) / 2;
- timeradd(&conf->rusages[0][mdl]->ru_stime,
- &conf->rusages[0][mdr]->ru_stime, &t);
- md_sys = TIMEVAL_TO_DOUBLE(&t) / 2;
- }
- else {
- int md = conf->num_runs / 2;
- md_real = TIMEVAL_TO_DOUBLE(conf->timevals[0][md]);
- md_user = TIMEVAL_TO_DOUBLE(&conf->rusages[0][md]->ru_utime);
- md_sys = TIMEVAL_TO_DOUBLE(&conf->rusages[0][md]->ru_stime);
- }
-
- fprintf(stderr, "real %-11.3f%-11.3f%-11.3f%-11.3f%-11.3f\n",
- TIMEVAL_TO_DOUBLE(conf->timevals[0][0]),
- TIMEVAL_TO_DOUBLE(conf->timevals[0][conf->num_runs - 1]),
- real_mean,
- sqrt(real_stddev / conf->num_runs),
- md_real);
- fprintf(stderr, "user %-11.3f%-11.3f%-11.3f%-11.3f%-11.3f\n",
- TIMEVAL_TO_DOUBLE(&conf->rusages[0][0]->ru_utime),
- TIMEVAL_TO_DOUBLE(&conf->rusages[0][conf->num_runs - 1]->ru_utime),
- user_mean,
- sqrt(user_stddev / conf->num_runs),
- md_user);
- fprintf(stderr, "sys %-11.3f%-11.3f%-11.3f%-11.3f%-11.3f\n",
- TIMEVAL_TO_DOUBLE(&conf->rusages[0][0]->ru_stime),
- TIMEVAL_TO_DOUBLE(&conf->rusages[0][conf->num_runs - 1]->ru_stime),
- sys_mean,
- sqrt(sys_stddev / conf->num_runs),
- md_sys);
-}
-
////////////////////////////////////////////////////////////////////////////////
// main
//
@@ -254,7 +98,7 @@ void usage(int rtn_code, char *msg)
{
if (msg)
fprintf(stderr, "%s\n", msg);
- fprintf(stderr, "Usage: %s [-f <liketime|maximal>] <num runs> <command> "
+ fprintf(stderr, "Usage: %s [-f <liketime|rusage>] <num runs> <command> "
"[<arg 1> ... <arg n>]\n", __progname);
exit(rtn_code);
}
@@ -271,8 +115,8 @@ int main(int argc, char** argv)
case 'f':
if (strcmp(optarg, "liketime") == 0)
conf->format_style = FORMAT_LIKE_TIME;
- else if (strcmp(optarg, "maximal") == 0)
- conf->format_style = FORMAT_MAXIMAL;
+ else if (strcmp(optarg, "rusage") == 0)
+ conf->format_style = FORMAT_RUSAGE;
else
usage(1, "Unknown format style.");
break;
@@ -333,9 +177,8 @@ int main(int argc, char** argv)
format_like_time(conf);
break;
case FORMAT_NORMAL:
- format_normal(conf);
- case FORMAT_MAXIMAL:
- // XXX
+ case FORMAT_RUSAGE:
+ format_other(conf);
break;
}
}
View
2  multitime.h
@@ -19,7 +19,7 @@
// IN THE SOFTWARE.
-enum Format_Style {FORMAT_LIKE_TIME, FORMAT_NORMAL, FORMAT_MAXIMAL};
+enum Format_Style {FORMAT_LIKE_TIME, FORMAT_NORMAL, FORMAT_RUSAGE};
typedef struct {
enum Format_Style format_style;

No commit comments for this range

Something went wrong with that request. Please try again.