X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=clients%2Fmemslap.c;h=88a0f21ca25be9b4dde03b8d9b43613d8d368ff5;hb=e110b4a534fd2d052461777411dac53b40c165bf;hp=ac35e9d291d6af7807abc3292ab3dabc7c413335;hpb=98c99981e0ebe7f716bea2e4d95434d159103fcd;p=m6w6%2Flibmemcached diff --git a/clients/memslap.c b/clients/memslap.c index ac35e9d2..88a0f21c 100644 --- a/clients/memslap.c +++ b/clients/memslap.c @@ -13,9 +13,22 @@ * Mingqiang Zhuang * */ +#include "config.h" + #include #include #include +#if TIME_WITH_SYS_TIME +# include +# include +#else +# if HAVE_SYS_TIME_H +# include +# else +# include +# endif +#endif + #include "ms_sigsegv.h" #include "ms_setting.h" @@ -164,7 +177,7 @@ static void ms_global_struct_destroy() */ static void ms_version_command(const char *command_name) { - printf("%s v%u.%u\n", command_name, 1, 0); + printf("%s v%u.%u\n", command_name, 1U, 0U); exit(0); } @@ -287,7 +300,7 @@ void ms_help_command(const char *command_name, const char *description) { char *help_message= NULL; - printf("%s v%u.%u\n", command_name, 1, 0); + printf("%s v%u.%u\n", command_name, 1U, 0U); printf(" %s\n\n", description); printf( "Usage:\n" @@ -298,6 +311,7 @@ void ms_help_command(const char *command_name, const char *description) { printf(" -%c, --%s%c\n", long_options[x].val, long_options[x].name, long_options[x].has_arg ? '=' : ' '); + if ((help_message= (char *)ms_lookup_help(long_options[x].val)) != NULL) { printf(" %s\n", help_message); @@ -417,7 +431,7 @@ static void ms_options_parse(int argc, char *argv[]) break; case OPT_CONCURRENCY: /* --concurrency or -c */ - ms_setting.nconns= atoi(optarg); + ms_setting.nconns= (uint32_t)strtoul(optarg, (char **) NULL, 10); if (ms_setting.nconns <= 0) { fprintf(stderr, "Concurrency must be greater than 0.:-)\n"); @@ -426,7 +440,7 @@ static void ms_options_parse(int argc, char *argv[]) break; case OPT_EXECUTE_NUMBER: /* --execute_number or -x */ - ms_setting.exec_num= atoll(optarg); + ms_setting.exec_num= (int)strtol(optarg, (char **) NULL, 10); if (ms_setting.exec_num <= 0) { fprintf(stderr, "Execute number must be greater than 0.:-)\n"); @@ -435,7 +449,7 @@ static void ms_options_parse(int argc, char *argv[]) break; case OPT_THREAD_NUMBER: /* --threads or -T */ - ms_setting.nthreads= atoi(optarg); + ms_setting.nthreads= (int)strtol(optarg, (char **) NULL, 10); if (ms_setting.nthreads <= 0) { fprintf(stderr, "Threads number must be greater than 0.:-)\n"); @@ -444,7 +458,7 @@ static void ms_options_parse(int argc, char *argv[]) break; case OPT_FIXED_LTH: /* --fixed_size or -X */ - ms_setting.fixed_value_size= (size_t)atoi(optarg); + ms_setting.fixed_value_size= (size_t)strtoull(optarg, (char **) NULL, 10); if ((ms_setting.fixed_value_size <= 0) || (ms_setting.fixed_value_size > MAX_VALUE_SIZE)) { @@ -465,7 +479,7 @@ static void ms_options_parse(int argc, char *argv[]) break; case OPT_GETS_DIVISION: /* --division or -d */ - ms_setting.mult_key_num= atoi(optarg); + ms_setting.mult_key_num= (int)strtol(optarg, (char **) NULL, 10); if (ms_setting.mult_key_num <= 0) { fprintf(stderr, "Multi-get key number must be greater than 0.:-)\n"); @@ -551,7 +565,7 @@ static void ms_options_parse(int argc, char *argv[]) break; case OPT_SOCK_PER_CONN: /* --conn_sock or -n */ - ms_setting.sock_per_conn= atoi(optarg); + ms_setting.sock_per_conn= (int)strtol(optarg, (char **) NULL, 10); if (ms_setting.sock_per_conn <= 0) { fprintf(stderr, "Number of socks of each concurrency " @@ -588,7 +602,7 @@ static void ms_options_parse(int argc, char *argv[]) break; case OPT_REP_WRITE_SRV: /* --rep_write or -p */ - ms_setting.rep_write_srv= atoi(optarg); + ms_setting.rep_write_srv= (int)strtol(optarg, (char **) NULL, 10); if (ms_setting.rep_write_srv <= 0) { fprintf(stderr, @@ -613,11 +627,20 @@ static int ms_check_para() { if (ms_setting.srv_str == NULL) { - fprintf(stderr, "No Servers provided.\n\n"); - return -1; + char *temp; + + if ((temp= getenv("MEMCACHED_SERVERS"))) + { + ms_setting.srv_str= strdup(temp); + } + else + { + fprintf(stderr, "No Servers provided\n\n"); + return -1; + } } - if (ms_setting.nconns % ms_setting.nthreads != 0) + if (ms_setting.nconns % (uint32_t)ms_setting.nthreads != 0) { fprintf(stderr, "Concurrency must be the multiples of threads count.\n"); return -1; @@ -761,7 +784,7 @@ static void ms_monitor_slap_mode() { /* Wait all the connects complete warm up. */ pthread_mutex_lock(&ms_global.init_lock.lock); - while (ms_global.init_lock.count < ms_setting.nconns) + while (ms_global.init_lock.count < (int)ms_setting.nconns) { pthread_cond_wait(&ms_global.init_lock.cond, &ms_global.init_lock.lock); @@ -781,8 +804,8 @@ static void ms_monitor_slap_mode() second++; if ((ms_setting.stat_freq > 0) && (second % ms_setting.stat_freq == 0) - && ((int32_t)ms_stats.active_conns >= ms_setting.nconns) - && (ms_stats.active_conns <= (uint32_t)INT_MAX)) + && (ms_stats.active_conns >= ms_setting.nconns) + && (ms_stats.active_conns <= INT_MAX)) { ms_print_statistics(second); } @@ -811,7 +834,7 @@ static void ms_monitor_slap_mode() * We loop until we know that all connects have cleaned up. */ pthread_mutex_lock(&ms_global.run_lock.lock); - while (ms_global.run_lock.count < ms_setting.nconns) + while (ms_global.run_lock.count < (int)ms_setting.nconns) { pthread_cond_wait(&ms_global.run_lock.cond, &ms_global.run_lock.lock); }