40 lines · 682 B · C
RawDownload
/*	debug.h - helpful debug routines 	Copyright (C) 2010, IBM Corporation,  		Eric Van Hensbergen (bergevan@us.ibm.com) */ static int vflag = 0;static int debugfd = 2; static void_dprint(ulong dlevel, char *fmt, ...){	va_list args;	char *p;	int len;	char s[255];	char *newfmt; 	if(vflag<dlevel)		return; 	p = strchr(fmt, '\n'); 	newfmt = smprint("\t[%8.8llud][%8.8d]\t %s\n", nsec()>>16, getpid(), fmt);	if(p != nil){		p = strchr(newfmt, '\n');		*p = ' ';	}	va_start(args, fmt);	len = vsnprint(s, sizeof s - 1, newfmt, args);	va_end(args);	if (newfmt != nil) free(newfmt);	s[len]=0;	 	fprint(debugfd, "%s", s);} #define DPRINT if(!vflag){} else _dprint