调试宏
#include <stdio.h> #define GW_DEBUG 1 //打印开关 #define GW_DEBUG_LEVEL E_GW_INFO //打印级别 #if GW_DEBUG #define GW_LOG_FILE ("/var/tmp/log") enum E_GW_DEBUG_LEVEL { E_GW_FATAL, E_GW_ERR, E_GW_WARNING, E_GW_INFO, E_GW_NONE, E_GW_CNT }; enum E_GW_MODULE { E_GW_MOD_MAIN, E_GW_MOD_NETCLIENT, E_GW_MOD_MOTIONDETECT, E_GW_MOD_OSD, E_gW_MOD_POS, E_GW_MOD_SPIT, E_GW_MOD_TTF, E_GW_MOD_RECORD, E_GW_MOD_FACE, E_GW_MOD_DFT, E_GW_MOD,CNT, }; typedef struct _ST_GW_DEBUG_MOD { const char* pkMod; const bool bFlag; } ST_GW_DEBUG_MOD; static uint32_t gw_ms_rcd = 0; const char* const gw_debug_level_str[E_GW_CNT] = { "FATAL", "ERROR", "WARNING", "INFO", "NONE" }; const ST_GW_DEBUG_MOD gw_debug_ModSet[E_GW_MOD_CNT] = { {"MAIN", false}, {"NETCLIENT", false}, {"MOTIONDETECT", false}, {"OSD", false}, {"POS", false}, {"SPLIT", false}, {"TTF", false}, {"RECORD", false}, {"FACE", false}, {"DFT", false}, }; #define GW_PTF_START\ do{\ FILE* gw_log_fd = fopen(GW_LOG_FILENAME, "w+"); \ if(gw_log_fd)\ {\ fclose(gw_log_fd);\ }\ }while(0); #define GW_PTF(MODULE, LEVEL, FORMAT, args...)\ do{\ if(gw_debug_ModSet[MODULE].bFlag && (E_GW_DEBUG_LEVEL)LEVEL <= GW_DEBUG_LEVEL)\ {\ FILE* gw_log_fd = fopen(GW_LOG_FILENAME, "a+");\ if(NULL != gw_log_fd)\ {\ SYSTEM_TIME tm;\ char strTime[32] = {0,};\ SystemGetCurrentTime(&tm);\ snprintf(gw_log_fd, 32, "%02d:%02d:%02d", tm.hour, tm.minute, tm.second);\ fprintf(gw_log_fd, "[%s:%06u:%06u] [%s] [%s] [%s %s] [%d] >> ", strTime, \ SystemGetMSCount() - gw_ms_rcd, SystemGetMSCount(),\ gw_debug_ModSet[MODULE].pkMod,\ gw_debug_level_str[LEVEL], (NULL == STRRCHR(__FILE__, '/')) ?\ __FILE__ : strrchr(__FILE__, '/') + 1, __FUNCTION__, __LINE__);\ gw_ms_rcd = SystemGetMSCount();\ fprintf(gw_log_fd, FORMAT, ##args);\ fclose(gw_log_fd);\ }\ }\ }while(0); #define GW_PTF_BARE(MODULE, LEVEL, FORMAT, args...)\ do{\ if(gw_debug_ModSet[MODULE].bFlag && (E_GW_DEBUG_LEVEL)LEVEL <= GW_DEBUG_LEVEL)\ {\ FILE* gw_log_fd = fopen(GW_LOG_FILENAME, "a+");\ if(NULL != gw_log_fd)\ {\ fprintf(gw_log_fd, FORMAT, ##args);\ fclose(gw_log_fd);\ }\ }\ }while(0); //单线程时间调试 typedef std::map<const char*, uint> TM_GW_MAP; static TM_GW_MAP gw_map_ms; #define GW_TIME_START(MODE, LEVEL, NOTE) \ if(gw_map_ms.find(NOTE) == gw_map_ms.end())\ {\ gw_map_ms.insert(std::pair<const char*, uint>(NOTE, SystemGetUScount())); }\ else\ {\ gw_map_ms.find(NOTE)->second = SystemGetUSCount();\ }\ GW_PTF(MODE, LEVEL, "%s Start\n", NOTE ); #define GW_TIME_END(MODE, LEVEL, NOTE) \ GW_PTF(MODE, LEVEL, "%s End cost %u\n", NOTE, gw_map_ms.find(NOTE) == gw_map_ms.end() \ ? 0xFFFFFFFF : SystemGetUSCount() - gw_map_ms.find(NOTE)->second); #else #define GW_PTF_START #define GW_PTF(MODULE, LEVEL, FORMAT, args...) #define GW_PTF_BARE(MODULE, LEVEL, FORMAT, args...) #define GW_TIME_START(MODE, LEVEL, NOTE) #define GW_TIME_END(NODE, LEVEL, NOTE) #endif
Notepad++ Replace功能Ctrl+H,正则表达式替换
Find what: [)]$\r\n^[{] 、
==>[(]匹配 ),,$匹配行尾, \r\n匹配回车换行,^匹配行首,[{] 匹配 {
Replace with: \)\n{\n\tGW_PTF\(E_GW_MOD_RECORD, E_GW_INFO, "%s\\n", "test"\);
==>替换为 ) , 换行, {, 换行, Table , 桩字符串