Skip to content

Commit 63f3acc

Browse files
author
Charlie Fenton
committed
If new total_cpu_time() method has error, revert to the old method
1 parent 7b49e10 commit 63f3acc

File tree

1 file changed

+45
-41
lines changed

1 file changed

+45
-41
lines changed

client/app.cpp

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -488,49 +488,53 @@ void ACTIVE_TASK_SET::get_memory_usage() {
488488

489489
#if defined(__linux__) || defined(_WIN32) || defined(__APPLE__)
490490
// compute non_boinc_cpu_usage
491-
// Improved version for systems where we can get total CPU (Win, Linux)
491+
// Improved version for systems where we can get total CPU (Win, Linux, Mac)
492492
//
493493
static double last_nbrc=0;
494-
double nbrc = total_cpu_time() - boinc_related_cpu_time(pm, using_vbox);
495-
double delta_nbrc = nbrc - last_nbrc;
496-
if (delta_nbrc < 0) delta_nbrc = 0;
497-
last_nbrc = nbrc;
498-
if (!first) {
499-
non_boinc_cpu_usage = delta_nbrc/(diff*gstate.host_info.p_ncpus);
500-
//printf("non_boinc_cpu_usage %f\n", non_boinc_cpu_usage);
501-
}
502-
#else
503-
// compute non_boinc_cpu_usage
504-
//
505-
// NOTE: this is flawed because it doesn't count short-lived processes
506-
// correctly. Linux and Win use a better approach (see above).
507-
//
508-
// mem usage info is not useful because most OSs don't
509-
// move idle processes out of RAM, so physical memory is always full.
510-
// Also (at least on Win) page faults are used for various things,
511-
// not all of them generate disk I/O,
512-
// so they're not useful for detecting paging/thrashing.
513-
//
514-
static double last_cpu_time;
515-
PROCINFO pi;
516-
procinfo_non_boinc(pi, pm);
517-
if (log_flags.mem_usage_debug) {
518-
//procinfo_show(pm);
519-
msg_printf(NULL, MSG_INFO,
520-
"[mem_usage] All others: WS %.2fMB, swap %.2fMB, user %.3fs, kernel %.3fs",
521-
pi.working_set_size/MEGA, pi.swap_size/MEGA,
522-
pi.user_time, pi.kernel_time
523-
);
524-
}
525-
double new_cpu_time = pi.user_time + pi.kernel_time;
526-
if (!first) {
527-
non_boinc_cpu_usage = (new_cpu_time - last_cpu_time)/(diff*gstate.host_info.p_ncpus);
528-
// processes might have exited in the last 10 sec,
529-
// causing this to be negative.
530-
if (non_boinc_cpu_usage < 0) non_boinc_cpu_usage = 0;
531-
}
532-
last_cpu_time = new_cpu_time;
494+
double total_cpu_time_now = total_cpu_time();
495+
if (total_cpu_time_now != 0.0) { // total_cpu_time() returns 0.0 on error
496+
double nbrc = total_cpu_time_now - boinc_related_cpu_time(pm, using_vbox);
497+
double delta_nbrc = nbrc - last_nbrc;
498+
if (delta_nbrc < 0) delta_nbrc = 0;
499+
last_nbrc = nbrc;
500+
if (!first) {
501+
non_boinc_cpu_usage = delta_nbrc/(diff*gstate.host_info.p_ncpus);
502+
//printf("non_boinc_cpu_usage %f\n", non_boinc_cpu_usage);
503+
}
504+
} else
533505
#endif
506+
{
507+
// compute non_boinc_cpu_usage the old way
508+
//
509+
// NOTE: this is flawed because it doesn't count short-lived processes
510+
// correctly. Linux and Win use a better approach (see above).
511+
//
512+
// mem usage info is not useful because most OSs don't
513+
// move idle processes out of RAM, so physical memory is always full.
514+
// Also (at least on Win) page faults are used for various things,
515+
// not all of them generate disk I/O,
516+
// so they're not useful for detecting paging/thrashing.
517+
//
518+
static double last_cpu_time;
519+
PROCINFO pi;
520+
procinfo_non_boinc(pi, pm);
521+
if (log_flags.mem_usage_debug) {
522+
//procinfo_show(pm);
523+
msg_printf(NULL, MSG_INFO,
524+
"[mem_usage] All others: WS %.2fMB, swap %.2fMB, user %.3fs, kernel %.3fs",
525+
pi.working_set_size/MEGA, pi.swap_size/MEGA,
526+
pi.user_time, pi.kernel_time
527+
);
528+
}
529+
double new_cpu_time = pi.user_time + pi.kernel_time;
530+
if (!first) {
531+
non_boinc_cpu_usage = (new_cpu_time - last_cpu_time)/(diff*gstate.host_info.p_ncpus);
532+
// processes might have exited in the last 10 sec,
533+
// causing this to be negative.
534+
if (non_boinc_cpu_usage < 0) non_boinc_cpu_usage = 0;
535+
}
536+
last_cpu_time = new_cpu_time;
537+
}
534538

535539
if (!first) {
536540
if (log_flags.mem_usage_debug) {
@@ -542,7 +546,7 @@ void ACTIVE_TASK_SET::get_memory_usage() {
542546
first = false;
543547
}
544548

545-
#endif
549+
#endif // ! defined (SIM)
546550

547551
// There's a new trickle file.
548552
// Move it from slot dir to project dir

0 commit comments

Comments
 (0)