diff --git a/src/redis.c b/src/redis.c index 3a9ab219..6070175a 100644 --- a/src/redis.c +++ b/src/redis.c @@ -1453,6 +1453,7 @@ void initServerConfig(void) { server.assert_line = 0; server.bug_report_start = 0; server.watchdog_period = 0; + server.use_cmd_time_accounting = 0; /* XXX: this should be configurable. */ } /* This function will try to raise the max number of open files accordingly to @@ -1932,6 +1933,9 @@ void forceCommandPropagation(redisClient *c, int flags) { /* Call() is the core of Redis execution of a command */ void call(redisClient *c, int flags) { long long dirty, start, duration; + int get_duration = server.latency_monitor_threshold != 0 || + server.slowlog_log_slower_than != 0 || + server.use_cmd_time_accounting != 0; int client_old_flags = c->flags; /* Sent the command to clients in MONITOR mode, only if the commands are @@ -1947,9 +1951,9 @@ void call(redisClient *c, int flags) { c->flags &= ~(REDIS_FORCE_AOF|REDIS_FORCE_REPL); redisOpArrayInit(&server.also_propagate); dirty = server.dirty; - start = ustime(); + if (get_duration) start = ustime(); c->cmd->proc(c); - duration = ustime()-start; + if (get_duration) duration = ustime()-start; dirty = server.dirty-dirty; if (dirty < 0) dirty = 0; @@ -1970,14 +1974,18 @@ void call(redisClient *c, int flags) { /* Log the command into the Slow log if needed, and populate the * per-command statistics that we show in INFO commandstats. */ - if (flags & REDIS_CALL_SLOWLOG && c->cmd->proc != execCommand) { + if (get_duration && + flags & REDIS_CALL_SLOWLOG && + c->cmd->proc != execCommand) + { char *latency_event = (c->cmd->flags & REDIS_CMD_FAST) ? "fast-command" : "command"; latencyAddSampleIfNeeded(latency_event,duration/1000); slowlogPushEntryIfNeeded(c->argv,c->argc,duration); } + if (flags & REDIS_CALL_STATS) { - c->cmd->microseconds += duration; + if (server.use_cmd_time_accounting) c->cmd->microseconds += duration; c->cmd->calls++; } diff --git a/src/redis.h b/src/redis.h index bd6e4939..3154f3e4 100644 --- a/src/redis.h +++ b/src/redis.h @@ -666,6 +666,7 @@ struct redisServer { size_t resident_set_size; /* RSS sampled in serverCron(). */ long long stat_net_input_bytes; /* Bytes read from network. */ long long stat_net_output_bytes; /* Bytes written to network. */ + int use_cmd_time_accounting; /* commandstats time accounting. */ /* The following two are used to track instantaneous metrics, like * number of operations per second, network traffic. */ struct {