+#ifndef unix
+double getCpuTime(int type)
+{
+FILETIME crtime[1];
+FILETIME xittime[1];
+FILETIME systime[1];
+FILETIME usrtime[1];
+SYSTEMTIME timeconv[1];
+double ans = 0;
+
+ memset (timeconv, 0, sizeof(SYSTEMTIME));
+
+ switch( type ) {
+ case 0:
+ GetSystemTimeAsFileTime (xittime);
+ FileTimeToSystemTime (xittime, timeconv);
+ ans = (double)timeconv->wDayOfWeek * 3600 * 24;
+ break;
+ case 1:
+ GetProcessTimes (GetCurrentProcess(), crtime, xittime, systime, usrtime);
+ FileTimeToSystemTime (usrtime, timeconv);
+ break;
+ case 2:
+ GetProcessTimes (GetCurrentProcess(), crtime, xittime, systime, usrtime);
+ 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 <time.h>
+#include <sys/resource.h>
+
+double getCpuTime(int type)
+{
+struct rusage used[1];
+struct timeval tv[1];
+
+ switch( type ) {
+ case 0:
+ gettimeofday(tv, NULL);
+ return (double)tv->tv_sec + (double)tv->tv_usec / 1000000;
+
+ case 1:
+ getrusage(RUSAGE_SELF, used);
+ return (double)used->ru_utime.tv_sec + (double)used->ru_utime.tv_usec / 1000000;
+
+ case 2:
+ getrusage(RUSAGE_SELF, used);
+ 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;
+BtPageSet set[1];
+BtKey ptr;
+
+#ifdef unix
+ for( idx = 1; idx <= bt->mgr->latchmgr->latchdeployed; idx++ ) {
+ 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 {
+ set->latch = bt->mgr->latchsets + idx;
+ if( set->latch->hash != hashidx )
+ fprintf(stderr, "latchset %d wrong hashidx\n", idx);
+ 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;
+ page_no = LEAF_page;
+
+ while( page_no < bt_getid(bt->mgr->latchmgr->alloc->right) ) {
+ pread (bt->mgr->idx, bt->frame, bt->mgr->page_size, page_no << bt->mgr->page_bits);
+ if( !bt->frame->free )
+ for( idx = 0; idx++ < bt->frame->cnt - 1; ) {
+ ptr = keyptr(bt->frame, idx+1);
+ if( keycmp (keyptr(bt->frame, idx), ptr->key, ptr->len) >= 0 )
+ fprintf(stderr, "page %.8x idx %.2x out of order\n", page_no, idx);
+ }
+
+ if( page_no > LEAF_page )
+ next = page_no + 1;
+ page_no = next;
+ }
+#endif
+}
+