From db1ba8648b17f7502985a6d761f0370ae1ccf44e Mon Sep 17 00:00:00 2001 From: Rajbeer Dhatt Date: Fri, 9 Jul 2021 21:41:33 -0700 Subject: [PATCH 1/6] New '-k' option to output machine-friendly key value pairs. --- vmtouch.c | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/vmtouch.c b/vmtouch.c index af40f52..f2ea7bb 100644 --- a/vmtouch.c +++ b/vmtouch.c @@ -130,6 +130,7 @@ int o_touch=0; int o_evict=0; int o_quiet=0; int o_verbose=0; +int o_keyvalue=0; int o_lock=0; int o_lockall=0; int o_daemon=0; @@ -957,13 +958,14 @@ int main(int argc, char **argv) { pagesize = sysconf(_SC_PAGESIZE); - while((ch = getopt(argc, argv, "tevqlLdfFh0i:I:p:b:m:P:w")) != -1) { + while((ch = getopt(argc, argv, "tevqklLdfFh0i:I:p:b:m:P:w")) != -1) { switch(ch) { case '?': usage(); break; case 't': o_touch = 1; break; case 'e': o_evict = 1; break; case 'q': o_quiet = 1; break; case 'v': o_verbose++; break; + case 'k': o_keyvalue = 1; break; case 'l': o_lock = 1; o_touch = 1; break; case 'L': o_lockall = 1; @@ -1054,22 +1056,34 @@ int main(int argc, char **argv) { } if (!o_quiet) { - if (o_verbose) printf("\n"); - printf(" Files: %" PRId64 "\n", total_files); - printf(" Directories: %" PRId64 "\n", total_dirs); - if (o_touch) - printf(" Touched Pages: %" PRId64 " (%s)\n", total_pages, pretty_print_size(total_pages*pagesize)); - else if (o_evict) - printf(" Evicted Pages: %" PRId64 " (%s)\n", total_pages, pretty_print_size(total_pages*pagesize)); + if (o_keyvalue) { + char pagestr[9]; + if (o_touch) + strcpy(pagestr, "Touched"); + else if (o_evict) + strcpy(pagestr, "Evicted"); + else + strcpy(pagestr, "Resident"); + printf("Files=%" PRId64 " Directories=%" PRId64 " %sPages=%" PRId64 " TotalPages=%" PRId64 " %sSize=%" PRId64 " TotalSize=%" PRId64 " %sPercent=%.3g Elapsed=%.5g", total_files, total_dirs, pagestr, total_pages_in_core, total_pages, pagestr, total_pages_in_core*pagesize, total_pages*pagesize, pagestr, 100.0*total_pages_in_core/total_pages, (end_time.tv_sec - start_time.tv_sec) + (double)(end_time.tv_usec - start_time.tv_usec)/1000000.0); + } else { - printf(" Resident Pages: %" PRId64 "/%" PRId64 " ", total_pages_in_core, total_pages); - printf("%s/", pretty_print_size(total_pages_in_core*pagesize)); - printf("%s ", pretty_print_size(total_pages*pagesize)); - if (total_pages) - printf("%.3g%%", 100.0*total_pages_in_core/total_pages); - printf("\n"); + if (o_verbose) printf("\n"); + printf(" Files: %" PRId64 "\n", total_files); + printf(" Directories: %" PRId64 "\n", total_dirs); + if (o_touch) + printf(" Touched Pages: %" PRId64 " (%s)\n", total_pages, pretty_print_size(total_pages*pagesize)); + else if (o_evict) + printf(" Evicted Pages: %" PRId64 " (%s)\n", total_pages, pretty_print_size(total_pages*pagesize)); + else { + printf(" Resident Pages: %" PRId64 "/%" PRId64 " ", total_pages_in_core, total_pages); + printf("%s/", pretty_print_size(total_pages_in_core*pagesize)); + printf("%s ", pretty_print_size(total_pages*pagesize)); + if (total_pages) + printf("%.3g%%", 100.0*total_pages_in_core/total_pages); + printf("\n"); + } + printf(" Elapsed: %.5g seconds\n", (end_time.tv_sec - start_time.tv_sec) + (double)(end_time.tv_usec - start_time.tv_usec)/1000000.0); } - printf(" Elapsed: %.5g seconds\n", (end_time.tv_sec - start_time.tv_sec) + (double)(end_time.tv_usec - start_time.tv_usec)/1000000.0); } return 0; From e1daebca7015352b99c3a3178307c4c244da84a4 Mon Sep 17 00:00:00 2001 From: Rajbeer Dhatt Date: Fri, 9 Jul 2021 21:50:15 -0700 Subject: [PATCH 2/6] Append newline to kvp output. --- vmtouch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vmtouch.c b/vmtouch.c index f2ea7bb..9a3b086 100644 --- a/vmtouch.c +++ b/vmtouch.c @@ -1064,7 +1064,7 @@ int main(int argc, char **argv) { strcpy(pagestr, "Evicted"); else strcpy(pagestr, "Resident"); - printf("Files=%" PRId64 " Directories=%" PRId64 " %sPages=%" PRId64 " TotalPages=%" PRId64 " %sSize=%" PRId64 " TotalSize=%" PRId64 " %sPercent=%.3g Elapsed=%.5g", total_files, total_dirs, pagestr, total_pages_in_core, total_pages, pagestr, total_pages_in_core*pagesize, total_pages*pagesize, pagestr, 100.0*total_pages_in_core/total_pages, (end_time.tv_sec - start_time.tv_sec) + (double)(end_time.tv_usec - start_time.tv_usec)/1000000.0); + printf("Files=%" PRId64 " Directories=%" PRId64 " %sPages=%" PRId64 " TotalPages=%" PRId64 " %sSize=%" PRId64 " TotalSize=%" PRId64 " %sPercent=%.3g Elapsed=%.5g\n", total_files, total_dirs, pagestr, total_pages_in_core, total_pages, pagestr, total_pages_in_core*pagesize, total_pages*pagesize, pagestr, 100.0*total_pages_in_core/total_pages, (end_time.tv_sec - start_time.tv_sec) + (double)(end_time.tv_usec - start_time.tv_usec)/1000000.0); } else { if (o_verbose) printf("\n"); From 3951cceb59b87068df0da4ab3dea287bc01b99a4 Mon Sep 17 00:00:00 2001 From: Rajbeer Dhatt Date: Tue, 27 Jul 2021 01:23:13 -0700 Subject: [PATCH 3/6] Consolidate display math into one place. This plus wrapping after printf format string gets line length under control. --- vmtouch.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/vmtouch.c b/vmtouch.c index 9a3b086..33e2186 100644 --- a/vmtouch.c +++ b/vmtouch.c @@ -1035,6 +1035,11 @@ int main(int argc, char **argv) { gettimeofday(&end_time, NULL); + int64_t total_pages_in_core_size = total_pages_in_core * pagesize; + int64_t total_pages_size = total_pages * pagesize; + double total_pages_in_core_perc = 100.0*total_pages_in_core/total_pages; + double elapsed = (end_time.tv_sec - start_time.tv_sec) + (double)(end_time.tv_usec - start_time.tv_usec)/1000000.0; + if (o_lock || o_lockall) { if (o_lockall) { if (mlockall(MCL_CURRENT)) @@ -1046,7 +1051,7 @@ int main(int argc, char **argv) { write_pidfile(); } - if (!o_quiet) printf("LOCKED %" PRId64 " pages (%s)\n", total_pages, pretty_print_size(total_pages*pagesize)); + if (!o_quiet) printf("LOCKED %" PRId64 " pages (%s)\n", total_pages, pretty_print_size(total_pages_size)); if (o_wait) reopen_all(); @@ -1064,25 +1069,26 @@ int main(int argc, char **argv) { strcpy(pagestr, "Evicted"); else strcpy(pagestr, "Resident"); - printf("Files=%" PRId64 " Directories=%" PRId64 " %sPages=%" PRId64 " TotalPages=%" PRId64 " %sSize=%" PRId64 " TotalSize=%" PRId64 " %sPercent=%.3g Elapsed=%.5g\n", total_files, total_dirs, pagestr, total_pages_in_core, total_pages, pagestr, total_pages_in_core*pagesize, total_pages*pagesize, pagestr, 100.0*total_pages_in_core/total_pages, (end_time.tv_sec - start_time.tv_sec) + (double)(end_time.tv_usec - start_time.tv_usec)/1000000.0); + printf("Files=%" PRId64 " Directories=%" PRId64 " %sPages=%" PRId64 " TotalPages=%" PRId64 " %sSize=%" PRId64 " TotalSize=%" PRId64 " %sPercent=%.3g Elapsed=%.5g\n", + total_files, total_dirs, pagestr, total_pages_in_core, total_pages, pagestr, total_pages_in_core_size, total_pages_size, pagestr, total_pages_in_core_perc, elapsed); } else { if (o_verbose) printf("\n"); printf(" Files: %" PRId64 "\n", total_files); printf(" Directories: %" PRId64 "\n", total_dirs); if (o_touch) - printf(" Touched Pages: %" PRId64 " (%s)\n", total_pages, pretty_print_size(total_pages*pagesize)); + printf(" Touched Pages: %" PRId64 " (%s)\n", total_pages, pretty_print_size(total_pages_size)); else if (o_evict) - printf(" Evicted Pages: %" PRId64 " (%s)\n", total_pages, pretty_print_size(total_pages*pagesize)); + printf(" Evicted Pages: %" PRId64 " (%s)\n", total_pages, pretty_print_size(total_pages_size)); else { printf(" Resident Pages: %" PRId64 "/%" PRId64 " ", total_pages_in_core, total_pages); - printf("%s/", pretty_print_size(total_pages_in_core*pagesize)); - printf("%s ", pretty_print_size(total_pages*pagesize)); + printf("%s/", pretty_print_size(total_pages_in_core_size)); + printf("%s ", pretty_print_size(total_pages_size)); if (total_pages) - printf("%.3g%%", 100.0*total_pages_in_core/total_pages); + printf("%.3g%%", total_pages_in_core_perc); printf("\n"); } - printf(" Elapsed: %.5g seconds\n", (end_time.tv_sec - start_time.tv_sec) + (double)(end_time.tv_usec - start_time.tv_usec)/1000000.0); + printf(" Elapsed: %.5g seconds\n", elapsed); } } From 806c866022b4cc7b514ad7a7c91ffe1ec7066f72 Mon Sep 17 00:00:00 2001 From: Rajbeer Dhatt Date: Fri, 13 Aug 2021 20:34:17 -0700 Subject: [PATCH 4/6] Add -o argument that formats output. Implements 'kv' type that renders simple key=value pairs. This replaces the previous '-k' implemenation. --- vmtouch.c | 8 +++++--- vmtouch.dSYM/Contents/Info.plist | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 vmtouch.dSYM/Contents/Info.plist diff --git a/vmtouch.c b/vmtouch.c index 33e2186..285b2b1 100644 --- a/vmtouch.c +++ b/vmtouch.c @@ -141,6 +141,7 @@ size_t o_max_file_size=SIZE_MAX; int o_wait=0; static char *o_batch = NULL; static char *o_pidfile = NULL; +static char *o_output = NULL; int o_0_delim = 0; @@ -183,6 +184,7 @@ void usage() { printf(" -0 in batch mode (-b) separate paths with NUL byte instead of newline\n"); printf(" -w wait until all pages are locked (only useful together with -d)\n"); printf(" -P write a pidfile (only useful together with -l or -L)\n"); + printf(" -o output in machine friendly format. 'kv' for key=value pairs.\n"); printf(" -v verbose\n"); printf(" -q quiet\n"); exit(1); @@ -958,14 +960,13 @@ int main(int argc, char **argv) { pagesize = sysconf(_SC_PAGESIZE); - while((ch = getopt(argc, argv, "tevqklLdfFh0i:I:p:b:m:P:w")) != -1) { + while((ch = getopt(argc, argv, "tevqlLdfFh0i:I:p:b:m:P:wo:")) != -1) { switch(ch) { case '?': usage(); break; case 't': o_touch = 1; break; case 'e': o_evict = 1; break; case 'q': o_quiet = 1; break; case 'v': o_verbose++; break; - case 'k': o_keyvalue = 1; break; case 'l': o_lock = 1; o_touch = 1; break; case 'L': o_lockall = 1; @@ -987,6 +988,7 @@ int main(int argc, char **argv) { case 'b': o_batch = optarg; break; case '0': o_0_delim = 1; break; case 'P': o_pidfile = optarg; break; + case 'o': o_output = optarg; break; } } @@ -1061,7 +1063,7 @@ int main(int argc, char **argv) { } if (!o_quiet) { - if (o_keyvalue) { + if (strncmp (o_output,"kv",2) == 0) { char pagestr[9]; if (o_touch) strcpy(pagestr, "Touched"); diff --git a/vmtouch.dSYM/Contents/Info.plist b/vmtouch.dSYM/Contents/Info.plist new file mode 100644 index 0000000..dacddd2 --- /dev/null +++ b/vmtouch.dSYM/Contents/Info.plist @@ -0,0 +1,20 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleIdentifier + com.apple.xcode.dsym.vmtouch + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + dSYM + CFBundleSignature + ???? + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + + From dc13da493383e7b3148e2cf9149ceffd28118825 Mon Sep 17 00:00:00 2001 From: Rajbeer Dhatt Date: Fri, 13 Aug 2021 21:53:12 -0700 Subject: [PATCH 5/6] Embarrassingly removing debug symbol build artifacts. --- vmtouch.dSYM/Contents/Info.plist | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100644 vmtouch.dSYM/Contents/Info.plist diff --git a/vmtouch.dSYM/Contents/Info.plist b/vmtouch.dSYM/Contents/Info.plist deleted file mode 100644 index dacddd2..0000000 --- a/vmtouch.dSYM/Contents/Info.plist +++ /dev/null @@ -1,20 +0,0 @@ - - - - - CFBundleDevelopmentRegion - English - CFBundleIdentifier - com.apple.xcode.dsym.vmtouch - CFBundleInfoDictionaryVersion - 6.0 - CFBundlePackageType - dSYM - CFBundleSignature - ???? - CFBundleShortVersionString - 1.0 - CFBundleVersion - 1 - - From 3a98f35d51f6a48cac05acc0a354fdf774456f84 Mon Sep 17 00:00:00 2001 From: Rajbeer Dhatt Date: Fri, 13 Aug 2021 23:34:47 -0700 Subject: [PATCH 6/6] Remove vestigial variable From previous -k implementation. --- vmtouch.c | 1 - 1 file changed, 1 deletion(-) diff --git a/vmtouch.c b/vmtouch.c index 285b2b1..72e7f28 100644 --- a/vmtouch.c +++ b/vmtouch.c @@ -130,7 +130,6 @@ int o_touch=0; int o_evict=0; int o_quiet=0; int o_verbose=0; -int o_keyvalue=0; int o_lock=0; int o_lockall=0; int o_daemon=0;