]> pd.if.org Git - btree/blobdiff - threads2i.c
Enhance process times reporting for linux or Windows
[btree] / threads2i.c
index d8ac6be9663ac2ca6825e8ddc5ff8e58570146eb..af913b4cf05b7e69553da0f76eb7df99f0b079f2 100644 (file)
@@ -703,7 +703,7 @@ uint slot;
        CloseHandle(mgr->idx);
        GlobalFree (mgr->pool);
        GlobalFree (mgr->hash);
-       GlobalFree (mgr->latch);
+       GlobalFree ((void *)mgr->latch);
        GlobalFree (mgr);
 #endif
 }
@@ -2135,51 +2135,81 @@ uint bt_tod(BtDb *bt, uint slot)
        return slotptr(bt->cursor,slot)->tod;
 }
 
-
 #ifdef STANDALONE
 
+#ifndef unix
+double getCpuTime(int type)
+{
+FILETIME crtime[1];
+FILETIME xittime[1];
+FILETIME systime[1];
+FILETIME usrtime[1];
+SYSTEMTIME timeconv[1];
+double ans;
+
+       GetProcessTimes (GetCurrentProcess(), crtime, xittime, systime, usrtime);
+       memset (timeconv, 0, sizeof(SYSTEMTIME));
+
+       switch( type ) {
+       case 1:
+               FileTimeToSystemTime (usrtime, timeconv);
+               break;
+       case 2:
+               FileTimeToSystemTime (systime, timeconv);
+               break;
+       }
+
+       ans = (double)timeconv->wHour * 3600;
+       ans += (double)timeconv->wMinute * 60;
+       ans += (double)timeconv->wSecond;
+       ans += (double)timeconv->wMilliseconds / 1000;
+       return ans;
+}
+#else
+#include <sys/time.h>
+#include <sys/resource.h>
+
+double getCpuTime(int type)
+{
+struct rusage used[1];
+
+       getrusage(RUSAGE_SELF, used);
+       switch( type ) {
+       case 1:
+               return (double)used->ru_utime.tv_sec + (double)used->ru_utime.tv_usec / 1000000;
+
+       case 2:
+               return (double)used->ru_stime.tv_sec + (double)used->ru_stime.tv_usec / 1000000;
+       }
+
+       return 0;
+}
+#endif
+
 void bt_latchaudit (BtDb *bt)
 {
 ushort idx, hashidx;
 uid next, page_no;
-BtLatchSet *latch;
-BtPool *pool;
-BtPage page;
+BtPageSet set[1];
 BtKey ptr;
 
 #ifdef unix
        for( idx = 1; idx < bt->mgr->latchmgr->latchdeployed; idx++ ) {
-               latch = bt->mgr->latchsets + idx;
-               if( *(ushort *)latch->readwr ) {
-                       fprintf(stderr, "latchset %d r/w locked for page %.8x\n", idx, latch->page_no);
-                       *(ushort *)latch->readwr = 0;
-               }
-               if( *(ushort *)latch->access ) {
-                       fprintf(stderr, "latchset %d access locked for page %.8x\n", idx, latch->page_no);
-                       *(ushort *)latch->access = 0;
-               }
-               if( *(ushort *)latch->parent ) {
-                       fprintf(stderr, "latchset %d parent locked for page %.8x\n", idx, latch->page_no);
-                       *(ushort *)latch->parent = 0;
-               }
-               if( *(ushort *)latch->busy ) {
-                       fprintf(stderr, "latchset %d busy locked for page %.8x\n", idx, latch->page_no);
-                       *(ushort *)latch->parent = 0;
-               }
-               if( latch->pin ) {
-                       fprintf(stderr, "latchset %d pinned for page %.8x\n", idx, latch->page_no);
-                       latch->pin = 0;
+               set->latch = bt->mgr->latchsets + idx;
+               if( set->latch->pin ) {
+                       fprintf(stderr, "latchset %d pinned for page %.6x\n", idx, set->latch->page_no);
+                       set->latch->pin = 0;
                }
        }
 
        for( hashidx = 0; hashidx < bt->mgr->latchmgr->latchhash; hashidx++ ) {
          if( idx = bt->mgr->latchmgr->table[hashidx].slot ) do {
-               latch = bt->mgr->latchsets + idx;
-               if( latch->hash != hashidx ) {
+               set->latch = bt->mgr->latchsets + idx;
+               if( set->latch->hash != hashidx )
                        fprintf(stderr, "latchset %d wrong hashidx\n", idx);
-                       latch->hash = hashidx;
-               }
-         } while( idx = latch->next );
+               if( set->latch->pin )
+                       fprintf(stderr, "latchset %d pinned for page %.8x\n", idx, set->latch->page_no);
+         } while( idx = set->latch->next );
        }
 
        next = bt->mgr->latchmgr->nlatchpage + LATCH_page;
@@ -2395,6 +2425,7 @@ HANDLE *threads;
 double real_time;
 ThreadArg *args;
 uint poolsize = 0;
+float elapsed;
 int num = 0;
 char key[1];
 BtMgr *mgr;
@@ -2484,7 +2515,13 @@ BtDb *bt;
        time (stop);
        real_time = 1000 * (*stop - *start);
 #endif
-       fprintf(stderr, " Time to complete: %.2f seconds\n", real_time/1000);
+       elapsed = real_time / 1000;
+       fprintf(stderr, " real %dm%.3fs\n", (int)(elapsed/60), elapsed - (int)(elapsed/60)*60);
+       elapsed = getCpuTime(1);
+       fprintf(stderr, " user %dm%.3fs\n", (int)(elapsed/60), elapsed - (int)(elapsed/60)*60);
+       elapsed = getCpuTime(2);
+       fprintf(stderr, " sys  %dm%.3fs\n", (int)(elapsed/60), elapsed - (int)(elapsed/60)*60);
+
        bt_mgrclose (mgr);
 }