归档 2010年12月12日

最后更新于 .

最近有很多时间相关的一些技术积累,主要分为三块,

  • 1.gettimeofday时间差不准的bug
  • 2.时间的字符串形式和时间戳形式的转化(C语言)
  • 3.提供时间日期选择的控件

一.gettimeofday时间不准的bug 先从第一个说起吧,前几天在fuload项目通过如下代码统计调用消耗的时间:

struct timeval stBegin;
struct timeval stEnd;
gettimeofday(&stBegin, NULL);
ret = process(swi);
gettimeofday(&stEnd, NULL);
time_ms = ((stEnd.tv_sec-stBegin.tv_sec)*1000000+(stEnd.tv_usec-stBegin.tv_usec))/1000;

按理说是很平常的写法,但是在实际的曲线图中,却发现每隔20分钟就会出现一个很大的波动,在网上苦询答案未果,最后突然想起来,既然是规律性的出现问题,是不是crontab中有每隔20分钟的调用导致的问题呢?最终在crontab中发现了这个:

*/20 * * * * /usr/sbin/ntpdate 172.23.32.142 ...

昨天

2010年12月8日

明天

2010年12月14日

归档