lkml.org 
[lkml]   [2020]   [Dec]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] usemem: Add option init-time
Date
From: Hui Zhu <teawaterz@linux.alibaba.com>

This commit add a new option init-time to remove the initialization time
from the run time and show the initialization time.

Signed-off-by: Hui Zhu <teawaterz@linux.alibaba.com>
---
usemem.c | 29 +++++++++++++++++++++++++++--
1 file changed, 27 insertions(+), 2 deletions(-)

diff --git a/usemem.c b/usemem.c
index 823647e..6d1d575 100644
--- a/usemem.c
+++ b/usemem.c
@@ -96,6 +96,7 @@ int opt_bind_interval = 0;
unsigned long opt_delay = 0;
int opt_read_again = 0;
int opt_punch_holes = 0;
+int opt_init_time = 0;
int nr_task;
int nr_thread;
int nr_cpu;
@@ -155,6 +156,7 @@ void usage(int ok)
" -U|--hugetlb allocate hugetlbfs page\n"
" -Z|--read-again read memory again after access the memory\n"
" --punch-holes free every other page after allocation\n"
+ " --init-time remove the initialization time from the run time and show the initialization time\n"
" -h|--help show this message\n"
, ourname);

@@ -193,7 +195,8 @@ static const struct option opts[] = {
{ "delay" , 1, NULL, 'e' },
{ "hugetlb" , 0, NULL, 'U' },
{ "read-again" , 0, NULL, 'Z' },
- { "punch-holes" , 0, NULL, 0 },
+ { "punch-holes" , 0, NULL, 0 },
+ { "init-time" , 0, NULL, 0 },
{ "help" , 0, NULL, 'h' },
{ NULL , 0, NULL, 0 }
};
@@ -945,6 +948,8 @@ int main(int argc, char *argv[])
case 0:
if (strcmp(opts[opt_index].name, "punch-holes") == 0) {
opt_punch_holes = 1;
+ } else if (strcmp(opts[opt_index].name, "init-time") == 0) {
+ opt_init_time = 1;
} else
usage(1);
break;
@@ -1128,7 +1133,7 @@ int main(int argc, char *argv[])
if (optind != argc - 1)
usage(0);

- if (!opt_write_signal_read)
+ if (!opt_write_signal_read || opt_init_time)
gettimeofday(&start_time, NULL);

opt_bytes = memparse(argv[optind], NULL);
@@ -1263,5 +1268,25 @@ int main(int argc, char *argv[])
if (!nr_task)
nr_task = 1;

+ if (opt_init_time) {
+ struct timeval stop;
+ char buf[1024];
+ size_t len;
+ unsigned long delta_us;
+
+ gettimeofday(&stop, NULL);
+ delta_us = (stop.tv_sec - start_time.tv_sec) * 1000000 +
+ (stop.tv_usec - start_time.tv_usec);
+ len = snprintf(buf, sizeof(buf),
+ "the initialization time is %lu secs %lu usecs\n",
+ delta_us / 1000000, delta_us % 1000000);
+ fflush(stdout);
+ if (write(1, buf, len) != len)
+ fprintf(stderr, "WARNING: statistics output may be incomplete.\n");
+
+ if (!opt_write_signal_read)
+ gettimeofday(&start_time, NULL);
+ }
+
return do_tasks();
}
--
2.17.1
\
 
 \ /
  Last update: 2020-12-16 15:00    [W:0.021 / U:1.512 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site