bsl_debug.h 1.7 KB
Newer Older
W
wangguibao 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
/***************************************************************************
 * 
 * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved
 * $Id: bsl_debug.h,v 1.1 2008/09/03 06:47:49 xiaowei Exp $ 
 * 
 **************************************************************************/
 
 
 
/**
 * @file bsl_debug.h
 * @author xiaowei(com@baidu.com)
 * @date 2008/07/25 20:49:30
 * @version $Revision: 1.1 $ 
 * @brief 
 *  
 **/


#ifndef  __BSL_DEBUG_H_
#define  __BSL_DEBUG_H_

#include <stdio.h>
#include <assert.h>
#include <sys/time.h>

namespace bsl
{

#ifdef BSL_DEBUG_MOD

#define __BSL_DEBUG(fmt, arg...) \
{ \
	fprintf(stdout, "[----------debug--------][%s:%d]" fmt "\n", __FILE__, __LINE__, ##arg); \
}
#define __BSL_ASSERT(flag, fmt, arg...) \
{\
	bool ___bsl_flag = flag; \
	if (!(___bsl_flag)) { \
		fprintf(stdout, "[error][%s:%d][%s]" fmt "\n", __FILE__, __LINE__, #flag, ##arg); \
	}\
	assert (___bsl_flag); \
}


class auto_xtimer            
{
	char buf[64];  
	timeval s, e;
	public:             
	auto_xtimer(const char *str = NULL) {                 
		buf[0] = 0;
		if (str) snprintf(buf, sizeof(buf), "%s", str);
		gettimeofday(&s, NULL);
	}
	~auto_xtimer() {
		gettimeofday(&e, NULL);                                           
		long t = (long)((e.tv_sec - s.tv_sec) * 1000000 + (e.tv_usec - s.tv_usec));
		__BSL_DEBUG("%s %ld", buf, t);                               
	}    
};

#define AUTO_TIMER(str) bsl::auto_xtimer t(str)
#else
#define __BSL_DEBUG(fmt, arg...) 
#define __BSL_ASSERT(...) 
#define AUTO_TIMER(str)
#endif

#define __BSL_ERROR(fmt, arg...) \
{ \
	fprintf(stdout, "[error][%s:%d]" fmt "\n", __FILE__, __LINE__, ##arg); \
}



};
















#endif  //__BSL_DEBUG_H_

/* vim: set ts=4 sw=4 sts=4 tw=100 */