Wrapped debug printfs in bdberl_drv.c with a macro

so that they can easily be removed with a recompile.
This commit is contained in:
Phillip Toland 2008-12-15 15:05:41 -06:00
parent 4494e9736d
commit 28be3ac80a
2 changed files with 20 additions and 12 deletions

View file

@ -22,7 +22,11 @@ end
rule ".o" => ["%X.c", "%X.h"] do |t|
puts "compiling #{t.source}..."
sh "gcc -g -c -Wall -Werror -fPIC -Ic_src/system/include -I#{erts_dir()}/include #{t.source} -o #{t.name}", :verbose => false
sh "gcc -g -c -Wall -Werror -fPIC #{dflag} -Ic_src/system/include -I#{erts_dir()}/include #{t.source} -o #{t.name}", :verbose => false
end
def dflag()
ENV["release"] ? "" : "-DDEBUG"
end
task :compile_c => ['c_src'] + C_OBJS

View file

@ -134,12 +134,16 @@ static TPool* G_TPOOL_TXNS;
erl_drv_mutex_unlock(d->port_lock); \
}}
#ifdef DEBUG
# define DBG printf
#else
# define DBG(arg1,...)
#endif
DRIVER_INIT(bdberl_drv)
{
printf("DRIVER INIT\n");
DBG("DRIVER INIT\n");
// Setup flags we'll use to init the environment
int flags =
DB_INIT_LOCK | /* Enable support for locking */
@ -253,9 +257,9 @@ static void bdberl_drv_stop(ErlDrvData handle)
// Drop the lock prior to starting the wait for the async process
erl_drv_mutex_unlock(d->port_lock);
printf("Cancelling async job for port: %p\n", d->port);
DBG("Cancelling async job for port: %p\n", d->port);
bdberl_tpool_cancel(d->async_pool, d->async_job);
printf("Canceled async job for port: %p\n", d->port);
DBG("Canceled async job for port: %p\n", d->port);
}
else
{
@ -284,7 +288,7 @@ static void bdberl_drv_stop(ErlDrvData handle)
close_database(d->dbrefs->dbref, 0, d);
}
printf("Stopped port: %p\n", d->port);
DBG("Stopped port: %p\n", d->port);
// Release the port instance data
driver_free(d->work_buffer);
@ -312,7 +316,7 @@ static void bdberl_drv_finish()
erl_drv_rwlock_destroy(G_DATABASES_RWLOCK);
hive_hash_destroy(G_DATABASES_NAMES);
printf("DRIVER_FINISH\n");
DBG("DRIVER_FINISH\n");
}
static int bdberl_drv_control(ErlDrvData handle, unsigned int cmd,
@ -696,7 +700,7 @@ static int close_database(int dbref, unsigned flags, PortData* data)
Database* database = &G_DATABASES[dbref];
if (database->ports == 0)
{
printf("Closing actual database for dbref %d\n", dbref);
DBG("Closing actual database for dbref %d\n", dbref);
// Close out the BDB handle
database->db->close(database->db, flags);
@ -1228,14 +1232,14 @@ static void* deadlock_check(void* arg)
G_DB_ENV->lock_detect(G_DB_ENV, 0, DB_LOCK_DEFAULT, &count);
if (count > 0)
{
printf("Rejected deadlocks: %d\n", count);
DBG("Rejected deadlocks: %d\n", count);
}
// TODO: Use nanosleep
usleep(G_DEADLOCK_CHECK_INTERVAL * 1000);
}
printf("Deadlock checker exiting.\n");
DBG("Deadlock checker exiting.\n");
return 0;
}
@ -1252,7 +1256,7 @@ static void* trickle_write(void* arg)
// Enough time has passed -- time to run the trickle operation again
int pages_wrote = 0;
G_DB_ENV->memp_trickle(G_DB_ENV, G_TRICKLE_PERCENTAGE, &pages_wrote);
printf("Wrote %d pages to achieve %d trickle\n", pages_wrote, G_TRICKLE_PERCENTAGE);
DBG("Wrote %d pages to achieve %d trickle\n", pages_wrote, G_TRICKLE_PERCENTAGE);
// Reset the counter
elapsed_secs = 0;
@ -1265,7 +1269,7 @@ static void* trickle_write(void* arg)
}
}
printf("Trickle writer exiting.\n");
DBG("Trickle writer exiting.\n");
return 0;
}