2037f9e6b4e6a2a9445a162809e88aa96703312c
markd
  Tue Apr 13 00:24:40 2021 -0700
log dynamic gfServer clock, user, and system times to help understand performance

diff --git src/lib/osunix.c src/lib/osunix.c
index 545ad93..9bb3f9f 100644
--- src/lib/osunix.c
+++ src/lib/osunix.c
@@ -3,30 +3,31 @@
  * This file is copyright 2002 Jim Kent, but license is hereby
  * granted for all use - public, private or commercial. */
 
 #include "common.h"
 #include <dirent.h>
 #include <sys/utsname.h>
 #include <sys/time.h>
 #include <sys/statvfs.h>
 #include <pwd.h>
 #include <termios.h>
 #include "portable.h"
 #include "portimpl.h"
 #include <sys/wait.h>
 #include <regex.h>
 #include <utime.h>
+#include <sys/resource.h>
 
 
 
 
 off_t fileSize(char *pathname)
 /* get file size for pathname. return -1 if not found */
 {
 struct stat mystat;
 ZeroVar(&mystat);
 if (stat(pathname,&mystat)==-1)
     {
     return -1;
     }
 return mystat.st_size;
 }
@@ -775,15 +776,38 @@
 if (lstat(path, &sb) == -1)
     errnoAbort("lstat failure on %s", path);
 if ((sb.st_mode & S_IFMT) != S_IFLNK)
     errnoAbort("path %s not a symlink.", path);
 return mustReadSymlinkExt(path, &sb);
 }
 
 
 void makeSymLink(char *oldName, char *newName)
 /* Return a symbolic link from newName to oldName or die trying */
 {
 int err = symlink(oldName, newName);
 if (err < 0)
      errnoAbort("Couldn't make symbolic link from %s to %s\n", oldName, newName);
 }
+static double timevalToSeconds(struct timeval tv)
+/* convert a timeval structure to seconds */
+{
+return ((double)tv.tv_sec)  + (1.0e-6 * (double)tv.tv_usec);
+}
+
+struct runTimes getTimesInSeconds(void)
+/* get the current clock time since epoch, process user CPU, and system CPU times, all in
+ * seconds. */
+{
+struct runTimes rts;
+
+struct timeval tv;
+gettimeofday(&tv, NULL);
+rts.clockSecs = timevalToSeconds(tv);
+
+struct rusage usage;
+getrusage(RUSAGE_SELF, &usage);
+rts.userSecs = timevalToSeconds(usage.ru_utime);
+rts.sysSecs = timevalToSeconds(usage.ru_stime);
+
+return rts;
+}