void* initMachine(void) { /* purpose: initialize the data structure. * returns: initialized MachineLinuxInfo structure. */ unsigned long version; MachineLinuxInfo* p = (MachineLinuxInfo*) calloc(1, sizeof(MachineLinuxInfo)); if (p == NULL) { printerr("calloc: %s\n", strerror(errno)); return NULL; } /* name of this provider -- overwritten by importers */ p->basic = initBasicMachine(); p->basic->provider = "linux"; gather_meminfo(&p->ram_total, &p->ram_free, &p->ram_shared, &p->ram_buffer, &p->swap_total, &p->swap_free); gather_loadavg(p->load); gather_proc_cpuinfo(p); gather_proc_uptime(&p->boottime, &p->idletime); version = extract_version(p->basic->uname.release); /* This used to have an upper limit of 3.2 from PM-571, but it was * removed because the Linux kernel is changing version numbers too * fast to keep updating it. */ if (version >= 2006000) { gather_linux_proc26(&p->procs, &p->tasks); } else if (version >= 2004000 && version <= 2004999) { gather_linux_proc24(&p->procs, &p->tasks); } else { printerr("Info: Kernel v%lu.%lu.%lu is not supported for proc stats gathering\n", version / 1000000, (version % 1000000) / 1000, version % 1000); } return p; }
void* initMachine(void) { /* purpose: initialize the data structure. * returns: initialized MachineDarwinInfo structure. */ MachineDarwinInfo* p = (MachineDarwinInfo*) calloc(1, sizeof(MachineDarwinInfo)); if (p == NULL) { printerr("calloc: %s\n", strerror(errno)); return NULL; } /* name of this provider -- overwritten by importers */ p->basic = initBasicMachine(); p->basic->provider = "darwin"; /* gather loadavg */ gather_darwin_meminfo(p); gather_loadavg(p->load); gather_darwin_uptime(p); gather_darwin_cpuinfo(p); gather_darwin_procstate(p->pid_state); return p; }