From 52793262e14131ff979d2dc24cad27ae6c84fce6 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Tue, 20 Mar 2007 23:12:22 +0000 Subject: [PATCH] *** empty log message *** svn path=/trunk/boinc/; revision=12257 --- api/boinc_api.C | 4 +- checkin_notes | 12 ++++++ lib/procinfo_unix.C | 99 +++++++++++++++++++++++---------------------- lib/util.C | 19 +++++++++ lib/util.h | 1 + 5 files changed, 85 insertions(+), 50 deletions(-) diff --git a/api/boinc_api.C b/api/boinc_api.C index 76d24a4a98..68db055e7f 100644 --- a/api/boinc_api.C +++ b/api/boinc_api.C @@ -925,7 +925,9 @@ int boinc_checkpoint_completed() { boinc_worker_thread_cpu_time(cur_cpu); last_wu_cpu_time = cur_cpu + aid.wu_cpu_time; last_checkpoint_cpu_time = last_wu_cpu_time; - update_app_progress(last_checkpoint_cpu_time, last_checkpoint_cpu_time); + if (options.send_status_msgs) { + update_app_progress(last_checkpoint_cpu_time, last_checkpoint_cpu_time); + } time_until_checkpoint = (int)aid.checkpoint_period; in_critical_section = false; ready_to_checkpoint = false; diff --git a/checkin_notes b/checkin_notes index c142a3540c..c7a2b7f36e 100755 --- a/checkin_notes +++ b/checkin_notes @@ -2722,3 +2722,15 @@ David 20 Mar 2007 cs_benchmark.C lib/ util.C,h + +David 20 Mar 2007 + - API: boinc_checkpoint_completed(): don't call update_app_progress() + unless options.send_status_msgs is set + (fixes bug in wrappers that call this) + - lib: add linux_cpu_time() function (get CPU time of another process) + + api/ + boinc_api.C + lib/ + procinfo_unix.C + util.C,h diff --git a/lib/procinfo_unix.C b/lib/procinfo_unix.C index 2ae0bc7290..38b37dfcec 100644 --- a/lib/procinfo_unix.C +++ b/lib/procinfo_unix.C @@ -96,53 +96,54 @@ struct PROC_STAT { }; int PROC_STAT::parse(char* buf) { - int n = sscanf(buf, "%d %s %c %d %d %d %d %d " - "%lu %lu %lu %lu %lu %lu %lu " - "%d %d %d %d %d %d " - "%lu %lu " - "%d " - "%lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu " - "%d %d", - &pid, - comm, - &state, - &ppid, - &pgrp, - &session, - &tty_nr, - &tpgid, - &flags, - &minflt, - &cminflt, - &majflt, - &cmajflt, - &utime, - &stime, - &cutime, - &cstime, - &priority, - &nice, - &zero, - &itrealvalue, - &starttime, - &vsize, - &rss, - &rlim, - &startcode, - &endcode, - &startstack, - &kstkesp, - &kstkeip, - &signal, - &blocked, - &sigignore, - &sigcatch, - &wchan, - &nswap, - &cnswap, - &exit_signal, - &processor - ); + int n = sscanf(buf, + "%d %s %c %d %d %d %d %d " + "%lu %lu %lu %lu %lu %lu %lu " + "%d %d %d %d %d %d " + "%lu %lu " + "%d " + "%lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu " + "%d %d", + &pid, + comm, + &state, + &ppid, + &pgrp, + &session, + &tty_nr, + &tpgid, + &flags, + &minflt, + &cminflt, + &majflt, + &cmajflt, + &utime, + &stime, + &cutime, + &cstime, + &priority, + &nice, + &zero, + &itrealvalue, + &starttime, + &vsize, + &rss, + &rlim, + &startcode, + &endcode, + &startstack, + &kstkesp, + &kstkeip, + &signal, + &blocked, + &sigignore, + &sigcatch, + &wchan, + &nswap, + &cnswap, + &exit_signal, + &processor + ); if (n == 39) return 0; // I don't see a good choice of ERR_ for this... @@ -189,9 +190,9 @@ int procinfo_setup(vector& pi) { if (fd) { if (fread(&prusage, sizeof(prusage_t), 1, fd) == 1) { p.user_time = (float)prusage.pr_utime.tv_sec + - ((float)prusage.pr_utime.tv_nsec)/1e+9; + ((float)prusage.pr_utime.tv_nsec)/1e+9; p.kernel_time = (float)prusage.pr_stime.tv_sec + - ((float)prusage.pr_utime.tv_nsec)/1e+9; + ((float)prusage.pr_utime.tv_nsec)/1e+9; // page faults: I/O + non I/O p.page_fault_count = prusage.pr_majf + prusage.pr_minf; } diff --git a/lib/util.C b/lib/util.C index 6a57fca5aa..a3dfc5f425 100755 --- a/lib/util.C +++ b/lib/util.C @@ -489,4 +489,23 @@ int wait_client_mutex(const char* dir, double timeout) { return ERR_ALREADY_RUNNING; } +#ifndef _WIN32 +// (linux) return current CPU time of the given process +// +double linux_cpu_time(int pid) { + FILE *file; + char file_name[24]; + unsigned long utime = 0, stime = 0; + int n; + + sprintf(file_name,"/proc/%d/stat",pid); + if ((file = fopen(file_name,"r")) != NULL) { + n = fscanf(file,"%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%lu%lu",&utime,&stime); + fclose(file); + if (n != 2) return 0; + } + return (double)(utime + stime)/100; +} +#endif + const char *BOINC_RCSID_ab65c90e1e = "$Id$"; diff --git a/lib/util.h b/lib/util.h index f4c78f468a..d5fee53e1c 100755 --- a/lib/util.h +++ b/lib/util.h @@ -71,6 +71,7 @@ extern int check_security(int use_sandbox, int isManager); // setpriority(2) arg to run in background // (don't use 20 because static const int PROCESS_IDLE_PRIORITY = 19; +extern double linux_cpu_time(int pid); #endif extern void update_average(double, double, double, double&, double&);