do munmap (hash->page, (bt->hashmask+1) << bt->page_bits);
while(hash = hash->lrunext);
- if ( bt->mem )
+ if( bt->mem )
free (bt->mem);
close (bt->idx);
free (bt->cache);
CloseHandle(hash->hmap);
} while(hash = hash->lrunext);
- if ( bt->mem)
+ if( bt->mem)
VirtualFree (bt->mem, 0, MEM_RELEASE);
FlushFileBuffers(bt->idx);
CloseHandle(bt->idx);
else if( bits < BT_minbits )
bits = BT_minbits;
- if ( bt_lockpage(bt, ALLOC_page, lockmode) )
+ if( bt_lockpage(bt, ALLOC_page, lockmode) )
return bt_close (bt), NULL;
#ifdef unix
bt->zero = (BtPage)(bt->mem + 5 * bt->page_size);
if( size || *amt ) {
- if ( bt_unlockpage(bt, ALLOC_page, lockmode) )
+ if( bt_unlockpage(bt, ALLOC_page, lockmode) )
return bt_close (bt), NULL;
return bt;
off64_t off = page_no << bt->page_bits;
#ifdef unix
- if ( !bt->mapped_io )
- if ( pwrite(bt->idx, page, bt->page_size, off) != bt->page_size )
+ if( !bt->mapped_io )
+ if( pwrite(bt->idx, page, bt->page_size, off) != bt->page_size )
return bt->err = BTERR_wrt;
#else
uint amt[1];
- if ( !bt->mapped_io )
+ if( !bt->mapped_io )
{
SetFilePointer (bt->idx, (long)off, (long*)(&off)+1, FILE_BEGIN);
if( !WriteFile (bt->idx, (char *)page, bt->page_size, amt, NULL) )
if( *amt < bt->page_size )
return GetLastError(), bt->err = BTERR_wrt;
}
- else if ( bt->mode == BT_fl ) {
+ else if( bt->mode == BT_fl ) {
FlushViewOfFile(page, bt->page_size);
FlushFileBuffers(bt->idx);
}
return bt->err;
}
#ifdef unix
- if ( pread(bt->idx, *page, bt->page_size, off) < bt->page_size )
+ if( pread(bt->idx, *page, bt->page_size, off) < bt->page_size )
return bt->err = BTERR_map;
#else
SetFilePointer (bt->idx, (long)off, (long*)(&off)+1, FILE_BEGIN);
// lock allocation page
- if ( bt_lockpage(bt, ALLOC_page, BtLockWrite) )
+ if( bt_lockpage(bt, ALLOC_page, BtLockWrite) )
return bt->err;
if( bt_mappage (bt, &bt->alloc, ALLOC_page) )
// lock page zero
- if ( bt_lockpage(bt, ALLOC_page, BtLockWrite) )
+ if( bt_lockpage(bt, ALLOC_page, BtLockWrite) )
return 0;
if( bt_mappage (bt, &bt->alloc, ALLOC_page) )
// unlock page zero
- if ( bt_unlockpage(bt, ALLOC_page, BtLockWrite) )
+ if( bt_unlockpage(bt, ALLOC_page, BtLockWrite) )
return 0;
return new_page;
}
#ifdef unix
- if ( pwrite(bt->idx, page, bt->page_size, new_page << bt->page_bits) < bt->page_size )
+ if( pwrite(bt->idx, page, bt->page_size, new_page << bt->page_bits) < bt->page_size )
return bt->err = BTERR_wrt, 0;
// if writing first page of hash block, zero last page in the block
- if ( !reuse && bt->hashmask > 0 && (new_page & bt->hashmask) == 0 )
+ if( !reuse && bt->hashmask > 0 && (new_page & bt->hashmask) == 0 )
{
// use temp buffer to write zeros
memset(bt->zero, 0, bt->page_size);
- if ( pwrite(bt->idx,bt->zero, bt->page_size, (new_page | bt->hashmask) << bt->page_bits) < bt->page_size )
+ if( pwrite(bt->idx,bt->zero, bt->page_size, (new_page | bt->hashmask) << bt->page_bits) < bt->page_size )
return bt->err = BTERR_wrt, 0;
}
#else
// unlock page zero
- if ( bt_unlockpage(bt, ALLOC_page, BtLockWrite) )
+ if( bt_unlockpage(bt, ALLOC_page, BtLockWrite) )
return 0;
return new_page;
// re-read and re-lock root after determining actual level of root
if( bt->page->lvl != drill) {
- if ( bt->page_no != ROOT_page )
+ if( bt->page_no != ROOT_page )
return bt->err = BTERR_struct, 0;
drill = bt->page->lvl;
// obtain lock on right page
- if ( bt_lockpage(bt, right, BtLockWrite) )
+ if( bt_lockpage(bt, right, BtLockWrite) )
return bt->err;
if( bt_mappage (bt, &bt->temp, right) )
else
id = 0;
- if ( bt_unlockpage(bt, bt->page_no, BtLockRead) )
+ if( bt_unlockpage(bt, bt->page_no, BtLockRead) )
return 0;
return id;
ptr = keyptr(bt->page, slot);
else
{
- if ( !bt->err )
+ if( !bt->err )
bt->err = BTERR_ovflw;
return bt->err;
}
slotptr(page, slot)->dead = 0;
slotptr(page, slot)->tod = tod;
bt_putid(slotptr(page,slot)->id, id);
- if ( bt_update(bt, bt->page, bt->page_no) )
+ if( bt_update(bt, bt->page, bt->page_no) )
return bt->err;
return bt_unlockpage(bt, bt->page_no, BtLockWrite);
}
bt->cursor_page = bt->page_no;
- if ( bt_unlockpage(bt, bt->page_no, BtLockRead) )
+ if( bt_unlockpage(bt, bt->page_no, BtLockRead) )
return 0;
return slot;
memcpy (bt->cursor, bt->page, bt->page_size);
- if ( bt_unlockpage(bt, right, BtLockRead) )
+ if( bt_unlockpage(bt, right, BtLockRead) )
return 0;
slot = 0;
#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
+
// standalone program to index file of keys
// then list them onto std-out
unsigned char key[256];
clock_t done, start;
uint pgblk = 0;
+float elapsed;
time_t tod[1];
uint scan = 0;
uint len = 0;
}
done = clock();
- fprintf(stderr, " Time to complete: %.2f seconds\n", (float)(done - start) / CLOCKS_PER_SEC);
+ elapsed = (float)(done - start)/CLOCKS_PER_SEC;
+ 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);
dead = cnt = 0;
len = key[0] = 0;
CloseHandle(mgr->idx);
GlobalFree (mgr->pool);
GlobalFree (mgr->hash);
- GlobalFree (mgr->latch);
+ GlobalFree ((void *)mgr->latch);
GlobalFree (mgr);
#endif
}
#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;
double real_time;
ThreadArg *args;
uint poolsize = 0;
+float elapsed;
int num = 0;
char key[1];
BtMgr *mgr;
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);
}
CloseHandle(mgr->idx);
GlobalFree (mgr->pool);
GlobalFree (mgr->hash);
- GlobalFree (mgr->latch);
+ GlobalFree ((void *)mgr->latch);
GlobalFree (mgr);
#endif
}
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;
double real_time;
ThreadArg *args;
uint poolsize = 0;
+float elapsed;
int num = 0;
char key[1];
BtMgr *mgr;
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);
}
close (mgr->idx);
free (mgr->pool);
free (mgr->hash);
- free (mgr->latch);
+ free ((void *)mgr->latch);
free (mgr);
#else
FlushFileBuffers(mgr->idx);
CloseHandle(mgr->idx);
GlobalFree (mgr->pool);
GlobalFree (mgr->hash);
- GlobalFree (mgr->latch);
+ GlobalFree ((void *)mgr->latch);
GlobalFree (mgr);
#endif
}
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( *(uint *)latch->readwr ) {
- fprintf(stderr, "latchset %d r/w locked for page %.8x\n", idx, latch->page_no);
- *(uint *)latch->readwr = 0;
- }
- if( *(uint *)latch->access ) {
- fprintf(stderr, "latchset %d access locked for page %.8x\n", idx, latch->page_no);
- *(uint *)latch->access = 0;
- }
- if( *(uint *)latch->parent ) {
- fprintf(stderr, "latchset %d parent locked for page %.8x\n", idx, latch->page_no);
- *(uint *)latch->parent = 0;
- }
- if( *(uint *)latch->busy ) {
- fprintf(stderr, "latchset %d busy locked for page %.8x\n", idx, latch->page_no);
- *(uint *)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;
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);
+ uid off = page_no << bt->mgr->page_bits;
+#ifdef unix
+ pread (bt->mgr->idx, bt->frame, bt->mgr->page_size, off);
+#else
+ DWORD amt[1];
+
+ SetFilePointer (bt->mgr->idx, (long)off, (long*)(&off)+1, FILE_BEGIN);
+
+ if( !ReadFile(bt->mgr->idx, bt->frame, bt->mgr->page_size, amt, NULL))
+ return bt->err = BTERR_map;
+
+ if( *amt < bt->mgr->page_size )
+ return bt->err = BTERR_map;
+#endif
if( !bt->frame->free && !bt->frame->lvl )
cnt += bt->frame->act;
if( page_no > LEAF_page )
double real_time;
ThreadArg *args;
uint poolsize = 0;
+float elapsed;
int num = 0;
char key[1];
BtMgr *mgr;
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);
}