2008-08-06 18:36:30 +00:00
|
|
|
// This file is part of BOINC.
|
2005-01-20 23:22:22 +00:00
|
|
|
// http://boinc.berkeley.edu
|
2008-08-06 18:36:30 +00:00
|
|
|
// Copyright (C) 2008 University of California
|
2003-08-20 18:56:52 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is free software; you can redistribute it and/or modify it
|
|
|
|
// under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation,
|
|
|
|
// either version 3 of the License, or (at your option) any later version.
|
2003-08-20 18:56:52 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
2005-01-20 23:22:22 +00:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
2002-04-30 22:22:54 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2010-05-11 19:10:29 +00:00
|
|
|
#include "cpp.h"
|
|
|
|
|
2004-03-04 11:41:43 +00:00
|
|
|
#ifdef _WIN32
|
2004-06-16 23:16:08 +00:00
|
|
|
#include "boinc_win.h"
|
2010-05-11 19:10:29 +00:00
|
|
|
#else
|
2005-11-21 18:34:44 +00:00
|
|
|
#include "config.h"
|
2004-07-13 13:54:09 +00:00
|
|
|
#include <cstdio>
|
|
|
|
#include <ctime>
|
|
|
|
#include <cmath>
|
2010-05-11 19:10:29 +00:00
|
|
|
#include <cstring>
|
2011-09-27 19:45:27 +00:00
|
|
|
#if HAVE_SYS_SOCKET_H
|
2005-05-06 02:09:35 +00:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#endif
|
2010-05-11 19:10:29 +00:00
|
|
|
#endif
|
2005-05-06 02:09:35 +00:00
|
|
|
|
2010-12-22 18:59:07 +00:00
|
|
|
#include "error_numbers.h"
|
|
|
|
#include "filesys.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
#include "parse.h"
|
2003-02-24 21:25:16 +00:00
|
|
|
#include "util.h"
|
2010-12-22 18:59:07 +00:00
|
|
|
|
2004-04-08 08:15:23 +00:00
|
|
|
#include "client_msgs.h"
|
2005-06-07 19:22:50 +00:00
|
|
|
#include "client_state.h"
|
2010-12-22 18:59:07 +00:00
|
|
|
#include "file_names.h"
|
2006-06-17 04:55:28 +00:00
|
|
|
#include "log_flags.h"
|
2010-12-22 18:59:07 +00:00
|
|
|
#include "network.h"
|
|
|
|
#ifdef SIM
|
|
|
|
#include "sim.h"
|
|
|
|
#endif
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
#include "time_stats.h"
|
|
|
|
|
2008-01-11 23:52:49 +00:00
|
|
|
#define CONNECTED_STATE_UNINITIALIZED -1
|
|
|
|
#define CONNECTED_STATE_NOT_CONNECTED 0
|
|
|
|
#define CONNECTED_STATE_CONNECTED 1
|
|
|
|
#define CONNECTED_STATE_UNKNOWN 2
|
|
|
|
|
|
|
|
#ifndef SIM
|
2014-06-20 14:48:31 +00:00
|
|
|
#if defined(_WIN32) && ( !defined(__MINGW32__) || defined(HAVE_LIBSENSAPI) )
|
2008-01-11 23:52:49 +00:00
|
|
|
#include <sensapi.h>
|
|
|
|
|
|
|
|
int get_connected_state() {
|
|
|
|
DWORD flags;
|
|
|
|
return IsNetworkAlive(&flags)?CONNECTED_STATE_CONNECTED:CONNECTED_STATE_NOT_CONNECTED;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
|
|
|
|
// anyone know how to see if this host has physical network connection?
|
|
|
|
//
|
|
|
|
int get_connected_state() {
|
|
|
|
return CONNECTED_STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
// exponential decay constant.
|
2006-08-29 23:15:47 +00:00
|
|
|
// The last 10 days have a weight of 1/e;
|
2002-04-30 22:22:54 +00:00
|
|
|
// everything before that has a weight of (1-1/e)
|
|
|
|
|
2006-08-29 23:15:47 +00:00
|
|
|
const float ALPHA = (SECONDS_PER_DAY*10);
|
2005-01-28 21:46:41 +00:00
|
|
|
//const float ALPHA = 60; // for testing
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2014-06-03 22:59:56 +00:00
|
|
|
// called before the client state file is parsed
|
|
|
|
//
|
2012-10-29 22:44:51 +00:00
|
|
|
void CLIENT_TIME_STATS::init() {
|
2014-06-03 22:59:56 +00:00
|
|
|
// members of TIME_STATS
|
|
|
|
now = 0;
|
2002-04-30 22:22:54 +00:00
|
|
|
on_frac = 1;
|
|
|
|
connected_frac = 1;
|
2014-06-03 22:59:56 +00:00
|
|
|
cpu_and_network_available_frac = 1;
|
2002-04-30 22:22:54 +00:00
|
|
|
active_frac = 1;
|
2010-08-23 05:00:22 +00:00
|
|
|
gpu_active_frac = 1;
|
2012-10-29 22:44:51 +00:00
|
|
|
client_start_time = gstate.now;
|
|
|
|
previous_uptime = 0;
|
2014-06-03 22:59:56 +00:00
|
|
|
session_active_duration = 0;
|
|
|
|
session_gpu_active_duration = 0;
|
|
|
|
total_start_time = 0;
|
2014-06-03 23:08:08 +00:00
|
|
|
total_duration = 0;
|
2014-06-03 22:59:56 +00:00
|
|
|
total_active_duration = 0;
|
|
|
|
total_gpu_active_duration = 0;
|
|
|
|
|
|
|
|
// members of CLIENT_TIME_STATS
|
|
|
|
first = true;
|
2007-04-11 21:49:57 +00:00
|
|
|
previous_connected_state = CONNECTED_STATE_UNINITIALIZED;
|
2014-06-03 22:59:56 +00:00
|
|
|
last_update = 0;
|
2007-04-11 21:49:57 +00:00
|
|
|
inactive_start = 0;
|
2014-06-03 22:59:56 +00:00
|
|
|
|
2007-04-11 21:49:57 +00:00
|
|
|
trim_stats_log();
|
2007-12-02 15:57:08 +00:00
|
|
|
time_stats_log = NULL;
|
2007-04-11 21:49:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// if log file is over a meg, discard everything older than a year
|
|
|
|
//
|
2012-10-29 22:44:51 +00:00
|
|
|
void CLIENT_TIME_STATS::trim_stats_log() {
|
2007-04-12 02:57:09 +00:00
|
|
|
#ifndef SIM
|
2007-04-11 21:49:57 +00:00
|
|
|
double size;
|
|
|
|
char buf[256];
|
|
|
|
int retval;
|
|
|
|
double x;
|
|
|
|
|
|
|
|
retval = file_size(TIME_STATS_LOG, size);
|
|
|
|
if (retval) return;
|
|
|
|
if (size < 1e6) return;
|
|
|
|
FILE* f = fopen(TIME_STATS_LOG, "r");
|
2007-06-29 15:45:15 +00:00
|
|
|
if (!f) return;
|
2008-10-07 12:45:06 +00:00
|
|
|
FILE* f2 = fopen(TEMP_TIME_STATS_FILE_NAME, "w");
|
2007-06-29 15:45:15 +00:00
|
|
|
if (!f2) {
|
|
|
|
fclose(f);
|
|
|
|
return;
|
|
|
|
}
|
2007-04-11 21:49:57 +00:00
|
|
|
while (fgets(buf, 256, f)) {
|
|
|
|
int n = sscanf(buf, "%lf", &x);
|
|
|
|
if (n != 1) continue;
|
|
|
|
if (x < gstate.now-86400*365) continue;
|
|
|
|
fputs(buf, f2);
|
|
|
|
}
|
|
|
|
fclose(f);
|
|
|
|
fclose(f2);
|
2007-04-12 02:57:09 +00:00
|
|
|
#endif
|
2007-04-11 21:49:57 +00:00
|
|
|
}
|
|
|
|
|
2007-06-20 23:16:30 +00:00
|
|
|
void send_log_after(const char* filename, double t, MIOFILE& mf) {
|
2007-04-11 21:49:57 +00:00
|
|
|
char buf[256];
|
2007-04-13 22:55:18 +00:00
|
|
|
double x;
|
2007-04-11 21:49:57 +00:00
|
|
|
|
2007-04-13 22:55:18 +00:00
|
|
|
FILE* f = fopen(filename, "r");
|
2007-04-11 21:49:57 +00:00
|
|
|
if (!f) return;
|
|
|
|
while (fgets(buf, 256, f)) {
|
|
|
|
int n = sscanf(buf, "%lf", &x);
|
|
|
|
if (n != 1) continue;
|
|
|
|
if (x < t) continue;
|
|
|
|
mf.printf("%s", buf);
|
|
|
|
}
|
|
|
|
fclose(f);
|
2007-04-13 22:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// copy the log file after a given time
|
|
|
|
//
|
2012-10-29 22:44:51 +00:00
|
|
|
void CLIENT_TIME_STATS::get_log_after(double t, MIOFILE& mf) {
|
2008-11-11 23:07:36 +00:00
|
|
|
if (time_stats_log) {
|
|
|
|
fclose(time_stats_log); // win: can't open twice
|
|
|
|
}
|
2007-04-13 22:55:18 +00:00
|
|
|
send_log_after(TIME_STATS_LOG, t, mf);
|
2007-04-11 21:49:57 +00:00
|
|
|
time_stats_log = fopen(TIME_STATS_LOG, "a");
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
|
2002-07-15 23:21:20 +00:00
|
|
|
// Update time statistics based on current activities
|
2005-01-28 19:01:08 +00:00
|
|
|
// NOTE: we don't set the state-file dirty flag here,
|
|
|
|
// so these get written to disk only when other activities
|
|
|
|
// cause this to happen. Maybe should change this.
|
2002-07-15 23:21:20 +00:00
|
|
|
//
|
2012-10-29 22:44:51 +00:00
|
|
|
void CLIENT_TIME_STATS::update(int suspend_reason, int _gpu_suspend_reason) {
|
2005-01-28 19:01:08 +00:00
|
|
|
double dt, w1, w2;
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2013-02-13 02:21:21 +00:00
|
|
|
bool is_active = (suspend_reason == 0) || (suspend_reason == SUSPEND_REASON_CPU_THROTTLE);
|
2011-06-12 20:58:43 +00:00
|
|
|
bool is_gpu_active = is_active && !_gpu_suspend_reason;
|
2014-06-03 22:59:56 +00:00
|
|
|
if (total_start_time == 0) {
|
|
|
|
total_start_time = gstate.now;
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
if (last_update == 0) {
|
|
|
|
// this is the first time this client has executed.
|
2005-01-28 21:46:41 +00:00
|
|
|
// Assume that everything is active
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
on_frac = 1;
|
2005-01-28 21:46:41 +00:00
|
|
|
connected_frac = 1;
|
|
|
|
active_frac = 1;
|
2010-08-23 05:00:22 +00:00
|
|
|
gpu_active_frac = 1;
|
2012-06-26 20:30:56 +00:00
|
|
|
cpu_and_network_available_frac = 1;
|
2002-04-30 22:22:54 +00:00
|
|
|
first = false;
|
2005-06-07 19:22:50 +00:00
|
|
|
last_update = gstate.now;
|
2007-04-11 21:49:57 +00:00
|
|
|
log_append("power_on", gstate.now);
|
2002-04-30 22:22:54 +00:00
|
|
|
} else {
|
2005-06-07 19:22:50 +00:00
|
|
|
dt = gstate.now - last_update;
|
2005-01-28 19:01:08 +00:00
|
|
|
if (dt <= 10) return;
|
2009-09-08 21:19:59 +00:00
|
|
|
|
|
|
|
if (dt > 14*86400) {
|
|
|
|
// If dt is large it could be because user is upgrading
|
|
|
|
// from a client version that wasn't updating due to bug.
|
|
|
|
// Or it could be because user wasn't running for a while
|
|
|
|
// and is starting up again.
|
2009-09-09 22:18:02 +00:00
|
|
|
// In either case, don't decay on_frac.
|
2009-09-08 21:19:59 +00:00
|
|
|
//
|
2009-09-09 22:18:02 +00:00
|
|
|
dt = 0;
|
2009-09-08 21:19:59 +00:00
|
|
|
}
|
|
|
|
|
2005-01-28 21:46:41 +00:00
|
|
|
w1 = 1 - exp(-dt/ALPHA); // weight for recent period
|
|
|
|
w2 = 1 - w1; // weight for everything before that
|
|
|
|
// (close to zero if long gap)
|
2006-11-02 21:35:47 +00:00
|
|
|
|
2008-01-11 23:52:49 +00:00
|
|
|
int connected_state;
|
|
|
|
#ifdef SIM
|
|
|
|
connected_state = CONNECTED_STATE_NOT_CONNECTED;
|
|
|
|
#else
|
|
|
|
connected_state = get_connected_state();
|
2007-04-11 21:49:57 +00:00
|
|
|
if (gstate.network_suspend_reason) {
|
|
|
|
connected_state = CONNECTED_STATE_NOT_CONNECTED;
|
|
|
|
}
|
|
|
|
#endif
|
2006-11-02 21:35:47 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
if (first) {
|
|
|
|
// the client has just started; this is the first call.
|
2005-01-28 21:46:41 +00:00
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
on_frac *= w2;
|
|
|
|
first = false;
|
2007-04-11 21:49:57 +00:00
|
|
|
log_append("power_off", last_update);
|
2008-01-11 23:52:49 +00:00
|
|
|
char buf[256];
|
|
|
|
#ifndef SIM
|
2016-02-18 05:59:13 +00:00
|
|
|
snprintf(buf, sizeof(buf),
|
|
|
|
"platform %s",
|
|
|
|
gstate.get_primary_platform()
|
|
|
|
);
|
2008-01-11 23:52:49 +00:00
|
|
|
log_append(buf, gstate.now);
|
|
|
|
#endif
|
2016-02-18 05:59:13 +00:00
|
|
|
snprintf(buf, sizeof(buf),
|
|
|
|
"version %d.%d.%d",
|
2012-06-26 20:30:56 +00:00
|
|
|
BOINC_MAJOR_VERSION, BOINC_MINOR_VERSION, BOINC_RELEASE
|
|
|
|
);
|
2008-01-11 23:52:49 +00:00
|
|
|
log_append(buf, gstate.now);
|
2007-04-11 21:49:57 +00:00
|
|
|
log_append("power_on", gstate.now);
|
2009-09-06 05:11:26 +00:00
|
|
|
} else if (dt > 100) {
|
|
|
|
// large dt - the client or host must have been suspended
|
|
|
|
on_frac *= w2;
|
|
|
|
log_append("proc_stop", last_update);
|
|
|
|
if (is_active) {
|
|
|
|
log_append("proc_start", gstate.now);
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
} else {
|
|
|
|
on_frac = w1 + w2*on_frac;
|
2012-06-26 20:30:56 +00:00
|
|
|
cpu_and_network_available_frac *= w2;
|
2005-01-28 21:46:41 +00:00
|
|
|
if (connected_frac < 0) connected_frac = 0;
|
|
|
|
switch (connected_state) {
|
|
|
|
case CONNECTED_STATE_NOT_CONNECTED:
|
|
|
|
connected_frac *= w2;
|
|
|
|
break;
|
|
|
|
case CONNECTED_STATE_CONNECTED:
|
|
|
|
connected_frac *= w2;
|
|
|
|
connected_frac += w1;
|
2012-06-26 20:30:56 +00:00
|
|
|
if (!gstate.network_suspended && !gstate.tasks_suspended) {
|
|
|
|
cpu_and_network_available_frac += w1;
|
|
|
|
}
|
2005-01-28 21:46:41 +00:00
|
|
|
break;
|
|
|
|
case CONNECTED_STATE_UNKNOWN:
|
|
|
|
connected_frac = -1;
|
2012-06-26 20:30:56 +00:00
|
|
|
if (!gstate.network_suspended && !gstate.tasks_suspended) {
|
|
|
|
cpu_and_network_available_frac += w1;
|
|
|
|
}
|
2005-01-28 21:46:41 +00:00
|
|
|
}
|
2007-04-11 21:49:57 +00:00
|
|
|
if (connected_state != previous_connected_state) {
|
|
|
|
log_append_net(connected_state);
|
|
|
|
previous_connected_state = connected_state;
|
|
|
|
}
|
2010-08-23 05:00:22 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
active_frac *= w2;
|
2014-06-03 22:59:56 +00:00
|
|
|
total_duration += dt;
|
2006-07-10 04:09:55 +00:00
|
|
|
if (is_active) {
|
|
|
|
active_frac += w1;
|
|
|
|
if (inactive_start) {
|
|
|
|
inactive_start = 0;
|
2007-04-11 21:49:57 +00:00
|
|
|
log_append("proc_start", gstate.now);
|
2006-07-10 04:09:55 +00:00
|
|
|
}
|
2014-06-03 22:59:56 +00:00
|
|
|
session_active_duration += dt;
|
|
|
|
total_active_duration += dt;
|
2006-07-10 04:09:55 +00:00
|
|
|
} else if (inactive_start == 0){
|
|
|
|
inactive_start = gstate.now;
|
2007-04-11 21:49:57 +00:00
|
|
|
log_append("proc_stop", gstate.now);
|
2006-07-10 04:09:55 +00:00
|
|
|
}
|
2010-08-23 05:00:22 +00:00
|
|
|
|
|
|
|
gpu_active_frac *= w2;
|
|
|
|
if (is_gpu_active) {
|
|
|
|
gpu_active_frac += w1;
|
2014-06-03 22:59:56 +00:00
|
|
|
session_gpu_active_duration += dt;
|
|
|
|
total_gpu_active_duration += dt;
|
2010-08-23 05:00:22 +00:00
|
|
|
}
|
|
|
|
|
2007-05-14 17:36:16 +00:00
|
|
|
//msg_printf(NULL, MSG_INFO, "is_active %d, active_frac %f", is_active, active_frac);
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2005-06-07 19:22:50 +00:00
|
|
|
last_update = gstate.now;
|
2006-09-06 15:51:26 +00:00
|
|
|
if (log_flags.time_debug) {
|
2006-09-07 20:39:25 +00:00
|
|
|
msg_printf(0, MSG_INFO,
|
2014-06-03 22:59:56 +00:00
|
|
|
"[time] dt %f susp_reason %d gpu_susp_reason %d",
|
|
|
|
dt, suspend_reason, _gpu_suspend_reason
|
|
|
|
);
|
|
|
|
msg_printf(0, MSG_INFO,
|
|
|
|
"[time] w2 %f on %f; active %f; gpu_active %f; conn %f, cpu_and_net_avail %f",
|
|
|
|
w2, on_frac, active_frac, gpu_active_frac, connected_frac,
|
2012-06-26 20:30:56 +00:00
|
|
|
cpu_and_network_available_frac
|
2006-09-06 15:51:26 +00:00
|
|
|
);
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-03 22:59:56 +00:00
|
|
|
// Write time statistics
|
|
|
|
// to_remote means GUI RPC reply; else writing client state file
|
2002-07-15 23:21:20 +00:00
|
|
|
//
|
2012-10-29 22:44:51 +00:00
|
|
|
int CLIENT_TIME_STATS::write(MIOFILE& out, bool to_remote) {
|
2004-06-12 04:45:36 +00:00
|
|
|
out.printf(
|
2002-04-30 22:22:54 +00:00
|
|
|
"<time_stats>\n"
|
|
|
|
" <on_frac>%f</on_frac>\n"
|
|
|
|
" <connected_frac>%f</connected_frac>\n"
|
2012-06-26 20:30:56 +00:00
|
|
|
" <cpu_and_network_available_frac>%f</cpu_and_network_available_frac>\n"
|
2010-08-23 05:00:22 +00:00
|
|
|
" <active_frac>%f</active_frac>\n"
|
2012-10-29 22:44:51 +00:00
|
|
|
" <gpu_active_frac>%f</gpu_active_frac>\n"
|
|
|
|
" <client_start_time>%f</client_start_time>\n"
|
2014-06-03 22:59:56 +00:00
|
|
|
" <total_start_time>%f</total_start_time>\n"
|
|
|
|
" <total_duration>%f</total_duration>\n"
|
|
|
|
" <total_active_duration>%f</total_active_duration>\n"
|
|
|
|
" <total_gpu_active_duration>%f</total_gpu_active_duration>\n",
|
2002-04-30 22:22:54 +00:00
|
|
|
on_frac,
|
|
|
|
connected_frac,
|
2012-06-26 20:30:56 +00:00
|
|
|
cpu_and_network_available_frac,
|
2010-08-23 05:00:22 +00:00
|
|
|
active_frac,
|
2012-10-29 22:44:51 +00:00
|
|
|
gpu_active_frac,
|
|
|
|
client_start_time,
|
2014-06-03 22:59:56 +00:00
|
|
|
total_start_time,
|
|
|
|
total_duration,
|
|
|
|
total_active_duration,
|
|
|
|
total_gpu_active_duration
|
2002-04-30 22:22:54 +00:00
|
|
|
);
|
2012-10-29 22:44:51 +00:00
|
|
|
if (to_remote) {
|
|
|
|
out.printf(
|
2014-06-03 22:59:56 +00:00
|
|
|
" <now>%f</now>\n"
|
|
|
|
" <previous_uptime>%f</previous_uptime>\n"
|
|
|
|
" <session_active_duration>%f</session_active_duration>\n"
|
|
|
|
" <session_gpu_active_duration>%f</session_gpu_active_duration>\n",
|
|
|
|
gstate.now,
|
|
|
|
previous_uptime,
|
|
|
|
session_active_duration,
|
|
|
|
session_gpu_active_duration
|
2012-10-29 22:44:51 +00:00
|
|
|
);
|
|
|
|
} else {
|
2004-06-12 04:45:36 +00:00
|
|
|
out.printf(
|
2014-06-03 22:59:56 +00:00
|
|
|
" <previous_uptime>%f</previous_uptime>\n"
|
2005-01-28 20:03:57 +00:00
|
|
|
" <last_update>%f</last_update>\n",
|
2014-06-03 22:59:56 +00:00
|
|
|
gstate.now - client_start_time,
|
2002-04-30 22:22:54 +00:00
|
|
|
last_update
|
|
|
|
);
|
|
|
|
}
|
2004-06-12 04:45:36 +00:00
|
|
|
out.printf("</time_stats>\n");
|
2002-04-30 22:22:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-06-03 22:59:56 +00:00
|
|
|
// Parse XML based time statistics from client_state.xml
|
2002-07-15 23:21:20 +00:00
|
|
|
//
|
2012-10-29 22:44:51 +00:00
|
|
|
int CLIENT_TIME_STATS::parse(XML_PARSER& xp) {
|
2008-12-19 20:55:49 +00:00
|
|
|
double x;
|
2010-12-22 18:59:07 +00:00
|
|
|
#ifdef SIM
|
2019-01-19 01:41:20 +00:00
|
|
|
// mean unavailability is 1 hour
|
|
|
|
//
|
2010-12-22 18:59:07 +00:00
|
|
|
double on_lambda = 3600, connected_lambda = 3600;
|
|
|
|
double active_lambda = 3600, gpu_active_lambda = 3600;
|
|
|
|
#endif
|
2002-08-15 22:03:41 +00:00
|
|
|
|
2011-08-11 06:17:33 +00:00
|
|
|
while (!xp.get_tag()) {
|
|
|
|
if (xp.match_tag("/time_stats")) {
|
2010-12-22 18:59:07 +00:00
|
|
|
#ifdef SIM
|
|
|
|
on_proc.init(on_frac, on_lambda);
|
|
|
|
connected_proc.init(connected_frac, connected_lambda);
|
|
|
|
active_proc.init(active_frac, active_lambda);
|
|
|
|
gpu_active_proc.init(gpu_active_frac, gpu_active_lambda);
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#ifdef SIM
|
2012-07-10 17:28:04 +00:00
|
|
|
if (xp.parse_double("on_lambda", on_lambda)) continue;
|
|
|
|
if (xp.parse_double("connected_lambda", connected_lambda)) continue;
|
|
|
|
if (xp.parse_double("active_lambda", active_lambda)) continue;
|
|
|
|
if (xp.parse_double("gpu_active_lambda", gpu_active_lambda)) continue;
|
2010-12-22 18:59:07 +00:00
|
|
|
#endif
|
2012-07-10 17:28:04 +00:00
|
|
|
if (xp.parse_double("last_update", x)) {
|
2008-12-19 20:55:49 +00:00
|
|
|
if (x < 0 || x > gstate.now) {
|
2010-09-27 20:34:47 +00:00
|
|
|
#ifndef SIM
|
2008-12-19 20:55:49 +00:00
|
|
|
msg_printf(0, MSG_INTERNAL_ERROR,
|
|
|
|
"bad value %f of time stats last update; ignoring", x
|
|
|
|
);
|
2010-09-27 20:34:47 +00:00
|
|
|
#endif
|
2008-12-19 20:55:49 +00:00
|
|
|
} else {
|
|
|
|
last_update = x;
|
|
|
|
}
|
|
|
|
continue;
|
2012-07-10 17:28:04 +00:00
|
|
|
}
|
|
|
|
if (xp.parse_double("on_frac", x)) {
|
2008-12-26 22:56:42 +00:00
|
|
|
if (x <= 0 || x > 1) {
|
2008-12-19 20:55:49 +00:00
|
|
|
msg_printf(0, MSG_INTERNAL_ERROR,
|
|
|
|
"bad value %f of time stats on_frac; ignoring", x
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
on_frac = x;
|
|
|
|
}
|
|
|
|
continue;
|
2012-07-10 17:28:04 +00:00
|
|
|
}
|
|
|
|
if (xp.parse_double("connected_frac", x)) {
|
2009-01-09 19:33:39 +00:00
|
|
|
// -1 means undefined; skip check
|
|
|
|
connected_frac = x;
|
2008-12-19 20:55:49 +00:00
|
|
|
continue;
|
2012-07-10 17:28:04 +00:00
|
|
|
}
|
|
|
|
if (xp.parse_double("cpu_and_network_available_frac", x)) {
|
2012-06-26 20:30:56 +00:00
|
|
|
if (x <= 0 || x > 1) {
|
|
|
|
msg_printf(0, MSG_INTERNAL_ERROR,
|
|
|
|
"bad value %f of time stats cpu_and_network_available_frac; ignoring", x
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
cpu_and_network_available_frac = x;
|
|
|
|
}
|
2012-07-10 17:28:04 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (xp.parse_double("active_frac", x)) {
|
2008-12-26 22:56:42 +00:00
|
|
|
if (x <= 0 || x > 1) {
|
2008-12-19 20:55:49 +00:00
|
|
|
msg_printf(0, MSG_INTERNAL_ERROR,
|
|
|
|
"bad value %f of time stats active_frac; ignoring", x
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
active_frac = x;
|
|
|
|
}
|
|
|
|
continue;
|
2012-07-10 17:28:04 +00:00
|
|
|
}
|
|
|
|
if (xp.parse_double("gpu_active_frac", x)) {
|
2010-08-23 05:00:22 +00:00
|
|
|
if (x <= 0 || x > 1) {
|
|
|
|
msg_printf(0, MSG_INTERNAL_ERROR,
|
|
|
|
"bad value %f of time stats gpu_active_frac; ignoring", x
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
gpu_active_frac = x;
|
|
|
|
}
|
|
|
|
continue;
|
2012-07-10 17:28:04 +00:00
|
|
|
}
|
2012-11-14 19:01:21 +00:00
|
|
|
if (xp.parse_double("client_start_time", x)) continue;
|
|
|
|
if (xp.parse_double("previous_uptime", previous_uptime)) continue;
|
2014-06-03 22:59:56 +00:00
|
|
|
if (xp.parse_double("total_start_time", total_start_time)) continue;
|
|
|
|
if (xp.parse_double("total_duration", total_duration)) continue;
|
|
|
|
if (xp.parse_double("total_active_duration", total_active_duration)) continue;
|
|
|
|
if (xp.parse_double("total_gpu_active_duration", total_gpu_active_duration)) continue;
|
2012-07-10 17:28:04 +00:00
|
|
|
if (log_flags.unparsed_xml) {
|
|
|
|
msg_printf(0, MSG_INFO,
|
|
|
|
"[unparsed_xml] TIME_STATS::parse(): unrecognized: %s\n",
|
|
|
|
xp.parsed_tag
|
|
|
|
);
|
2006-06-22 19:40:30 +00:00
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
2004-12-08 00:40:19 +00:00
|
|
|
|
2012-10-29 22:44:51 +00:00
|
|
|
void CLIENT_TIME_STATS::start() {
|
2007-12-02 15:57:08 +00:00
|
|
|
time_stats_log = fopen(TIME_STATS_LOG, "a");
|
|
|
|
if (time_stats_log) {
|
|
|
|
setbuf(time_stats_log, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-29 22:44:51 +00:00
|
|
|
void CLIENT_TIME_STATS::quit() {
|
2007-04-11 21:49:57 +00:00
|
|
|
log_append("power_off", gstate.now);
|
|
|
|
}
|
|
|
|
|
2008-10-27 20:17:22 +00:00
|
|
|
#ifdef SIM
|
2012-10-29 22:44:51 +00:00
|
|
|
void CLIENT_TIME_STATS::log_append(const char* , double ) {}
|
2008-10-27 20:17:22 +00:00
|
|
|
#else
|
2012-10-29 22:44:51 +00:00
|
|
|
void CLIENT_TIME_STATS::log_append(const char* msg, double t) {
|
2007-04-11 21:49:57 +00:00
|
|
|
if (!time_stats_log) return;
|
|
|
|
fprintf(time_stats_log, "%f %s\n", t, msg);
|
|
|
|
}
|
2008-10-27 20:17:22 +00:00
|
|
|
#endif
|
2007-04-11 21:49:57 +00:00
|
|
|
|
2012-10-29 22:44:51 +00:00
|
|
|
void CLIENT_TIME_STATS::log_append_net(int new_state) {
|
2007-04-11 21:49:57 +00:00
|
|
|
switch(new_state) {
|
|
|
|
case CONNECTED_STATE_NOT_CONNECTED:
|
|
|
|
log_append("net_not_connected", gstate.now);
|
|
|
|
break;
|
|
|
|
case CONNECTED_STATE_CONNECTED:
|
|
|
|
log_append("net_connected", gstate.now);
|
|
|
|
break;
|
|
|
|
case CONNECTED_STATE_UNKNOWN:
|
|
|
|
log_append("net_unknown", gstate.now);
|
|
|
|
break;
|
2006-07-10 04:09:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|