Develop and Download Open Source Software

Browse Subversion Repository

Diff of /branches/mty-makai/mty.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 116 by notanpe, Tue Apr 10 13:52:39 2007 UTC revision 119 by notanpe, Fri Apr 13 03:09:02 2007 UTC
# Line 693  set_salt(signed char *code, Line 693  set_salt(signed char *code,
693  }  }
694    
695  static  static
696    unsigned long
697    usec()
698    {
699    #if !defined(WIN32)
700      struct timeval tv;
701      gettimeofday(&tv, NULL);
702      return 100UL * tv.tv_sec + (tv.tv_usec / 10000);
703    #else
704      struct timeb tm;
705      ftime(&tm);
706      return 100UL * tm.time + tm.millitm / 10;
707    #endif
708    }
709    
710    static
711  int  int
712  log_printf(FILE *ofp, char const *fmt, ...)  log_printf(FILE *ofp, char const *fmt, ...)
713  {  {
# Line 756  main(int argc, char *argv[]) Line 771  main(int argc, char *argv[])
771    
772    int xhash_loaded;    int xhash_loaded;
773    
774  #define   LOOP_FACTOR  1000000UL  #define LOOP_FACTOR 100000UL    /* こんなもんでいいか */
775  #define   UPDATE_INTERVAL   5   /* ステータス表示の最低間隔 */  #define UPDATE_INTERVAL 8       /* 速度表示の間隔 秒 */
776    #define AVG_SPD 500000UL        /* 平均速度の初期値 trips/s */
777    struct status {    struct status {
778      time_t      startTime;      /* 開始時刻 */      unsigned long startTime;    /* 開始時刻 ミリ秒 */
779      time_t      lastTime;       /* 最後に表示した時刻 */      unsigned long lastTime;     /* 最後に表示した時刻 ミリ秒 */
780      unsigned long       lastLoopCnt;    /* 最後に表示した時の検索数 */      double        lastLoopCnt;  /* 最後に表示した時のループ回数 */
781      unsigned long       loop;           /* ループ回数 % LOOP_FACTOR */      unsigned long loop;         /* ループ回数 % LOOP_FACTOR */
782      unsigned long       mloop;          /* ループ回数 / LOOP_FACTOR */      unsigned long mloop;        /* ループ回数 / LOOP_FACTOR */
783    } status;    } status;
784      unsigned long upd_int = AVG_SPD * UPDATE_INTERVAL;
785    /*
786     平均速度 (trips/s) * UPDATE_INTERVAL が ULONG_MAX を超えると発狂する。
787     ULONG_MAX = 4294967295, 平均速度 = 100Mtrips/s なら、
788     4294967295 / (100 * 1000 * 1000) = 42.949 秒までにすること。
789     LOOP_FACTOR が平均速度より十分小さければ、ほぼ指定間隔になる。
790     */
791    
792  #if 0  #if 0
793    if (argc < 2)    if (argc < 2)
# Line 837  main(int argc, char *argv[]) Line 860  main(int argc, char *argv[])
860    nblk_hit = nblk_total = 0;    nblk_hit = nblk_total = 0;
861    nap_hit = nap_total = 0;    nap_hit = nap_total = 0;
862    cr = 0;    cr = 0;
863    status.startTime = status.lastTime = time( NULL );    status.startTime = status.lastTime = usec();
864    status.lastLoopCnt = 0;    status.lastLoopCnt = 0;
865    status.loop = 0;    status.loop = 0;
866    status.mloop = 0;    status.mloop = 0;
# Line 952  main(int argc, char *argv[]) Line 975  main(int argc, char *argv[])
975                  }                  }
976    
977            status.loop += N_ALU * ALU_BITS;            status.loop += N_ALU * ALU_BITS;
978            if ( status.loop >= LOOP_FACTOR )            if ( status.loop >= upd_int )
979                  {                  {
980    /*
981     ここで更新間隔のチェックをすれば、高速マシンでヘンな速度表示が最初だけ出る
982     のを防げる。
983     だがそれをすると普通のマシンでムダな usec() 呼び出しをすることになる。
984     だからやらない。決して手抜きではない。
985     */
986                    time_t curTime;                    time_t curTime;
987                      int a, b;
988                      double loopCnt, zoneCnt;
989    
990                    status.mloop += ( status.loop / LOOP_FACTOR );                    status.mloop += ( status.loop / LOOP_FACTOR );
991                    status.loop %= LOOP_FACTOR;                    status.loop %= LOOP_FACTOR;
992                    curTime = time( NULL );                    curTime = usec();
993                    if ( curTime >= (status.lastTime + (time_t)UPDATE_INTERVAL) )                    loopCnt = (double)status.mloop * LOOP_FACTOR + status.loop;
994                          {                    zoneCnt = loopCnt - status.lastLoopCnt;
995                            int a, b;                    a = loopCnt * 100 / (curTime - status.startTime);
996                            unsigned long loopCnt, zoneCnt;                    b = zoneCnt * 100 / (curTime - status.lastTime);
997                            loopCnt = status.mloop * LOOP_FACTOR + status.loop;                    upd_int = b * UPDATE_INTERVAL;
                           zoneCnt = loopCnt - status.lastLoopCnt;  
                           a = loopCnt / (curTime - status.startTime);  
                           b = zoneCnt / (curTime - status.lastTime);  
998  #if DEBUG>=1  #if DEBUG>=1
999                            fprintf(stderr,                    fprintf(stderr,
1000                                            "%5d/%5d(%3d%%)",                            "%5d/%5d(%3d%%)",
1001                                            nblk_hit, nblk_total, 100 * nblk_hit / nblk_total);                            nblk_hit, nblk_total, 100 * nblk_hit / nblk_total);
1002                            nblk_hit = nblk_total = 0;                    nblk_hit = nblk_total = 0;
1003                            if (nap_total)                    if (nap_total)
1004                                  fprintf(stderr,                          fprintf(stderr,
1005                                                  "  %5d/%5d(%3d%%)",                                  "  %5d/%5d(%3d%%)",
1006                                                  nap_hit, nap_total, 100 * nap_hit / nap_total);                                  nap_hit, nap_total, 100 * nap_hit / nap_total);
1007                            else                    else
1008                                  fprintf(stderr,                          fprintf(stderr,
1009                                                  "  -----/-----(---%%)");                                          "  -----/-----(---%%)");
1010                            nap_hit = nap_total = 0;                    nap_hit = nap_total = 0;
1011  #endif  #endif
1012                            fprintf( stderr,                    fprintf( stderr,
1013                                  "%8d.%03dktrips/s [%8d.%03dktrips/s]\r",                          "%6d.%03dktrips/s [%6d.%03dktrips/s]\r",
1014                                  a / 1000, a % 1000,                          a / 1000, a % 1000,
1015                                  b / 1000, b % 1000 );                          b / 1000, b % 1000 );
1016                            status.lastTime = curTime;                    status.lastTime = curTime;
1017                            status.lastLoopCnt = loopCnt;                    status.lastLoopCnt = loopCnt;
1018                            cr++;                    cr++;
                         }  
1019                  }                  }
1020  #if 1  #if 1
1021            if (!key_inc(3))            if (!key_inc(3))

Legend:
Removed from v.116  
changed lines
  Added in v.119

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26