added man pages for utils.

lots of gmdb2 work.
added statistics collection.
This commit is contained in:
brianb
2003-01-05 14:57:50 +00:00
parent cc362c42e9
commit 320f03c401
23 changed files with 1239 additions and 123 deletions

View File

@@ -1,4 +1,4 @@
lib_LTLIBRARIES = libmdb.la
libmdb_la_SOURCES= catalog.c mem.c file.c kkd.c table.c data.c dump.c backend.c money.c sargs.c index.c like.c write.c
libmdb_la_SOURCES= catalog.c mem.c file.c kkd.c table.c data.c dump.c backend.c money.c sargs.c index.c like.c write.c stats.c
INCLUDES = -I$(top_srcdir)/include $(GLIB_CFLAGS)
LIBS = $(GLIB_LIBS)

View File

@@ -21,6 +21,8 @@
#include "time.h"
#include "math.h"
#define MDB_DEBUG_OLE 1
char *mdb_money_to_string(MdbHandle *mdb, int start, char *s);
static int _mdb_attempt_bind(MdbHandle *mdb,
MdbColumn *col, unsigned char isnull, int offset, int len);
@@ -561,7 +563,7 @@ guint16 len, cur;
ole_row = mdb->pg_buf[start+4];
lval_pg = mdb_get_int24(mdb, start+5);
#if MDB_DEBUG
#if MDB_DEBUG_OLE
printf("Reading LVAL page %06x\n", lval_pg);
#endif
if(mdb_read_alt_pg(mdb, lval_pg) != mdb->fmt->pg_size) {
@@ -576,7 +578,7 @@ guint16 len, cur;
row_stop = mdb->fmt->pg_size - 1;
}
row_start = mdb_get_int16(mdb, 10 + ole_row * 2);
#if MDB_DEBUG
#if MDB_DEBUG_OLE
printf("row num %d row start %d row stop %d\n", ole_row, row_start, row_stop);
#endif
len = row_stop - row_start;
@@ -587,7 +589,7 @@ guint16 len, cur;
} else if (ole_flags == 0x0000) {
ole_row = mdb->pg_buf[start+4];
lval_pg = mdb_get_int24(mdb, start+5);
#if MDB_DEBUG
#if MDB_DEBUG_OLE
printf("Reading LVAL page %06x\n", lval_pg);
#endif
/* swap the alt and regular page buffers, so we can call get_int16 */
@@ -604,7 +606,7 @@ guint16 len, cur;
row_stop = mdb->fmt->pg_size - 1;
}
row_start = mdb_get_int16(mdb, 10 + ole_row * 2);
#if MDB_DEBUG
#if MDB_DEBUG_OLE
printf("row num %d row start %d row stop %d\n", ole_row, row_start, row_stop);
#endif
len = row_stop - row_start;

View File

@@ -51,6 +51,7 @@ int j,pos;
/* fprintf(stderr,"Couldn't open file %s\n",filename); */
return NULL;
}
mdb->f->refs++;
if (!mdb_read_pg(mdb, 0)) {
fprintf(stderr,"Couldn't read first page.\n");
return NULL;
@@ -87,9 +88,30 @@ MdbHandle *mdb_open(char *filename)
void mdb_close(MdbHandle *mdb)
{
if (mdb->f) {
mdb_free_file(mdb->f);
mdb->f->refs--;
if (mdb->f->refs<=0) mdb_free_file(mdb->f);
}
}
MdbHandle *mdb_clone_handle(MdbHandle *mdb)
{
MdbHandle *newmdb;
MdbCatalogEntry *entry;
int i;
newmdb = mdb_alloc_handle();
memcpy(newmdb, mdb, sizeof(MdbHandle));
newmdb->stats = NULL;
newmdb->catalog = g_array_new(FALSE,FALSE,sizeof(MdbCatalogEntry));
for (i=0;i<mdb->num_catalog;i++) {
entry = g_ptr_array_index(mdb->catalog,i);
newmdb->catalog = g_array_append_val(newmdb->catalog, entry);
}
mdb->backend_name = NULL;
if (mdb->f) {
mdb->f->refs++;
}
return newmdb;
}
/*
** mdb_read a wrapper for read that bails if anything is wrong
@@ -121,6 +143,9 @@ off_t offset = pg * mdb->fmt->pg_size;
fprintf(stderr,"offset %lu is beyond EOF\n",offset);
return 0;
}
if (mdb->stats && mdb->stats->collect)
mdb->stats->pg_reads++;
lseek(mdb->f->fd, offset, SEEK_SET);
len = read(mdb->f->fd,pg_buf,mdb->fmt->pg_size);
if (len==-1) {
@@ -166,6 +191,20 @@ int i;
return i;
}
gint32 mdb_get_int24_msb(MdbHandle *mdb, int offset)
{
gint32 l;
unsigned char *c;
if (offset <0 || offset+3 > mdb->fmt->pg_size) return -1;
c = &mdb->pg_buf[offset];
l =c[0]; l<<=8;
l+=c[1]; l<<=8;
l+=c[2];
mdb->cur_pos+=3;
return l;
}
gint32 mdb_get_int24(MdbHandle *mdb, int offset)
{
gint32 l;

View File

@@ -126,7 +126,7 @@ int i;
for (i=0;i<idx->num_keys;i++) {
marker = mdb->pg_buf[cur_pos++];
col=g_ptr_array_index(table->columns,idx->key_col_num[i]-1);
printf("column %d coltype %d col_size %d\n",i,col->col_type, mdb_col_fixed_size(col));
printf("column %d coltype %d col_size %d (%d)\n",i,col->col_type, mdb_col_fixed_size(col), col->col_size);
}
}
void mdb_index_dump(MdbTableDef *table, MdbIndex *idx)

View File

@@ -30,6 +30,16 @@ void mdb_exit()
g_hash_table_destroy(mdb_backends);
}
MdbStatistics *mdb_alloc_stats(MdbHandle *mdb)
{
mdb->stats = g_malloc0(sizeof(MdbStatistics));
return mdb->stats;
}
void mdb_free_stats(MdbHandle *mdb)
{
g_free(mdb->stats);
mdb->stats = NULL;
}
MdbFile *mdb_alloc_file()
{
MdbHandle *f;
@@ -60,8 +70,9 @@ void mdb_free_handle(MdbHandle *mdb)
{
if (!mdb) return;
if (mdb->stats) mdb_free_stats(mdb);
if (mdb->catalog) mdb_free_catalog(mdb);
if (mdb->f) mdb_free_file(mdb->f);
if (mdb->f && mdb->f->refs<=0) mdb_free_file(mdb->f);
if (mdb->backend_name) free(mdb->backend_name);
free(mdb);
}

43
src/libmdb/stats.c Normal file
View File

@@ -0,0 +1,43 @@
/* MDB Tools - A library for reading MS Access database files
* Copyright (C) 2000 Brian Bruns
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "mdbtools.h"
void
mdb_stats_on(MdbHandle *mdb)
{
if (!mdb->stats)
mdb_alloc_stats(mdb);
mdb->stats->collect = TRUE;
}
void
mdb_stats_off(MdbHandle *mdb)
{
if (!mdb->stats) return;
mdb->stats->collect = FALSE;
}
void
mdb_dump_stats(MdbHandle *mdb)
{
if (!mdb->stats) return;
fprintf(stdout, "Physical Page Reads: %lu\n", mdb->stats->pg_reads);
}