19# include <arpa/inet.h>
22# include <netinet/in.h>
24# include <sys/ioctl.h>
25# include <sys/socket.h>
26# include <sys/statvfs.h>
27# include <sys/types.h>
28# include <sys/utsname.h>
33#elif defined(__APPLE__)
34# include <mach/mach.h>
37# include <sys/mount.h>
38# include <sys/param.h>
39# include <sys/sysctl.h>
40# include <sys/types.h>
59# if (defined(WINVER)) && (WINVER >= 0x0502)
62# pragma comment(lib, "pdh.lib")
63# pragma comment(lib, "psapi.lib")
64# pragma comment(lib, "wbemuuid.lib")
84 while (
bufptr !=
nullptr) {
90 if (tail ==
bufptr + len) {
101bool getCpuEntry(
const char* tag,
const char* buff, std::string& value)
112 if (
pos1 ==
nullptr) {
116 while ((*
pos1 !=
'\0') && ((*
pos1 ==
' ') || (*
pos1 ==
':') || (*
pos1 ==
'\t'))) {
120 while ((*
pos2 !=
':') && ((*
pos2 ==
' ') || (*
pos2 ==
'\n'))) {
142 load.cpuLoad15 = 0.0;
143 load.cpuLoadInstant = (
int)0;
154 samples.push_back(load.cpuLoadInstant);
155 if (samples.size() > 180)
156 samples.erase(samples.begin());
158 std::vector<int>::reverse_iterator
rti;
161 for (
rti = samples.rbegin();
rti < samples.rend(); ++
rti) {
166 load.cpuLoad1 = (
double)(sum /
n) / 100.0;
169 load.cpuLoad5 = (
double)(sum /
n) / 100.0;
171 load.cpuLoad15 = (
double)(sum /
n) / 100.0;
187# if (defined(WINVER)) && (WINVER >= 0x0502)
221# if (defined(WINVER)) && (WINVER >= 0x0502)
229 std::vector<int> samples;
270#if defined(__linux__)
286#elif defined(__APPLE__)
334#if defined(__linux__)
348#if defined(__APPLE__)
460 switch (
sysinf.wProcessorArchitecture) {
478 switch (
sysinf.dwProcessorType) {
480 processor.
model =
"PROCESSOR_INTEL_386";
484 processor.
model =
"PROCESSOR_INTEL_486";
488 processor.
model =
"PROCESSOR_INTEL_PENTIUM";
492 processor.
model =
"PROCESSOR_INTEL_IA64";
496 processor.
model =
"PROCESSOR_AMD_X8664";
505 "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0",
520#if defined(__linux__)
530 processor.
model = value;
555#elif defined(__APPLE__)
560 size_t length =
sizeof(value);
562 if (!
sysctl(
mib, 2, &value, &length,
nullptr, 0)) {
566 if (!
sysctlbyname(
"hw.logicalcpu", &value, &length,
nullptr, 0)) {
567 processor.
cores = value;
579 processor.
model = buff;
582 if (!
sysctlbyname(
"machdep.cpu.family", &value, &length,
nullptr, 0)) {
586 if (!
sysctlbyname(
"machdep.cpu.model", &value, &length,
nullptr, 0)) {
602 platform.
name =
"Windows";
630 }
else if ((
osver.dwMajorVersion == 5) && (
osver.dwMinorVersion == 2)) {
638 }
else if ((
osver.dwMajorVersion == 5) && (
osver.dwMinorVersion == 1)) {
640 }
else if ((
osver.dwMajorVersion == 5) && (
osver.dwMinorVersion == 0)) {
647 for (
size_t i = 0;; i++) {
656 if (a[i + 1] ==
'\0') {
664#if defined(__linux__)
670 platform.
name =
"Linux";
674 FILE* release =
popen(
"lsb_release -ric",
"r");
675 if (release !=
nullptr) {
693 for (
int i = 0;
varChar !=
nullptr; i++) {
703#if defined(__APPLE__)
708 platform.
name = buff;
738#if defined(__linux__) || defined(__APPLE__)
741 if (
pwd !=
nullptr) {
771#if defined(__linux__)
777 char* tail =
strchr(buff,
'/');
778 if ((tail !=
nullptr) && (tail != buff)) {
786#if defined(__APPLE__)
814 info.schedPolicy = -1;
815 info.schedPriority = -1;
816#if defined(__linux__)
818 char cmdline[256] = {0};
820 sprintf(filename,
"/proc/%d/cmdline", pid);
821 file =
fopen(filename,
"r");
822 if (file !=
nullptr) {
823 char* p =
fgets(cmdline,
sizeof(cmdline) /
sizeof(*cmdline), file);
836 size_t index =
info.name.find(
' ');
837 if (index != std::string::npos) {
838 info.name =
info.name.substr(0, index);
839 info.arguments = cmdline;
840 info.arguments =
info.arguments.substr(index + 1);
848 info.schedPriority = param.__sched_priority;
857 info.name = filename;
894 hr = result->Get(L
"ProcessId", 0, &
ProcessId, 0, 0);
899 info.arguments.resize(res);
901 size_t idx =
info.arguments.find(
' ');
902 if (
idx ==
info.arguments.npos) {
903 info.arguments.clear();
925#elif defined(__APPLE__)
968 std::stringstream arguments;
979 info.arguments = arguments.str();
A mini-server for performing network communication in the background.
void release(void *handle) override
Return control to YARP of an object previously taken control of with the acquire() method.
BufferedPort()
Constructor.
An abstraction for a periodic thread.
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
A class for thread synchronization and mutual exclusion.
static MemoryInfo getMemoryInfo()
getMemoryInfo
static ProcessInfo getProcessInfo(int pid=0)
gets the operating system process information given by its PID.
static PlatformInfo getPlatformInfo()
getPlatformInfo
static UserInfo getUserInfo()
getUserInfo
static LoadInfo getLoadInfo()
getLoadInfo
static StorageInfo getStorageInfo()
getStorageInfo
static ProcessorInfo getProcessorInfo()
getProcessorInfo
#define yCError(component,...)
#define YARP_OS_LOG_COMPONENT(name, name_string)
An interface to the operating system, including Port based communication.
int getpid()
Portable wrapper for the getppid() function.
bool sum(yarp::sig::Image &OutImg, const yarp::sig::Image &InImg, bool colorkey_enable, int colorkey, bool alpha_enable, float alpha, size_t off_x, size_t off_y)
applies an image on the top over another image.
The LoadInfo struct holds the current cpu load information.
The MemoryInfo struct holds the system memory information.
The ProcessInfo struct provides the operating system process information.
The ProcessorInfo struct holds the processor information.
The StorageInfo struct holds the system storage information.
The UserInfo struct holds the current user information.