From 9cf10b400a39113c4f0e8c8bf6100b108fabfe1f Mon Sep 17 00:00:00 2001 From: David Anderson Date: Mon, 29 Oct 2012 15:44:51 -0700 Subject: [PATCH] - GUI RPC: expose TIME_STATS info (e.g. on_frac) in the binding of the get_state() RPC - client: move client_start_time and previous_uptime from CLIENT_STATE to TIME_STATS, so that these are also visible in GUI RPC - scheduler RPC: move uptime and previous_uptime into - client: condition an RR simulation message on - boinccmd: show TIME_STATS info in --get_state --- checkin_notes | 24 +++++++++++++++++++++++ client/client_state.cpp | 2 -- client/client_state.h | 5 +---- client/cs_prefs.cpp | 2 +- client/cs_scheduler.cpp | 8 ++------ client/cs_statefile.cpp | 19 +++++++++--------- client/rr_sim.cpp | 10 ++++++---- client/time_stats.cpp | 38 +++++++++++++++++++++++------------- client/time_stats.h | 26 +++++------------------- lib/common_defs.h | 31 +++++++++++++++++++++++++++++ lib/gui_rpc_client.h | 10 +++++++--- lib/gui_rpc_client_ops.cpp | 20 +++++++++++++++++++ lib/gui_rpc_client_print.cpp | 13 ++++++++++++ 13 files changed, 144 insertions(+), 64 deletions(-) diff --git a/checkin_notes b/checkin_notes index bd784aae1a..21ed5f5ea7 100644 --- a/checkin_notes +++ b/checkin_notes @@ -6444,3 +6444,27 @@ David 28 Oct 2012 tools/ update_versions + +David 29 Oct 2012 + - GUI RPC: expose TIME_STATS info (e.g. on_frac) in + the binding of the get_state() RPC + - client: move client_start_time and previous_uptime + from CLIENT_STATE to TIME_STATS, + so that these are also visible in GUI RPC + - scheduler RPC: move uptime and previous_uptime + into + - client: condition an RR simulation message on + - boinccmd: show TIME_STATS info in --get_state + + client/ + client_state.cpp,h + cs_prefs.cpp + cs_scheduler.cpp + cs_statefile.cpp + rr_sim.cpp + time_stats.cpp,h + lib/ + common_defs.h + gui_rpc_client.h + gui_rpc_client_ops.cpp + gui_rpc_client_print.cpp diff --git a/client/client_state.cpp b/client/client_state.cpp index c19046558a..49701f0af7 100644 --- a/client/client_state.cpp +++ b/client/client_state.cpp @@ -143,7 +143,6 @@ CLIENT_STATE::CLIENT_STATE() launched_by_manager = false; initialized = false; last_wakeup_time = dtime(); - previous_uptime = 0; } void CLIENT_STATE::show_host_info() { @@ -301,7 +300,6 @@ int CLIENT_STATE::init() { srand((unsigned int)time(0)); now = dtime(); - client_start_time = now; scheduler_op->url_random = drand(); notices.init(); diff --git a/client/client_state.h b/client/client_state.h index e9d68acae4..42eba833a9 100644 --- a/client/client_state.h +++ b/client/client_state.h @@ -92,7 +92,7 @@ struct CLIENT_STATE { GET_PROJECT_LIST_OP get_project_list_op; ACCT_MGR_OP acct_mgr_op; - TIME_STATS time_stats; + CLIENT_TIME_STATS time_stats; GLOBAL_PREFS global_prefs; NET_STATS net_stats; ACTIVE_TASK_SET active_tasks; @@ -185,9 +185,6 @@ struct CLIENT_STATE { // this affects auto-update bool run_by_updater; double now; - double client_start_time; - double previous_uptime; - // duration of previous client session double last_wakeup_time; bool initialized; bool cant_write_state_file; diff --git a/client/cs_prefs.cpp b/client/cs_prefs.cpp index 697f3f6759..748190c70c 100644 --- a/client/cs_prefs.cpp +++ b/client/cs_prefs.cpp @@ -206,7 +206,7 @@ int CLIENT_STATE::check_suspend_processing() { return SUSPEND_REASON_BENCHMARKS; } - if (config.start_delay && now < client_start_time + config.start_delay) { + if (config.start_delay && now < time_stats.client_start_time + config.start_delay) { return SUSPEND_REASON_INITIAL_DELAY; } diff --git a/client/cs_scheduler.cpp b/client/cs_scheduler.cpp index 35fdc7f589..c59683624c 100644 --- a/client/cs_scheduler.cpp +++ b/client/cs_scheduler.cpp @@ -121,9 +121,7 @@ int CLIENT_STATE::make_scheduler_request(PROJECT* p) { " %f\n" " %f\n" " %d\n" - " %d\n" - " %f\n" - " %f\n", + " %d\n", p->authenticator, p->hostid, p->rpc_seqno, @@ -135,9 +133,7 @@ int CLIENT_STATE::make_scheduler_request(PROJECT* p) { prrs_fraction, p->duration_correction_factor, config.allow_multiple_clients?1:0, - g_use_sandbox?1:0, - now - client_start_time, - previous_uptime + g_use_sandbox?1:0 ); work_fetch.write_request(f, p); diff --git a/client/cs_statefile.cpp b/client/cs_statefile.cpp index 52c18bf4e9..5e26cf853a 100644 --- a/client/cs_statefile.cpp +++ b/client/cs_statefile.cpp @@ -500,7 +500,7 @@ int CLIENT_STATE::parse_state_file_aux(const char* fname) { if (xp.parse_string("newer_version", newer_version)) { continue; } - if (xp.parse_double("previous_uptime", previous_uptime)) { + if (xp.parse_double("previous_uptime", time_stats.previous_uptime)) { continue; } #ifdef ENABLE_AUTO_UPDATE @@ -771,7 +771,7 @@ int CLIENT_STATE::write_state(MIOFILE& f) { cpu_benchmarks_pending?"\n":"", new_version_check_time, all_projects_list_check_time, - now - client_start_time + now - time_stats.client_start_time ); if (newer_version.size()) { f.printf("%s\n", newer_version.c_str()); @@ -931,11 +931,6 @@ int CLIENT_STATE::write_state_gui(MIOFILE& f) { f.printf("\n"); -#if 1 - // NOTE: the following stuff is not in CC_STATE. - // However, BoincView (which does its own parsing) expects it - // to be in the get_state() reply, so leave it in for now - // retval = host_info.write(f, true, false); if (retval) return retval; @@ -948,12 +943,18 @@ int CLIENT_STATE::write_state_gui(MIOFILE& f) { f.printf("\n"); } - retval = time_stats.write(f, false); - if (retval) return retval; +#if 1 + // NOTE: the following is not in CC_STATE. + // However, BoincView (which does its own parsing) expects it + // to be in the get_state() reply, so leave it in for now + // retval = net_stats.write(f); if (retval) return retval; #endif + retval = time_stats.write(f, true); + if (retval) return retval; + for (j=0; jwrite_state(f, true); diff --git a/client/rr_sim.cpp b/client/rr_sim.cpp index 4f0bf3adf3..f087596b31 100644 --- a/client/rr_sim.cpp +++ b/client/rr_sim.cpp @@ -489,10 +489,12 @@ void RR_SIM::simulate() { COPROC& cp = coprocs.coprocs[i]; int mask = (1<\n" " %f\n" " %f\n" " %f\n" " %f\n" - " %f\n", + " %f\n" + " %f\n" + " %f\n", on_frac, connected_frac, cpu_and_network_available_frac, active_frac, - gpu_active_frac + gpu_active_frac, + client_start_time, + previous_uptime ); - if (!to_server) { + if (to_remote) { + out.printf( + " %f\n", gstate.now + ); + } else { out.printf( " %f\n", last_update @@ -302,7 +312,7 @@ int TIME_STATS::write(MIOFILE& out, bool to_server) { // Parse XML based time statistics, usually from client_state.xml // -int TIME_STATS::parse(XML_PARSER& xp) { +int CLIENT_TIME_STATS::parse(XML_PARSER& xp) { double x; #ifdef SIM double on_lambda = 3600, connected_lambda = 3600; @@ -392,27 +402,27 @@ int TIME_STATS::parse(XML_PARSER& xp) { return ERR_XML_PARSE; } -void TIME_STATS::start() { +void CLIENT_TIME_STATS::start() { time_stats_log = fopen(TIME_STATS_LOG, "a"); if (time_stats_log) { setbuf(time_stats_log, 0); } } -void TIME_STATS::quit() { +void CLIENT_TIME_STATS::quit() { log_append("power_off", gstate.now); } #ifdef SIM -void TIME_STATS::log_append(const char* , double ) {} +void CLIENT_TIME_STATS::log_append(const char* , double ) {} #else -void TIME_STATS::log_append(const char* msg, double t) { +void CLIENT_TIME_STATS::log_append(const char* msg, double t) { if (!time_stats_log) return; fprintf(time_stats_log, "%f %s\n", t, msg); } #endif -void TIME_STATS::log_append_net(int new_state) { +void CLIENT_TIME_STATS::log_append_net(int new_state) { switch(new_state) { case CONNECTED_STATE_NOT_CONNECTED: log_append("net_not_connected", gstate.now); diff --git a/client/time_stats.h b/client/time_stats.h index 9abc4d3bbe..dfc3fbafb7 100644 --- a/client/time_stats.h +++ b/client/time_stats.h @@ -18,32 +18,16 @@ #ifndef _TIME_STATS_ #define _TIME_STATS_ -#include "miofile.h" #include -struct TIME_STATS { +#include "miofile.h" +#include "common_defs.h" + +struct CLIENT_TIME_STATS : TIME_STATS { bool first; int previous_connected_state; double last_update; -// we maintain an exponentially weighted average of these quantities: - double on_frac; - // the fraction of total time this host runs the client - double connected_frac; - // of the time this host runs the client, - // the fraction it is connected to the Internet, - // or -1 if not known - double cpu_and_network_available_frac; - // of the time this host runs the client, - // the fraction it is connected to the Internet - // AND network usage is allowed (by prefs and user toggle) - // AND CPU usage is allowed - double active_frac; - // of the time this host runs the client, - // the fraction it is enabled to use CPU - // (as determined by preferences, manual suspend/resume, etc.) - double gpu_active_frac; - // same, GPU FILE* time_stats_log; double inactive_start; @@ -51,7 +35,7 @@ struct TIME_STATS { void update(int suspend_reason, int gpu_suspend_reason); void init(); - int write(MIOFILE&, bool to_server); + int write(MIOFILE&, bool to_remote); int parse(XML_PARSER&); double availability_frac(int rsc_type) { diff --git a/lib/common_defs.h b/lib/common_defs.h index 9eb1f2825f..74e85c91ac 100644 --- a/lib/common_defs.h +++ b/lib/common_defs.h @@ -19,6 +19,7 @@ #define _COMMON_DEFS_ #include "miofile.h" +#include "parse.h" // #defines or enums that are shared by more than one BOINC component // (e.g. client, server, Manager, etc.) @@ -179,6 +180,36 @@ enum SUSPEND_REASON { #define RPC_REASON_INIT 6 #define RPC_REASON_PROJECT_REQ 7 +struct TIME_STATS { +// we maintain an exponentially weighted average of these quantities: + double now; + // the client's time of day + double on_frac; + // the fraction of total time this host runs the client + double connected_frac; + // of the time this host runs the client, + // the fraction it is connected to the Internet, + // or -1 if not known + double cpu_and_network_available_frac; + // of the time this host runs the client, + // the fraction it is connected to the Internet + // AND network usage is allowed (by prefs and user toggle) + // AND CPU usage is allowed + double active_frac; + // of the time this host runs the client, + // the fraction it is enabled to use CPU + // (as determined by preferences, manual suspend/resume, etc.) + double gpu_active_frac; + // same, GPU + double client_start_time; + double previous_uptime; + // duration of previous session + + void write(MIOFILE&); + int parse(XML_PARSER&); + void print(); +}; + struct VERSION_INFO { int major; int minor; diff --git a/lib/gui_rpc_client.h b/lib/gui_rpc_client.h index 22298255cb..153fa2ad7a 100644 --- a/lib/gui_rpc_client.h +++ b/lib/gui_rpc_client.h @@ -369,6 +369,9 @@ struct GR_PROXY_INFO { void clear(); }; +// Represents the entire client state. +// Call get_state() infrequently. +// struct CC_STATE { std::vector projects; std::vector apps; @@ -378,11 +381,12 @@ struct CC_STATE { std::vector platforms; // platforms supported by client GLOBAL_PREFS global_prefs; // working prefs, i.e. network + override - VERSION_INFO version_info; // populated only if talking to pre-5.6 CC + VERSION_INFO version_info; // populated only if talking to pre-5.6 client bool executing_as_daemon; // true if client is running as a service / daemon HOST_INFO host_info; - bool have_nvidia; // redundant; include for compat (set by ) - bool have_ati; // redundant; include for compat + TIME_STATS time_stats; + bool have_nvidia; // deprecated; include for compat (set by ) + bool have_ati; // deprecated; include for compat CC_STATE(); ~CC_STATE(); diff --git a/lib/gui_rpc_client_ops.cpp b/lib/gui_rpc_client_ops.cpp index 133e05de36..2d9e486985 100644 --- a/lib/gui_rpc_client_ops.cpp +++ b/lib/gui_rpc_client_ops.cpp @@ -77,6 +77,22 @@ using std::string; using std::vector; using std::sort; +int TIME_STATS::parse(XML_PARSER& xp) { + memset(this, 0, sizeof(TIME_STATS)); + while (!xp.get_tag()) { + if (xp.match_tag("/time_stats")) return 0; + if (xp.parse_double("now", now)) continue; + if (xp.parse_double("on_frac", on_frac)) continue; + if (xp.parse_double("connected_frac", connected_frac)) continue; + if (xp.parse_double("cpu_and_network_available_frac", cpu_and_network_available_frac)) continue; + if (xp.parse_double("active_frac", active_frac)) continue; + if (xp.parse_double("gpu_active_frac", gpu_active_frac)) continue; + if (xp.parse_double("client_start_time", client_start_time)) continue; + if (xp.parse_double("previous_uptime", previous_uptime)) continue; + } + return ERR_XML_PARSE; +} + int DAILY_XFER::parse(XML_PARSER& xp) { while (!xp.get_tag()) { if (xp.match_tag("/dx")) return 0; @@ -942,6 +958,10 @@ int CC_STATE::parse(XML_PARSER& xp) { host_info.parse(xp); continue; } + if (xp.match_tag("time_stats")) { + time_stats.parse(xp); + continue; + } if (xp.parse_bool("have_cuda", have_nvidia)) continue; if (xp.parse_bool("have_ati", have_ati)) continue; } diff --git a/lib/gui_rpc_client_print.cpp b/lib/gui_rpc_client_print.cpp index 0a0b28be4a..e96c3c7b5f 100644 --- a/lib/gui_rpc_client_print.cpp +++ b/lib/gui_rpc_client_print.cpp @@ -211,6 +211,17 @@ void SIMPLE_GUI_INFO::print() { } } +void TIME_STATS::print() { + printf(" now: %f\n", now); + printf(" on_frac: %f\n", on_frac); + printf(" connected_frac: %f\n", connected_frac); + printf(" cpu_and_network_available_frac: %f\n", cpu_and_network_available_frac); + printf(" active_frac: %f\n", active_frac); + printf(" gpu_active_frac: %f\n", gpu_active_frac); + printf(" client_start_time: %f\n", client_start_time); + printf(" previous_uptime: %f\n", previous_uptime); +} + void CC_STATE::print() { unsigned int i; printf("======== Projects ========\n"); @@ -238,6 +249,8 @@ void CC_STATE::print() { printf("%d) -----------\n", i+1); results[i]->print(); } + printf("\n======== Time stats ========\n"); + time_stats.print(); } void print_status(