Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1177104
  • 博文数量: 573
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 66
  • 用 户 组: 普通用户
  • 注册时间: 2016-06-28 16:21
文章分类

全部博文(573)

文章存档

2018年(3)

2016年(48)

2015年(522)

分类: LINUX

2015-12-02 15:56:58


点击(此处)折叠或打开

  1. #include <string.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <signal.h>
  5. #include <time.h>
  6. #include <sys/time.h>
  7. #include <sys/timeb.h>
  8. #include <stdarg.h>

  9. #define _X_ __LINE__,__FILE__,'1'

  10. char * StrTrim(char * pstr);
  11. int    GetDateTime(char * cDate, char * cTime);
  12. void SipWriteLog(const long _line_,const char *_file_,char flag,const char *strFmt, ...);

  13. char sDebugFile[128];

  14. int main(int argc, char ** argv)
  15. {
  16.     char sDate[9], sTime1[10], sTime2[10];
  17.     
  18.     memset(sDate,0,sizeof(sDate));
  19.     memset(sTime1,0,sizeof(sTime1));
  20.     
  21.     GetDateTime(sDate,sTime1);
  22.     StrTrim(sDate);
  23.     StrTrim(sTime1);

  24.     memset(sDebugFile, 0, sizeof(sDebugFile));
  25.     sprintf(sDebugFile, "Created_%s_%s.signal", sDate, sTime1);
  26.     
  27.     int i = -1;
  28.     int j = -1;
  29.     int m = -1;
  30.     SipWriteLog(_X_,"0****************************");
  31.     printf("0****************************\n");
  32.     sleep(2);
  33.     SipWriteLog(_X_,"1****************************");
  34.     printf("1****************************\n");
  35.     for(i=0; i<5000; i++)
  36.     {
  37.         for(j=0; j<1000; j++)
  38.         {
  39.             for(m=0; m<1000; m++)
  40.             {
  41.             }
  42.         }
  43.     }
  44.     /*计算时间间隔*/
  45.     memset(sDate,0,sizeof(sDate));
  46.     memset(sTime2,0,sizeof(sTime2));
  47.     GetDateTime(sDate,sTime2);
  48.     int time_internal=sTime2[4]*10*1000+sTime2[5]*1000+sTime2[6]*100+sTime2[7]*10+sTime2[8] - sTime1[4]*10*1000-sTime1[5]*1000-sTime1[6]*100-sTime1[7]*10-sTime1[8];
  49.     printf("sTime1 = [%s]\n", sTime1);
  50.     printf("sTime2 = [%s]\n", sTime2);
  51.     SipWriteLog(_X_,"sTime1 = [%s]", sTime1);
  52.     SipWriteLog(_X_,"sTime2 = [%s]", sTime2);
  53.     if (time_internal < 0)
  54.     time_internal = time_internal + 60*1000;
  55.     printf("三层for循环耗时 = [%d]毫秒\n", time_internal);
  56.     SipWriteLog(_X_,"三层for循环耗时 = [%d]毫秒", time_internal);
  57.     
  58.     /*sleep(10);*/
  59.     SipWriteLog(_X_,"2****************************");
  60.     printf("2****************************\n");
  61.     sleep(2);
  62.     SipWriteLog(_X_,"3****************************");
  63.     printf("3****************************\n");
  64.     sleep(2);
  65.     SipWriteLog(_X_,"4****************************");
  66.     printf("4****************************\n");
  67.     sleep(2);
  68.     SipWriteLog(_X_,"5****************************");
  69.     printf("5****************************\n");
  70.     sleep(2);
  71.     SipWriteLog(_X_,"6****************************");
  72.     printf("6****************************\n");
  73.     sleep(2);
  74.     SipWriteLog(_X_,"7****************************");
  75.     printf("7****************************\n");
  76.     sleep(2);
  77.     SipWriteLog(_X_,"8****************************");
  78.     printf("8****************************\n");
  79.     sleep(2);
  80.     SipWriteLog(_X_,"9****************************");
  81.     printf("9****************************\n");
  82.     sleep(5);
  83.     SipWriteLog(_X_,"10****************************");
  84.     printf("10****************************\n");
  85.     sleep(5);
  86.     SipWriteLog(_X_,"11****************************");
  87.     printf("11****************************\n");
  88.     sleep(1);
  89.     SipWriteLog(_X_,"12****************************");
  90.     printf("12****************************\n");
  91.     sleep(1);
  92.     SipWriteLog(_X_,"13****************************");
  93.     printf("13****************************\n");
  94.     sleep(1);
  95.     SipWriteLog(_X_,"14****************************");
  96.     printf("14****************************\n");
  97.     sleep(1);
  98.     SipWriteLog(_X_,"15****************************");
  99.     printf("15****************************\n");
  100.     
  101.     /*alarm(0);*/
  102.     return 0;
  103. }

  104. char * StrTrim(char * pstr)
  105. {
  106.     if(NULL == pstr)
  107.     {
  108.         return NULL;
  109.     }
  110.     char * phead = pstr;
  111.     char * ptail = pstr + strlen(pstr) - 1;
  112.     while((*phead == ' ')&&(phead < ptail)) phead++;
  113.     while((*ptail == ' ')&&(ptail > phead)) ptail--;
  114.     *(ptail + 1) = '\0';
  115.     memcpy(pstr, phead, sizeof(char)*(ptail - phead + 2));
  116.     return pstr;
  117. }

  118. /***********************************************************
  119. * 函 数 名:GetDateTime()
  120. * 功能描述: 分别获取系统日期时间
  121. * 输入参数:
  122. *            cDate-日期接收缓冲区;
  123. *            cTime-日期接收缓冲区;
  124. * 输出参数:cDate
  125. * 返 回:0 成功
  126. * 流程描述:
  127. * 说明: 返回日期格式:YYYYMMDD
  128. * 修改记录:
  129. * [修改人] [日期] - [描述]
  130. ***********************************************************/
  131. int    GetDateTime(char * cDate, char * cTime)
  132. {
  133.     struct tm *    cur;
  134.     time_t    timep;

  135.     struct timeb time_msec;
  136.     unsigned short msec;

  137.     time(&timep);
  138.     cur = localtime(&timep);

  139.     ftime(&time_msec);
  140.     msec=time_msec.millitm;

  141.     sprintf(cDate,"%04d%02d%02d",cur->tm_year+1900,cur->tm_mon+1,cur->tm_mday);
  142.     cDate[8]=0;
  143.     sprintf(cTime,"%02d%02d%02d%03d",cur->tm_hour,cur->tm_min,cur->tm_sec,msec);
  144.     cTime[9]=0;

  145.     return 0;
  146. }


  147. void SipWriteLog(const long _line_,const char *_file_,char flag,const char *strFmt, ...)
  148. {
  149.     char sdate[25];
  150.     va_list ap;
  151.     FILE *fp;
  152.     int filelen;
  153.     
  154.      fp=fopen(sDebugFile,"a");
  155.      if(fp==NULL) return;
  156.     memset(sdate,0,sizeof(sdate));
  157.     GetDateTime(sdate,sdate+9);
  158.     sdate[8]=' ';

  159.     fprintf(fp, "[%s] [%s][%d] >> ",sdate,_file_,_line_);
  160.     va_start(ap,strFmt);
  161.     vfprintf(fp, strFmt, ap);
  162.     va_end(ap);
  163.     fprintf(fp,"\n");
  164.     fflush(NULL);
  165.     fclose(fp);
  166.     return ;
  167. }

阅读(856) | 评论(0) | 转发(0) |
0

上一篇:sigsetjmp函数

下一篇:pause函数

给主人留下些什么吧!~~