1
1
// This file is part of BOINC.
2
2
// http://boinc.berkeley.edu
3
- // Copyright (C) 2008 University of California
3
+ // Copyright (C) 2022 University of California
4
4
//
5
5
// BOINC is free software; you can redistribute it and/or modify it
6
6
// under the terms of the GNU Lesser General Public License
@@ -486,51 +486,55 @@ void ACTIVE_TASK_SET::get_memory_usage() {
486
486
}
487
487
}
488
488
489
- #if defined(__linux__) || defined(_WIN32)
489
+ #if defined(__linux__) || defined(_WIN32) || defined(__APPLE__)
490
490
// 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 )
492
492
//
493
493
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
533
505
#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
+ }
534
538
535
539
if (!first) {
536
540
if (log_flags.mem_usage_debug ) {
@@ -542,7 +546,7 @@ void ACTIVE_TASK_SET::get_memory_usage() {
542
546
first = false ;
543
547
}
544
548
545
- #endif
549
+ #endif // ! defined (SIM)
546
550
547
551
// There's a new trickle file.
548
552
// Move it from slot dir to project dir
0 commit comments