From 56dd21f443c86c3bf96a884c970ceed11a56409a Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Fri, 29 May 2015 13:54:11 +0200 Subject: added more around physical memory (worker/coordingator data and cli data) --- src/biruda.c | 2 +- src/cli.c | 4 ++++ src/coordinator.c | 5 +++++ src/system.c | 2 +- src/system.h | 2 +- src/worker.c | 7 +++++++ 6 files changed, 19 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/biruda.c b/src/biruda.c index 091bbbf..ff2f046 100644 --- a/src/biruda.c +++ b/src/biruda.c @@ -205,7 +205,7 @@ static void print_config( struct gengetopt_args_info *args_info, cfg_t *cfg ) puts( "Environment:" ); printf( " Number of CPUs: %d\n", nofCpus ); int physMem = system_phys_memory( ); - printf( " Physical memory available: %d kB\n", physMem ); + printf( " Physically installed memory: %d kB\n", physMem ); char machine_arch[100]; system_arch( machine_arch, sizeof( machine_arch ) ); printf( " System architecture: %s\n", machine_arch ); diff --git a/src/cli.c b/src/cli.c index 0ec95b1..f5bdcd1 100644 --- a/src/cli.c +++ b/src/cli.c @@ -400,6 +400,7 @@ void print_guessed_env( bool human_readable ) char hostname[100]; gethostname( hostname, sizeof( hostname ) ); unsigned int nofCpus = system_available_cpus( ); + unsigned int nofPhysMem = system_phys_memory( ); char os_name[100]; system_os( os_name, sizeof( os_name ) ); char machine_arch[100]; @@ -410,6 +411,7 @@ void print_guessed_env( bool human_readable ) printf( "Operating system: %s\n", os_name ); printf( "Hostname: %s\n", hostname ); printf( "Number of CPUs: %d\n", nofCpus ); + printf( "Physical memory in kB: %d\n", nofPhysMem ); } else { json_object *obj = json_object_new_object( ); @@ -421,6 +423,8 @@ void print_guessed_env( bool human_readable ) json_object_object_add( obj, "host", host ); json_object *cpus = json_object_new_int( nofCpus ); json_object_object_add( obj, "cpus", cpus ); + json_object *physMem = json_object_new_int( nofPhysMem ); + json_object_object_add( obj, "physical_memory", physMem ); const char *msg = json_object_to_json_string( obj ); char *res = strdup( msg ); diff --git a/src/coordinator.c b/src/coordinator.c index b1412e0..356a402 100644 --- a/src/coordinator.c +++ b/src/coordinator.c @@ -121,6 +121,11 @@ static char *create_register_answer( ) json_object *cpus = json_object_new_int( nofCpus ); json_object_object_add( obj, "cpus", cpus ); + /* physically installed memory in kBytes */ + unsigned int nofPhysMem = system_phys_memory( ); + json_object *physMem = json_object_new_int( nofPhysMem ); + json_object_object_add( obj, "physical_memory", physMem ); + /* Operating system running on the coordinator, this is * important so we know what we can run on the system * directly diff --git a/src/system.c b/src/system.c index 9e2256d..96a07ab 100644 --- a/src/system.c +++ b/src/system.c @@ -383,7 +383,7 @@ void system_arch( char *name, size_t len ) #endif } -int system_phys_memory( ) +unsigned int system_phys_memory( ) { #ifdef _WIN32 MEMORYSTATUSEX memState; diff --git a/src/system.h b/src/system.h index 1b84c5a..3ff2ebb 100644 --- a/src/system.h +++ b/src/system.h @@ -10,6 +10,6 @@ void system_os( char *name, size_t len ); void system_arch( char *name, size_t len ); /* in kilobytes */ -int system_phys_memory( ); +unsigned int system_phys_memory( ); #endif diff --git a/src/worker.c b/src/worker.c index 7529394..4360432 100644 --- a/src/worker.c +++ b/src/worker.c @@ -346,6 +346,13 @@ static char *expand_system_variables( const char *s ) strncpy( d, buf, strlen( buf ) ); d += strlen( buf ); state = COPYING; + } else if( strncmp( var, "PHYSICAL_MEMORY", 15 ) == 0 ) { + unsigned int physMem = system_phys_memory( ); + char buf[12]; + snprintf( buf, sizeof( buf ), "%d", physMem ); + strncpy( d, buf, strlen( buf ) ); + d += strlen( buf ); + state = COPYING; } else { fprintf( stderr, "ERROR: Unknown variable '${%*s}' at position %d in '%s'\n", (int)( p-var ), var, (int)( p - s ), s ); state = _ERROR; -- cgit v1.2.3-54-g00ecf