版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zhangpengzp/article/details/87719980
Log 打印
log的定义,需要打印log时候#define __DEBUG__ANDROID__ON ,关闭时候#define __DEBUG__ANDROID__OFF,下面的时间打印同理。
#define __DEBUG__ANDROID__ON
//write debug images
#ifdef __DEBUG__ANDROID__ON
#include <android/log.h>
// Define the LOGI and others for print debug infomation like the log.i in java
#define LOG_TAG "lammy -- JNILOG"
//#undef LOG
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG, __VA_ARGS__)
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG, __VA_ARGS__)
#define LOGW(...) __android_log_print(ANDROID_LOG_WARN,LOG_TAG, __VA_ARGS__)
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG, __VA_ARGS__)
#define LOGF(...) __android_log_print(ANDROID_LOG_FATAL,LOG_TAG, __VA_ARGS__)
#else
#ifdef __DEBUG__WIN__ON
#define LOGI(...) printf( __VA_ARGS__); printf("\n")
#define LOGD(...) printf( __VA_ARGS__); printf("\n")
#define LOGW(...) printf( __VA_ARGS__); printf("\n")
#define LOGE(...) printf( __VA_ARGS__); printf("\n")
#define LOGF(...) printf( __VA_ARGS__); printf("\n")
#else
#define LOGI(...)
#define LOGD(...)
#define LOGW(...)
#define LOGE(...)
#define LOGF(...)
#endif
#endif
调用方式:
LOGE("array.length = %d",env->GetArrayLength(array));
时间打印
#define __DEBUG__TIME__ON
#define millisecond 1000000
//run times test...
#ifdef __DEBUG__TIME__ON
#define LOG_TIME LOGE
#define RUN_TIME(time) (double)(time).count()/millisecond
//#define RUN_TIME(...) getTime_MS( __VA_ARGS__)
#define DEBUG__TIME0 auto TIME0= std::chrono::high_resolution_clock::now()
#define DEBUG__TIME1 auto TIME1= std::chrono::high_resolution_clock::now()
#define DEBUG__TIME2 auto TIME2= std::chrono::high_resolution_clock::now()
#define DEBUG__TIME3 auto TIME3= std::chrono::high_resolution_clock::now()
#define DEBUG__TIME4 auto TIME4= std::chrono::high_resolution_clock::now()
#define DEBUG__TIME5 auto TIME5= std::chrono::high_resolution_clock::now()
#define DEBUG__TIME6 auto TIME6= std::chrono::high_resolution_clock::now()
#define DEBUG__TIME7 auto TIME7= std::chrono::high_resolution_clock::now()
#define DEBUG__TIME8 auto TIME8= std::chrono::high_resolution_clock::now()
#define DEBUG__TIME9 auto TIME9= std::chrono::high_resolution_clock::now()
#else
#define DEBUG__TIME0
#define DEBUG__TIME1
#define DEBUG__TIME2
#define DEBUG__TIME3
#define DEBUG__TIME4
#define DEBUG__TIME5
#define DEBUG__TIME6
#define DEBUG__TIME7
#define DEBUG__TIME8
#define DEBUG__TIME9
#define LOG_TIME(...)
#endif
调用方法:
DEBUG__TIME0;
testMethod();
DEBUG__TIME1;
//%4.4f 前面4表示总数字位为4,不满4则右对齐,后面的4表示小数点后保留4位有效数字
LOG_TIME("Running times:detect facedetect %4.4fms" , RUN_TIME(TIME1 - TIME0));