10 #include <sys/times.h>
29 ProgressLog(
long NIn,
int maxsec = 1200) : secstep(maxsec) {
35 void operator()(
int cnt) {
47 void tick(
long i,
long n) {
48 if ( !statusTime(i, n) )
return;
50 double fcpui = fclock();
51 time_t timei = time(0);
52 double ftime0 = time0;
53 double ftime1 = time1;
54 double ftimei = timei;
56 if ( ftimei > ftime1 && fcpui > fcpu1 )
57 eff = (fcpui-fcpu1)/(ftimei-ftime1);
58 if ( eff >= 1.0 ) eff = 0.999999;
61 if ( ftimei > ftime0 && fcpui > fcpu0 )
62 eff0 = (fcpui-fcpu0)/(ftimei-ftime0);
63 if ( eff0 >= 1.0 ) eff0 = 0.999999;
65 double fcpun = fcpu0 + (n*(fcpui-fcpu0))/i;
66 time_t timen = (time_t)(ftimei + (fcpun-fcpui)/eff + 30.0);
67 time_t timen0 = (time_t)(ftimei + (fcpun-fcpui)/eff0 + 30.0);
71 strftime(date,1024,
"%y.%m.%d %H:%M",localtime(&timei));
72 strftime(daten,1024,
"%H:%M",localtime(&timen));
73 strftime(daten0,1024,
"%H:%M",localtime(&timen0));
75 if ( n - i < n/10 ) ii = i - n;
76 time_t dayn = (timen - timei)/86400;
77 time_t dayn0 = (timen0 - timei)/86400;
81 if ( dayn <= 0 && dayn0 <= 0 ) {
82 os << date <<
" " << setw(8) << ii <<
"/" << setw(9);
83 os.setf(ios::left, ios::adjustfield);
84 os << n <<
" etc: " << daten <<
"[";
85 os.setf(ios::right, ios::adjustfield);
86 os << setw(2) << ieff <<
"%] " << daten0 <<
"[" << ieff0 <<
"%] "
87 << host <<
":" << pid << endl << flush;
89 os << date <<
" " << setw(8) << ii <<
"/" << setw(9);
90 os.setf(ios::left, ios::adjustfield);
91 os << n <<
" etc: " << dayn <<
"+" << daten <<
"[";
92 os.setf(ios::right, ios::adjustfield);
93 os << setw(2) << ieff <<
"%] "
94 << dayn0 <<
"+" << daten0 <<
"[" << ieff0 <<
"%] "
95 << host <<
":" << pid << endl << flush;
108 tmsbuf.tms_utime+tmsbuf.tms_stime+tmsbuf.tms_cutime+tmsbuf.tms_cstime;
109 d /= sysconf(_SC_CLK_TCK);
114 bool statusTime(
long i,
long n)
const {
115 if ( i <= 0 )
return false;
116 if ( i == n )
return true;
117 if ( i > n/2 ) i = n-i;
118 while ( i >= 10 && !(i%10) ) i /= 10;
119 if ( i == 1 || i == 2 || i == 5 )
return true;
120 if ( secstep > 0 && time(0) > time1 + secstep )
return true;
128 fcpu0 = fcpu1 = fclock();
129 time0 = time1 = time(0);
131 gethostname(name,1024);
133 if ( host.find(
".") != string::npos )
134 host = host.substr(0, host.find(
"."));
137 strftime(date,1024,
"%y.%m.%d %H:%M",localtime(&time0));
139 os << date <<
" 0/" << setw(9);
140 os.setf(ios::left, ios::adjustfield);
142 os.setf(ios::right, ios::adjustfield);
143 os <<
" Initializing... "
144 << host <<
":" << pid << endl << flush;