Chinaunix首页 | 论坛 | 博客

分类: LINUX

2011-10-04 22:58:05

进入main.c
初始化这次按照code中本来的调用。
首先调用
int main( int argc, char **argv)
{
. . . . . .
program_name = argv[0] ; /*这就是wget*/
struct ptimer* timer = ptimer_new(); +++++++++------>/src/ptimer// /*1、_________-------->
double start_time = ptimer_measure(timer );/*8、___----->src/primer.c*/
i18n_initialize();/*3__---->
. . . . .
}
  1. struct ptimer{

  2. ptimer_system_time start; /*起始时间:typedef struct timespec ptimer_system_time; typedef struct timeval ptimer_system_time timespec和timeval是POSIX的精度秒以下的时间类型,前者精确到纳秒,后者精确到微秒。定义如下:
  3. struct timespec {
  4. __kernel_time_t tv_sec;                 /* seconds */
  5. long            tv_nsec;                /* nanoseconds */
  6. };
  7. struct timeval {
  8. __kernel_time_t         tv_sec;         /* seconds */
  9. __kernel_suseconds_t    tv_usec;        /* microseconds */
  10. };  定时*/

  11. double elapsed_last;  /*逝去时间,由ptimer_measure()计算*/
  12. double elapsed_pre_start; /*时间矫正,在measure调用和运行之间的误差*/
  13. }
  14. 1、____________------------>
  15. [code]
  16. 315 struct ptimer *
  17. 316 ptimer_new (void)
  18. 317 {  
  19. 318   struct ptimer *pt = xnew0 (struct ptimer); /*2_____________---------->src/utils.h*/
  20. 319 #ifdef IMPL_init
  21. 320   static bool init_done;
  22. 321   if (!init_done)
  23. 322     {
  24. 323       init_done = true;
  25. 324       IMPL_init ();  /*6、_____------------>/src/primer.c*/
  26. 325     }
  27. 326 #endif
  28. 327   ptimer_reset (pt);
  29. 328   return pt;
  30. 329 }  
复制代码
2、__________--------------->
#define xnew0(type) (xcalloc (1, sizeof (type)))/*____------>3、______----->/xmalloc.c*/
3、________------>
/*检测成功,分配空间并返回此地址*/
95 xcalloc (size_t n, size_t s)
96 {
97   void *p;
98   /* Test for overflow, since some calloc implementations don't have
99      proper overflow checks.  But omit overflow and size-zero tests if
100      HAVE_GNU_CALLOC, since GNU calloc catches overflow and never
101      returns NULL if successful.  因为calloc不进行溢出检测。但是如果定义了GUN calloc 可以捕捉到溢出。*/
102   if ((! HAVE_GNU_CALLOC && xalloc_oversized (n, s)) /*4________---------->*/
103       || (! (p = calloc (n, s)) && (HAVE_GNU_CALLOC || n != 0)))5、______------->/C 函数库中完成的*/
104     xalloc_die ();
105   return p;
106 }
4、___________------------->
35 # define xalloc_oversized(n, s) \
36     ((size_t) (sizeof (ptrdiff_t) <= sizeof (size_t) ? -1 : -2) / (s) < (n)) /*ptrdiff_t和size_t代表看我的博客里面有解释,如果没有定义就进行检测如果整个地址空间分配的数目小于n那么就会出现错误。*/
5、________-------->
calloc 和malloc的区别在于第一个对分配空间进行初始化0,第二个不初始化*/
6、____--------->
#define IMPL_init posix_init /*7、__--->src/primer.c*/
7、__________---------->
在此函数中会遇到几个clock.
/*
CLOCK_REALTIME
System-wide realtime clock. Setting this clock requires appro-
priate privileges. 如果权限很高可以设定;

CLOCK_MONOTONIC
Clock that cannot be set and represents monotonic time since
some unspecified starting point. 不可以设定,这是对时钟中断进行的计数*/
函数调用sysconf是返回系统中的某些常数值。
clock_getres()是获得clock的精确值,并将clock.id对应的clock值赋值给&r
8、______________________________________--------------------------->
double ptimer_measure(struct ptimer *pt)
{
. . . . . .
IMPL_measure(&now); /*9_________---------->src/ptimer.c*/
elapsed = pt->elapsed_pre_start + IMPL_diff (&now, &pt->start); /*11、______------->src/ptimer.c*/


9、_______________----------->
#define IMPL_measure posix_measuer /*10、______________-------->src/ptimer.c*/
10、_____________------------------->
static inline void posix_measuer(ptimer_system_time *pst)
{
clock_gettime(posix_clock_id, pst); /*11、__________-----------> clock_gettime returns the current timespec value of tp for the specific  clock */
}

11、__________------>
#define IMPL_diff posix_diff /*ptimer.c 12、____________--------->*/
12、__________________----------------------------->
175 posix_diff (ptimer_system_time *pst1, ptimer_system_time *pst2)
176 {
177   return ((pst1->tv_sec - pst2->tv_sec)
178           + (pst1->tv_nsec - pst2->tv_nsec) / 1e9);
179 }
阅读(757) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~