aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Lu <aaron.lu@intel.com>2016-09-30 14:38:52 +0800
committerFengguang Wu <fengguang.wu@intel.com>2016-10-08 14:16:23 +0800
commitc357a069e66c2e9e84904bba605aecfca5fa38c6 (patch)
tree25b7bb99d04a3c4866f6989a23b36e9cb240c49d
parent75cc5d3d4413d9916f1d441c58cca3724d8089b5 (diff)
downloadvm-scalability-c357a069e66c2e9e84904bba605aecfca5fa38c6.tar.gz
usemem: introduce output_statistics
The code to output statistics is useful later so make a new function for it. There should be no functional change. Signed-off-by: Aaron Lu <aaron.lu@intel.com> Signed-off-by: Fengguang Wu <fengguang.wu@intel.com>
-rw-r--r--usemem.c38
1 files changed, 21 insertions, 17 deletions
diff --git a/usemem.c b/usemem.c
index bd75aa9..9af6bdc 100644
--- a/usemem.c
+++ b/usemem.c
@@ -538,11 +538,28 @@ unsigned long do_unit(unsigned long bytes, struct drand48_data *rand_data)
return rw_bytes;
}
-long do_units(void)
+static void output_statistics(unsigned long unit_bytes)
{
- struct drand48_data rand_data;
+ struct timeval stop;
+ char buf[1024];
+ size_t len;
unsigned long delta_us;
unsigned long throughput;
+
+ gettimeofday(&stop, NULL);
+ delta_us = (stop.tv_sec - start_time.tv_sec) * 1000000 +
+ (stop.tv_usec - start_time.tv_usec);
+ throughput = ((unit_bytes * 1000000ULL) >> 10) / delta_us;
+ len = snprintf(buf, sizeof(buf),
+ "%lu bytes / %lu usecs = %lu KB/s\n",
+ unit_bytes, delta_us, throughput);
+ fflush(stdout);
+ write(1, buf, len);
+}
+
+long do_units(void)
+{
+ struct drand48_data rand_data;
unsigned long unit_bytes = done_bytes;
unsigned long bytes = opt_bytes;
@@ -567,21 +584,8 @@ long do_units(void)
break;
} while (bytes);
- if (unit_bytes) {
- struct timeval stop;
- char buf[1024];
- size_t len;
-
- gettimeofday(&stop, NULL);
- delta_us = (stop.tv_sec - start_time.tv_sec) * 1000000 +
- (stop.tv_usec - start_time.tv_usec);
- throughput = ((unit_bytes * 1000000ULL) >> 10) / delta_us;
- len = snprintf(buf, sizeof(buf),
- "%lu bytes / %lu usecs = %lu KB/s\n",
- unit_bytes, delta_us, throughput);
- fflush(stdout);
- write(1, buf, len);
- }
+ if (unit_bytes)
+ output_statistics(unit_bytes);
if (opt_detach && up(sem_id))
perror("up");