From 25e231db858dec0fd5946e2b62095b7cf0ae6f81 Mon Sep 17 00:00:00 2001 From: Paul Fee Date: Fri, 15 Apr 2022 00:24:50 +0100 Subject: [PATCH 1/3] Switch from fprintf to printf. Since print_page_residency_chart() was only ever called with the first parameter set to stdout, this API flexibility is not used. Simplify API until it's needed by removing the first parameter. --- vmtouch.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/vmtouch.c b/vmtouch.c index 8accef3..b1a6828 100644 --- a/vmtouch.c +++ b/vmtouch.c @@ -436,7 +436,7 @@ double gettimeofday_as_double() { -void print_page_residency_chart(FILE *out, char *mincore_array, int64_t pages_in_file) { +void print_page_residency_chart(char *mincore_array, int64_t pages_in_file) { int64_t pages_in_core=0; int64_t pages_per_char; int64_t i,j=0,curr=0; @@ -444,7 +444,7 @@ void print_page_residency_chart(FILE *out, char *mincore_array, int64_t pages_in if (pages_in_file <= RESIDENCY_CHART_WIDTH) pages_per_char = 1; else pages_per_char = (pages_in_file / RESIDENCY_CHART_WIDTH) + 1; - fprintf(out, "\r["); + printf("\r["); for (i=0; i (last_chart_print_time+CHART_UPDATE_INTERVAL)) { last_chart_print_time = temp_time; - print_page_residency_chart(stdout, mincore_array, pages_in_range); + print_page_residency_chart(mincore_array, pages_in_range); } } } } if (o_verbose) { - print_page_residency_chart(stdout, mincore_array, pages_in_range); + print_page_residency_chart(mincore_array, pages_in_range); printf("\n"); } From 4c878f22f8789fc313ad88992b68b1629a5b32ab Mon Sep 17 00:00:00 2001 From: Paul Fee Date: Fri, 15 Apr 2022 00:28:44 +0100 Subject: [PATCH 2/3] Make function file scoped. This makes it easier to reason about function, knowing that it's never called outside this compilation unit. --- vmtouch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vmtouch.c b/vmtouch.c index b1a6828..8e178d3 100644 --- a/vmtouch.c +++ b/vmtouch.c @@ -436,7 +436,7 @@ double gettimeofday_as_double() { -void print_page_residency_chart(char *mincore_array, int64_t pages_in_file) { +static void print_page_residency_chart(char *mincore_array, int64_t pages_in_file) { int64_t pages_in_core=0; int64_t pages_per_char; int64_t i,j=0,curr=0; From ab21a140308ad8868f2c92b7dbbc92728d25d63d Mon Sep 17 00:00:00 2001 From: Paul Fee Date: Fri, 15 Apr 2022 00:41:44 +0100 Subject: [PATCH 3/3] Move CR printing from print_page_residency_chart. The carriage return is not needed the first time print_page_residency_chart() is called. By moving \r printing to the caller, it knows which is the first time. Only within the o_touch loop is print_page_residency_chart() called multiple times, so only within that loop is \r necessary. The final call to print_page_residency_chart() has been removed since it would print identical content to the previous time it was called, whether than be within the o_touch loop or not. Hence it has been removed as all that's needed is to terminate the line with \n. --- vmtouch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vmtouch.c b/vmtouch.c index 8e178d3..cbccd47 100644 --- a/vmtouch.c +++ b/vmtouch.c @@ -444,7 +444,7 @@ static void print_page_residency_chart(char *mincore_array, int64_t pages_in_fil if (pages_in_file <= RESIDENCY_CHART_WIDTH) pages_per_char = 1; else pages_per_char = (pages_in_file / RESIDENCY_CHART_WIDTH) + 1; - printf("\r["); + printf("["); for (i=0; i (last_chart_print_time+CHART_UPDATE_INTERVAL)) { last_chart_print_time = temp_time; + printf("\r"); print_page_residency_chart(mincore_array, pages_in_range); } } @@ -650,7 +651,6 @@ void vmtouch_file(char *path) { } if (o_verbose) { - print_page_residency_chart(mincore_array, pages_in_range); printf("\n"); }