summaryrefslogtreecommitdiffstats
path: root/eval.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2016-06-27 19:51:19 -0400
committerTavian Barnes <tavianator@tavianator.com>2016-06-28 10:14:29 -0400
commit5a4a805a4d460a6996facc5d1fd06986344c899b (patch)
treed58feedf49ea751956b9d334cbd3112853eb9c91 /eval.c
parent814cccec0dfa7da0646dac0cc39f192d8a574cb8 (diff)
downloadbfs-5a4a805a4d460a6996facc5d1fd06986344c899b.tar.xz
Implement -D rates.
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c47
1 files changed, 45 insertions, 2 deletions
diff --git a/eval.c b/eval.c
index f7292a2..48603fb 100644
--- a/eval.c
+++ b/eval.c
@@ -743,10 +743,49 @@ bool eval_xtype(const struct expr *expr, struct eval_state *state) {
}
/**
+ * Record the time that elapsed evaluating an expression.
+ */
+static void add_elapsed(struct expr *expr, const struct timespec *start, const struct timespec *end) {
+ expr->elapsed.tv_sec += end->tv_sec - start->tv_sec;
+ expr->elapsed.tv_nsec += end->tv_nsec - start->tv_nsec;
+ if (expr->elapsed.tv_nsec < 0) {
+ expr->elapsed.tv_nsec += 1000000000L;
+ --expr->elapsed.tv_sec;
+ } else if (expr->elapsed.tv_nsec >= 1000000000L) {
+ expr->elapsed.tv_nsec -= 1000000000L;
+ ++expr->elapsed.tv_sec;
+ }
+}
+
+/**
* Evaluate an expression.
*/
-static bool eval_expr(const struct expr *expr, struct eval_state *state) {
- return expr->eval(expr, state);
+static bool eval_expr(struct expr *expr, struct eval_state *state) {
+ struct timespec start, end;
+ bool time = state->cmdline->debug & DEBUG_RATES;
+ if (time) {
+ if (clock_gettime(CLOCK_MONOTONIC, &start) != 0) {
+ perror("clock_gettime()");
+ time = false;
+ }
+ }
+
+ bool ret = expr->eval(expr, state);
+
+ if (time) {
+ if (clock_gettime(CLOCK_MONOTONIC, &end) == 0) {
+ add_elapsed(expr, &start, &end);
+ } else {
+ perror("clock_gettime()");
+ }
+ }
+
+ ++expr->evaluations;
+ if (ret) {
+ ++expr->successes;
+ }
+
+ return ret;
}
/**
@@ -943,5 +982,9 @@ int eval_cmdline(const struct cmdline *cmdline) {
}
}
+ if (cmdline->debug & DEBUG_RATES) {
+ dump_cmdline(cmdline, true);
+ }
+
return args.ret;
}