e37af94374417fa6f35f3b8a9a9629226905610a hiram Tue Jul 11 15:31:54 2017 -0700 would like to have vmPeak value to decide on memory usage refs #18969 diff --git src/lib/obscure.c src/lib/obscure.c index 5f53b6f..9b95092 100644 --- src/lib/obscure.c +++ src/lib/obscure.c @@ -1,27 +1,28 @@ /* Obscure stuff that is handy every now and again. * * This file is copyright 2002 Jim Kent, but license is hereby * granted for all use - public, private or commercial. */ #include "common.h" #include <unistd.h> #include "portable.h" #include "localmem.h" #include "hash.h" #include "obscure.h" #include "linefile.h" +#include "sqlNum.h" static int _dotForUserMod = 100; /* How often does dotForUser() output a dot. */ long incCounterFile(char *fileName) /* Increment a 32 bit value on disk. */ { long val = 0; FILE *f = fopen(fileName, "r+b"); if (f != NULL) { mustReadOne(f, val); rewind(f); } else { @@ -802,30 +803,59 @@ } } void spaceToUnderbar(char *s) /* Convert white space to underbar. */ { char c; while ((c = *s) != 0) { if (isspace(c)) *s = '_'; ++s; } } +long long currentVmPeak() +/* return value of peak Vm memory usage (if /proc/ business exists) */ +{ +long long vmPeak = 0; + +pid_t pid = getpid(); +char temp[256]; +safef(temp, sizeof(temp), "/proc/%d/status", (int) pid); +struct lineFile *lf = lineFileMayOpen(temp, TRUE); +if (lf) + { + char *line; + while (lineFileNextReal(lf, &line)) + { // typical line: 'VmPeak: 62646196 kB' + // seems to always be kB + if (stringIn("VmPeak", line)) + { + char *words[3]; + chopByWhite(line, words, 3); + vmPeak = sqlLongLong(words[1]); // assume always 2nd word + break; + } + } + lineFileClose(&lf); + } + +return vmPeak; +} + void printVmPeak() /* print to stderr peak Vm memory usage (if /proc/ business exists) */ { pid_t pid = getpid(); char temp[256]; safef(temp, sizeof(temp), "/proc/%d/status", (int) pid); struct lineFile *lf = lineFileMayOpen(temp, TRUE); if (lf) { char *line; while (lineFileNextReal(lf, &line)) { if (stringIn("VmPeak", line)) { fprintf(stderr, "# pid=%d: %s\n", pid, line);