Improve: getPublicIP may fail and block mater program
This commit is contained in:
@@ -89,7 +89,9 @@ public:
|
||||
// 智能计时器,计算函数的耗时
|
||||
class auto_tick {
|
||||
private:
|
||||
const char* file;
|
||||
const char* func;
|
||||
int line;
|
||||
int span;
|
||||
clock_t tick;
|
||||
__inline clock_t now() const {
|
||||
@@ -100,7 +102,8 @@ private:
|
||||
}
|
||||
|
||||
public:
|
||||
auto_tick(const char* func_name, int th = 5) : func(func_name), span(th), tick(now()) { }
|
||||
auto_tick(const char* file_name, const char* func_name, int line_no, int th = 5) :
|
||||
file(file_name), func(func_name), line(line_no), span(th), tick(now()) { }
|
||||
~auto_tick() {
|
||||
stop();
|
||||
}
|
||||
@@ -108,7 +111,11 @@ public:
|
||||
__inline void stop() {
|
||||
if (span != 0) {
|
||||
int s(this->time());
|
||||
if (s > span)Mprintf("[%s] cost: [%d]ms.\n", func, s);
|
||||
if (s > span) {
|
||||
char buf[1024];
|
||||
sprintf_s(buf, "%s(%d) : [%s] cost [%d]ms.\n", file, line, func, s);
|
||||
OutputDebugStringA(buf);
|
||||
}
|
||||
span = 0;
|
||||
}
|
||||
}
|
||||
@@ -116,7 +123,7 @@ public:
|
||||
|
||||
#ifdef _DEBUG
|
||||
// 智能计算当前函数的耗时,超时会打印
|
||||
#define AUTO_TICK(thresh) auto_tick TICK(__FUNCTION__, thresh)
|
||||
#define AUTO_TICK(thresh) auto_tick TICK(__FILE__, __FUNCTION__, __LINE__, thresh)
|
||||
#define STOP_TICK TICK.stop()
|
||||
#else
|
||||
#define AUTO_TICK(thresh)
|
||||
|
||||
Reference in New Issue
Block a user