首页 > 代码库 > glog工具函数

glog工具函数

1.时间处理函数

int64_t CycleClock_Now() {    struct timeval tv;    gettimeofday(&tv, NULL);    return static_cast<int64>(tv.tv_sec) * 1000000 + tv.tv_usec;}double WallTime_Now() {    //return microseconds since the epoch(纪元)    return CycleClock_Now() * 0.000001;}

//将当前时间换算成
//tm_sec
//tm_min
//tm_mday
//tm_mon
//tm_year
//tm_wday
//tm_yday
//tm_isdst
//tm_gmtoff
//tm_zone
localtime_r(&data_->timestamp_, &data_->tm_time_);

//获取微秒数
int usecs = static_case<int>((now-data_->timestamp_)*1000000);

2. backtrace函数调用信息

int GetStackTrace(void** result, int max_depth, int skip_count) {static const int kStackLength = 64;void * stack[kStackLength];int size;size = backtrace(stack, kStackLength);skip_count++;  // we want to skip the current frame as wellint result_count = size - skip_count;if (result_count < 0)    result_count = 0;    if (result_count > max_depth)    result_count = max_depth;    for (int i = 0; i < result_count; i++)     result[i] = stack[i + skip_count];   return result_count;}

 

  

glog工具函数