From 703bdc8fde03f75e86ad3a9e23e45968bee33608 Mon Sep 17 00:00:00 2001 From: Eric Heien Date: Mon, 14 Oct 2002 05:52:48 +0000 Subject: [PATCH] more host information svn path=/trunk/boinc/; revision=491 --- checkin_notes | 13 +++++ client/client_state.C | 1 + client/file_names.C | 4 +- client/hostinfo.h | 2 + client/hostinfo_unix.C | 108 +++++++++++++++++++++++++++++++++++------ client/scheduler_op.C | 2 +- 6 files changed, 112 insertions(+), 18 deletions(-) diff --git a/checkin_notes b/checkin_notes index 5f57991777..d8877491a8 100755 --- a/checkin_notes +++ b/checkin_notes @@ -2115,3 +2115,16 @@ David Oct 8 2002 tools/ backend_lib.C,h process_result_template.C + +Eric October 13, 2002 + - Now uses alternate means (statfs, sysctl) to get host information + on non-Linux platforms + - Fixed compile warnings + + client/ + client_state.C + hostinfo.h + hostinfo_unix.C + file_names.C + scheduler_op.C + diff --git a/client/client_state.C b/client/client_state.C index cbb0afc835..ac07e0df4e 100644 --- a/client/client_state.C +++ b/client/client_state.C @@ -136,6 +136,7 @@ int CLIENT_STATE::time_tests() { if (log_flags.measurement_debug) { printf("Getting general host information.\n"); } + clear_host_info(host_info); get_host_info(host_info); // this is platform dependent #if 0 double fpop_test_secs = 2.0; diff --git a/client/file_names.C b/client/file_names.C index 60d9543b98..b11abb0eb4 100644 --- a/client/file_names.C +++ b/client/file_names.C @@ -53,7 +53,7 @@ static void c2x(char *what) { // Escape a URL, converting the non alphanumeric characters to // %XY where XY is their hexadecimal equivalent // -static void escape_url(char *in, char* out) { +/*static void escape_url(char *in, char* out) { int x, y; for (x=0, y=0; in[x]; ++x) { if (isalnum(in[x]) || in[x]=='.' || in[x]=='-' || in[x]=='_') { @@ -72,7 +72,7 @@ static void escape_url(char *in, char* out) { } } out[y] = 0; -} +}*/ // Escape a URL for the project directory, cutting off the "http://", // converting '\' '/' and ' ' to '_', diff --git a/client/hostinfo.h b/client/hostinfo.h index 363c1f2531..029f7a9ff4 100644 --- a/client/hostinfo.h +++ b/client/hostinfo.h @@ -60,5 +60,7 @@ struct HOST_INFO { extern bool host_is_running_on_batteries(); extern int get_host_info(HOST_INFO&); +extern void clear_host_info(HOST_INFO&); +extern void get_host_disk_info( double &total_space, double &free_space ); #endif diff --git a/client/hostinfo_unix.C b/client/hostinfo_unix.C index 06e9db592b..39991ff267 100644 --- a/client/hostinfo_unix.C +++ b/client/hostinfo_unix.C @@ -24,12 +24,29 @@ #include #include +#include + #if HAVE_SYS_TYPES_H #include #endif -#if HAVE_SYS_STATVFS_H +#ifdef HAVE_SYS_MOUNT_H +#include +#endif +#ifdef HAVE_SYS_STATVFS_H #include #endif +#ifdef HAVE_SYS_VFS_H +#include +#endif + +#include + +#ifdef HAVE_SYS_STATVFS_H +#define STATFS statvfs +#else +#define STATFS statfs +#endif + #include #if HAVE_SYS_SWAP_H #include @@ -40,6 +57,9 @@ #include #endif +#if HAVE_SYS_SYSCTL_H +#include +#endif #if HAVE_SYS_SYSTEMINFO_H #include #endif @@ -221,9 +241,9 @@ void get_osinfo(HOST_INFO& host) { int get_host_info2(HOST_INFO &host); -// General function to get all relevant host information +// Reset the host info struct to default values // -int get_host_info(HOST_INFO& host) { +void clear_host_info(HOST_INFO& host) { host.timezone = 0; // seconds added to local time to get UTC strcpy(host.domain_name,""); strcpy(host.serialnum,""); @@ -250,23 +270,31 @@ int get_host_info(HOST_INFO& host) { host.d_total = 0; host.d_free = 0; +} +// Returns total and free space on current disk (in bytes) +// +void get_host_disk_info( double &total_space, double &free_space ) { +#ifdef STATFS + struct STATFS fs_info; + + STATFS(".", &fs_info); + total_space = (double)fs_info.f_bsize * (double)fs_info.f_blocks; + free_space = (double)fs_info.f_bsize * (double)fs_info.f_bavail; +#endif +} + +// General function to get all relevant host information +// +int get_host_info(HOST_INFO& host) { #ifdef _WIN32 return get_host_info2( host ); #endif -#if HAVE_SYS_SYSTEMINFO_H - struct statvfs foo; - char buf[256]; - - memset(&host, 0, sizeof(host)); + get_host_disk_info( host.d_total, host.d_free ); - get_local_domain_name(host.domain_name); - get_local_ip_addr_str(host.ip_addr); - - statvfs(".", &foo); - host.d_total = (double)foo.f_bsize * (double)foo.f_blocks; - host.d_free = (double)foo.f_bsize * (double)foo.f_bavail; +#if HAVE_SYS_SYSTEMINFO_H + char buf[256]; int i, n; sysinfo(SI_SYSNAME, host.os_name, sizeof(host.os_name)); @@ -289,11 +317,61 @@ int get_host_info(HOST_INFO& host) { } #endif +#if HAVE_SYS_SYSCTL_H + int mib[2], mem_size; + size_t len; + vmtotal vm_info; + + // Get number of CPUs + mib[0] = CTL_HW; + mib[1] = HW_NCPU; + len = sizeof(host.p_ncpus); + sysctl(mib, 2, &host.p_ncpus, &len, NULL, 0); + + // Get machine + mib[0] = CTL_HW; + mib[1] = HW_MACHINE; + len = sizeof(host.p_vendor); + sysctl(mib, 2, &host.p_vendor, &len, NULL, 0); + + // Get model + mib[0] = CTL_HW; + mib[1] = HW_MODEL; + len = sizeof(host.p_model); + sysctl(mib, 2, &host.p_model, &len, NULL, 0); + + // Get physical memory size + mib[0] = CTL_HW; + mib[1] = HW_PHYSMEM; + len = sizeof(mem_size); + sysctl(mib, 2, &mem_size, &len, NULL, 0); + host.m_nbytes = mem_size; + + // Get operating system name + mib[0] = CTL_KERN; + mib[1] = KERN_OSTYPE; + len = sizeof(host.os_name); + sysctl(mib, 2, &host.os_name, &len, NULL, 0); + + // Get operating system version + mib[0] = CTL_KERN; + mib[1] = KERN_OSRELEASE; + len = sizeof(host.os_version); + sysctl(mib, 2, &host.os_version, &len, NULL, 0); + + // TODO: Get virtual memory info + /*mib[0] = CTL_VM; + mib[1] = VM_METER; + len = sizeof(vm_info); + sysctl(mib, 2, &vm_info, &len, NULL, 0); + host.m_swap = vm_info.t_vm;*/ +#endif + #ifdef linux - memset(&host, 0, sizeof(host)); parse_cpuinfo(host); parse_meminfo(host); #endif + get_local_domain_name(host.domain_name); get_local_ip_addr_str(host.ip_addr); host.timezone = get_timezone(); diff --git a/client/scheduler_op.C b/client/scheduler_op.C index 357df77ea8..2902176ab9 100644 --- a/client/scheduler_op.C +++ b/client/scheduler_op.C @@ -169,7 +169,7 @@ int SCHEDULER_OP::parse_master_file(vector &urls) { } fclose(f); if (log_flags.sched_op_debug) { - printf("Parsed master file; got %d scheduler URLs\n", urls.size()); + printf("Parsed master file; got %d scheduler URLs\n", (int)urls.size()); } return 0; }