From 6d143f164d43aece6b488cc0e6c8dfece572ece1 Mon Sep 17 00:00:00 2001 From: Will Date: Sun, 25 Mar 2012 19:21:06 +0900 Subject: [PATCH] use more appropriate integer types --- src/stats.c | 12 ++++++------ src/stats.h | 8 ++++---- src/wrk.c | 12 ++++++------ 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/stats.c b/src/stats.c index f92ae8c..a114917 100644 --- a/src/stats.c +++ b/src/stats.c @@ -7,7 +7,7 @@ #include "stats.h" #include "zmalloc.h" -stats *stats_alloc(int samples) { +stats *stats_alloc(uint64_t samples) { stats *stats = zcalloc(sizeof(stats) + sizeof(uint64_t) * samples); stats->samples = samples; return stats; @@ -25,7 +25,7 @@ void stats_record(stats *stats, uint64_t x) { uint64_t stats_min(stats *stats) { uint64_t min = 0; - for (int i = 0; i < stats->limit; i++) { + for (uint64_t i = 0; i < stats->limit; i++) { uint64_t x = stats->data[i]; if (x < min || min == 0) min = x; } @@ -34,7 +34,7 @@ uint64_t stats_min(stats *stats) { uint64_t stats_max(stats *stats) { uint64_t max = 0; - for (int i = 0; i < stats->limit; i++) { + for (uint64_t i = 0; i < stats->limit; i++) { uint64_t x = stats->data[i]; if (x > max || max == 0) max = x; } @@ -44,7 +44,7 @@ uint64_t stats_max(stats *stats) { long double stats_mean(stats *stats) { uint64_t sum = 0; if (stats->limit == 0) return 0.0; - for (int i = 0; i < stats->limit; i++) { + for (uint64_t i = 0; i < stats->limit; i++) { sum += stats->data[i]; } return sum / (long double) stats->limit; @@ -53,7 +53,7 @@ long double stats_mean(stats *stats) { long double stats_stdev(stats *stats, long double mean) { long double sum = 0.0; if (stats->limit < 2) return 0.0; - for (int i = 0; i < stats->limit; i++) { + for (uint64_t i = 0; i < stats->limit; i++) { sum += powl(stats->data[i] - mean, 2); } return sqrtl(sum / (stats->limit - 1)); @@ -64,7 +64,7 @@ long double stats_within_stdev(stats *stats, long double mean, long double stdev long double lower = mean - (stdev * n); uint64_t sum = 0; - for (int i = 0; i < stats->limit; i++) { + for (uint64_t i = 0; i < stats->limit; i++) { uint64_t x = stats->data[i]; if (x >= lower && x <= upper) sum++; } diff --git a/src/stats.h b/src/stats.h index 8970f10..04a9393 100644 --- a/src/stats.h +++ b/src/stats.h @@ -2,13 +2,13 @@ #define STATS_H typedef struct { - int samples; - int index; - int limit; + uint64_t samples; + uint64_t index; + uint64_t limit; uint64_t data[]; } stats; -stats *stats_alloc(int); +stats *stats_alloc(uint64_t); void stats_free(stats *); void stats_record(stats *, uint64_t); uint64_t stats_min(stats *); diff --git a/src/wrk.c b/src/wrk.c index 3d3c0d9..ea97c68 100644 --- a/src/wrk.c +++ b/src/wrk.c @@ -127,14 +127,14 @@ int main(int argc, char **argv) { uint64_t connections = cfg.connections / cfg.threads; uint64_t requests = cfg.requests / cfg.threads; - for (int i = 0; i < cfg.threads; i++) { + for (uint64_t i = 0; i < cfg.threads; i++) { thread *t = &threads[i]; t->connections = connections; t->requests = requests; if (pthread_create(&t->thread, NULL, &thread_main, t)) { char *msg = strerror(errno); - fprintf(stderr, "unable to create thread %d %s\n", i, msg); + fprintf(stderr, "unable to create thread %zu %s\n", i, msg); exit(2); } } @@ -147,7 +147,7 @@ int main(int argc, char **argv) { uint64_t bytes = 0; errors errors = { 0 }; - for (int i = 0; i < cfg.threads; i++) { + for (uint64_t i = 0; i < cfg.threads; i++) { thread *t = &threads[i]; pthread_join(t->thread, NULL); @@ -198,7 +198,7 @@ void *thread_main(void *arg) { connection *c = thread->cs; - for (int i = 0; i < thread->connections; i++, c++) { + for (uint64_t i = 0; i < thread->connections; i++, c++) { c->thread = thread; c->latency = 0; connect_socket(thread, c); @@ -308,7 +308,7 @@ static int check_timeouts(aeEventLoop *loop, long long id, void *data) { uint64_t maxAge = time_us() - (cfg.timeout * 1000); - for (int i = 0; i < thread->connections; i++, c++) { + for (uint64_t i = 0; i < thread->connections; i++, c++) { if (maxAge > c->start) { thread->errors.timeout++; } @@ -334,7 +334,7 @@ static void socket_writeable(aeEventLoop *loop, int fd, void *data, int mask) { static void socket_readable(aeEventLoop *loop, int fd, void *data, int mask) { connection *c = data; - int n; + ssize_t n; if ((n = read(fd, c->buf, sizeof(c->buf))) == -1) goto error; if (http_parser_execute(&c->parser, &parser_settings, c->buf, n) != n) goto error;