From: Brian Aker Date: Sat, 29 Sep 2007 16:32:32 +0000 (-0700) Subject: Added basic print output. X-Git-Tag: 0.3~8 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=151506dd4b5da014f23438226ee286772a78dfd3;p=awesomized%2Flibmemcached Added basic print output. --- diff --git a/lib/memcached_get.c b/lib/memcached_get.c index aedfd001..aa50d70b 100644 --- a/lib/memcached_get.c +++ b/lib/memcached_get.c @@ -15,11 +15,11 @@ static char *memcached_value_fetch(memcached_st *ptr, char *key, size_t *key_len assert(flags); assert(error); + memset(buffer, 0, MEMCACHED_DEFAULT_COMMAND_SIZE); end_ptr= buffer + MEMCACHED_DEFAULT_COMMAND_SIZE; *value_length= 0; - memset(buffer, 0, MEMCACHED_DEFAULT_COMMAND_SIZE); *error= memcached_response(ptr, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, server_key); if (*error == MEMCACHED_SUCCESS) diff --git a/src/memslap.c b/src/memslap.c index 3551536b..661790ab 100644 --- a/src/memslap.c +++ b/src/memslap.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -21,6 +22,14 @@ static const char ALPHANUMERICS[]= /* Types */ typedef struct pairs_st pairs_st; +typedef struct conclusions_st conclusions_st; + +struct conclusions_st { + long int load_time; + long int read_time; + unsigned int rows_loaded; + unsigned int rows_read; +}; struct pairs_st { char *key; @@ -34,9 +43,10 @@ void options_parse(int argc, char *argv[]); static pairs_st *pairs_generate(void); static void pairs_free(pairs_st *pairs); static void get_random_string(char *buffer, size_t size); +void conclusions_print(conclusions_st *conclusion); static int opt_verbose= 0; -static int opt_default_pairs= 100; +static unsigned int opt_default_pairs= 100; static int opt_displayflag= 0; static char *opt_servers= NULL; @@ -45,7 +55,11 @@ int main(int argc, char *argv[]) unsigned int x; memcached_return rc; memcached_st *memc; + struct timeval start_time, end_time; pairs_st *pairs; + conclusions_st conclusion; + + memset(&conclusion, 0, sizeof(conclusions_st)); srandom(time(NULL)); memc= memcached_init(NULL); @@ -59,20 +73,23 @@ int main(int argc, char *argv[]) pairs= pairs_generate(); + gettimeofday(&start_time, NULL); for (x= 0; x < opt_default_pairs; x++) { - printf("Key(%u) %.10s \t%.10s\n", x, pairs[x].key, pairs[x].value); rc= memcached_set(memc, pairs[x].key, pairs[x].key_length, pairs[x].value, pairs[x].value_length, 0, 0); if (rc != MEMCACHED_SUCCESS) fprintf(stderr, "Failured on insert of %.*s\n", (unsigned int)pairs[x].key_length, pairs[x].key); + conclusion.rows_loaded++; } + gettimeofday(&end_time, NULL); + conclusion.load_time= timedif(end_time, start_time); + gettimeofday(&start_time, NULL); for (x= 0; x < opt_default_pairs; x++) { - printf("Key(%u) %.10s \n", x, pairs[x].key); char *value; size_t value_length; uint16_t flags; @@ -81,13 +98,14 @@ int main(int argc, char *argv[]) &value_length, &flags, &rc); - WATCHPOINT_ERROR(rc); if (rc != MEMCACHED_SUCCESS) fprintf(stderr, "Failured on read of %.*s\n", (unsigned int)pairs[x].key_length, pairs[x].key); - printf("\t%.10s\n", value); + conclusion.rows_read++; free(value); } + gettimeofday(&end_time, NULL); + conclusion.read_time= timedif(end_time, start_time); pairs_free(pairs); @@ -95,6 +113,8 @@ int main(int argc, char *argv[]) memcached_deinit(memc); + conclusions_print(&conclusion); + return 0; } @@ -196,6 +216,16 @@ error: exit(0); } +void conclusions_print(conclusions_st *conclusion) +{ + printf("\tLoaded %u rows\n", conclusion->rows_loaded); + printf("\tRead %u rows\n", conclusion->rows_read); + printf("\tTook %ld.%03ld seconds to load data\n", conclusion->load_time / 1000, + conclusion->load_time % 1000); + printf("\tTook %ld.%03ld seconds to read data\n", conclusion->read_time / 1000, + conclusion->read_time % 1000); +} + static void get_random_string(char *buffer, size_t size) { char *buffer_ptr= buffer; diff --git a/src/utilities.c b/src/utilities.c index 159e97df..3252df86 100644 --- a/src/utilities.c +++ b/src/utilities.c @@ -53,3 +53,14 @@ void parse_opt_servers(memcached_st *memc, begin_ptr++; } } + +long int timedif(struct timeval a, struct timeval b) +{ + register int us, s; + + us = a.tv_usec - b.tv_usec; + us /= 1000; + s = a.tv_sec - b.tv_sec; + s *= 1000; + return s + us; +} diff --git a/src/utilities.h b/src/utilities.h index 7d442f23..777c7765 100644 --- a/src/utilities.h +++ b/src/utilities.h @@ -4,3 +4,4 @@ void parse_opt_servers (memcached_st *ptr, char *opt_servers); char *strdup_cleanup(const char *str); void cleanup(void); +long int timedif(struct timeval a, struct timeval b);