Skip to content

Commit

Permalink
Merge pull request #91 from rdhatt/master
Browse files Browse the repository at this point in the history
Machine readable output kvp-style
  • Loading branch information
hoytech committed Aug 15, 2021
2 parents 3382336 + 3a98f35 commit b77ff04
Showing 1 changed file with 37 additions and 16 deletions.
53 changes: 37 additions & 16 deletions vmtouch.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,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;


Expand Down Expand Up @@ -182,6 +183,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 <pidfile> write a pidfile (only useful together with -l or -L)\n");
printf(" -o <type> output in machine friendly format. 'kv' for key=value pairs.\n");
printf(" -v verbose\n");
printf(" -q quiet\n");
exit(1);
Expand Down Expand Up @@ -957,7 +959,7 @@ 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, "tevqlLdfFh0i:I:p:b:m:P:wo:")) != -1) {
switch(ch) {
case '?': usage(); break;
case 't': o_touch = 1; break;
Expand Down Expand Up @@ -985,6 +987,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;
}
}

Expand Down Expand Up @@ -1033,6 +1036,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))
Expand All @@ -1044,7 +1052,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();

Expand All @@ -1054,22 +1062,35 @@ 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 (strncmp (o_output,"kv",2) == 0) {
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\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 {
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_size));
else if (o_evict)
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_size));
printf("%s ", pretty_print_size(total_pages_size));
if (total_pages)
printf("%.3g%%", total_pages_in_core_perc);
printf("\n");
}
printf(" Elapsed: %.5g seconds\n", elapsed);
}
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;
Expand Down

0 comments on commit b77ff04

Please sign in to comment.