void work_queue_resources_measure_locally( struct work_queue_resources *r, const char *disk_path ) { static int gpu_check = 0; UINT64_T avail,total; r->cores.total = load_average_get_cpus(); r->cores.largest = r->cores.smallest = r->cores.total; /* For disk and memory, we compute the total thinking that the worker is * not executing by itself, but that it has to share its resources with * other processes/workers. */ host_disk_info_get(disk_path,&avail,&total); r->disk.total = (avail / (UINT64_T) MEGA) + r->disk.inuse; // Free + whatever we are using. r->disk.largest = r->disk.smallest = r->disk.total; host_memory_info_get(&avail,&total); r->memory.total = (avail / (UINT64_T) MEGA) + r->memory.inuse; // Free + whatever we are using. r->memory.largest = r->memory.smallest = r->memory.total; if(!gpu_check) { r->gpus.total = gpu_info_get(); r->gpus.largest = r->gpus.smallest = r->gpus.total; gpu_check = 1; } r->workers.total = 1; r->workers.largest = r->workers.smallest = r->workers.total; }
int block_size_estimate( struct text_list *seta ) { int count = MIN(100,text_list_size(seta)); int i; UINT64_T total_data = 0,free_mem,total_mem; int block_size; host_memory_info_get(&free_mem, &total_mem); for(i=0;i<count;i++) { total_data += get_file_size(text_list_get(seta,i)); } total_mem = total_mem/2; if(total_data>=total_mem) { block_size = text_list_size(seta) * total_mem / total_data; if(block_size<1) block_size = 1; if(block_size>text_list_size(seta)) block_size = text_list_size(seta); } else { block_size = text_list_size(seta); } return block_size; }
int main(int argc, char *argv[]) { char *host = CATALOG_HOST; int port = CATALOG_PORT; static const struct option long_options[] = { {"catalog", required_argument, 0, 'c'}, {0,0,0,0} }; signed int c; while ((c = getopt_long(argc, argv, "c:", long_options, NULL)) > -1) { switch (c) { case 'c': host = optarg; break; default: show_help(argv[0]); return EXIT_FAILURE; } } struct datagram *d; d = datagram_create(DATAGRAM_PORT_ANY); if (!d) { fatal("could not create datagram port!"); } struct utsname name; int cpus; int uptime; double load[3]; UINT64_T memory_total, memory_avail; char owner[USERNAME_MAX]; uname(&name); string_tolower(name.sysname); string_tolower(name.machine); string_tolower(name.release); load_average_get(load); cpus = load_average_get_cpus(); host_memory_info_get(&memory_avail, &memory_total); uptime = uptime_get(); username_get(owner); struct jx *j = jx_object(0); jx_insert_string(j,"type","node"); jx_insert(j,jx_string("version"),jx_format("%d.%d.%d",CCTOOLS_VERSION_MAJOR, CCTOOLS_VERSION_MINOR, CCTOOLS_VERSION_MICRO)); jx_insert_string(j,"cpu",name.machine); jx_insert_string(j,"opsys",name.sysname); jx_insert_string(j,"opsysversion",name.release); jx_insert_double(j,"load1",load[0]); jx_insert_double(j,"load5",load[1]); jx_insert_double(j,"load15",load[2]); jx_insert_integer(j,"memory_total",memory_total); jx_insert_integer(j,"memory_avail",memory_avail); jx_insert_integer(j,"cpus",cpus); jx_insert_integer(j,"uptime,",uptime); jx_insert_string(j,"owner",owner); int i; for (i = optind; i < argc; i++) { char *name; char *value; name = argv[i]; value = strchr(name, '='); if (!value) { fatal("invalid name/value pair = %s", name); } else { *value++ = 0; } jx_insert_string(j,name,value); } char *text = jx_print_string(j); char address[DATAGRAM_ADDRESS_MAX]; if (domain_name_cache_lookup(host, address)) { datagram_send(d, text, strlen(text), address, port); } else { fatal("unable to lookup address of host: %s", host); } jx_delete(j); datagram_delete(d); return EXIT_SUCCESS; }
static unsigned long get_mem_avail() { UINT64_T total, avail; host_memory_info_get(&total, &avail); return (unsigned long) avail / 1024; }