Skip to content

Commit

Permalink
Simplify stats aggregation code
Browse files Browse the repository at this point in the history
We can use memset, unlike what the previous comment said, because this is a
one-time allocated thread_stats struct that doesn't actually use the mutex
for anything. This simplifies the setup code a decent amount and makes one
fewer place where things need to be added if a new stat is introduced.

Signed-off-by: Dan McGee <[email protected]>
  • Loading branch information
toofishes authored and dustin committed Nov 3, 2010
1 parent 3d8d80d commit 92d6e12
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -503,22 +503,10 @@ void threadlocal_stats_reset(void) {

void threadlocal_stats_aggregate(struct thread_stats *stats) {
int ii, sid;
/* The struct contains a mutex, so I should probably not memset it.. */
stats->get_cmds = 0;
stats->get_misses = 0;
stats->delete_misses = 0;
stats->incr_misses = 0;
stats->decr_misses = 0;
stats->cas_misses = 0;
stats->bytes_written = 0;
stats->bytes_read = 0;
stats->flush_cmds = 0;
stats->conn_yields = 0;
stats->auth_cmds = 0;
stats->auth_errors = 0;

memset(stats->slab_stats, 0,
sizeof(struct slab_stats) * MAX_NUMBER_OF_SLAB_CLASSES);

/* The struct has a mutex, but we can safely set the whole thing
* to zero since it is unused when aggregating. */
memset(stats, 0, sizeof(*stats));

for (ii = 0; ii < settings.num_threads; ++ii) {
pthread_mutex_lock(&threads[ii].stats.mutex);
Expand Down

0 comments on commit 92d6e12

Please sign in to comment.