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) {
505 "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0",
520#if defined(__linux__)
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)) {
582 if (!
sysctlbyname(
"machdep.cpu.family", &value, &length,
nullptr, 0)) {
586 if (!
sysctlbyname(
"machdep.cpu.model", &value, &length,
nullptr, 0)) {
653 }
else if ((
osver.dwMajorVersion == 5) && (
osver.dwMinorVersion == 2)) {
661 }
else if ((
osver.dwMajorVersion == 5) && (
osver.dwMinorVersion == 1)) {
663 }
else if ((
osver.dwMajorVersion == 5) && (
osver.dwMinorVersion == 0)) {
671 for (
size_t i = 0;; i++) {
680 if (a[i + 1] ==
'\0') {
689#if defined(__linux__)
699 FILE* release =
popen(
"lsb_release -ric",
"r");
700 if (release !=
nullptr) {
718 for (
int i = 0;
varChar !=
nullptr; i++) {
730#if defined(__APPLE__)
765#if defined(__linux__) || defined(__APPLE__)
768 if (
pwd !=
nullptr) {
798#if defined(__linux__)
804 char* tail =
strchr(buff,
'/');
805 if ((tail !=
nullptr) && (tail != buff)) {
813#if defined(__APPLE__)
841 info.schedPolicy = -1;
842 info.schedPriority = -1;
843#if defined(__linux__)
845 char cmdline[256] = {0};
847 sprintf(filename,
"/proc/%d/cmdline", pid);
848 file =
fopen(filename,
"r");
849 if (file !=
nullptr) {
850 char* p =
fgets(cmdline,
sizeof(cmdline) /
sizeof(*cmdline), file);
863 size_t index =
info.name.find(
' ');
864 if (index != std::string::npos) {
865 info.name =
info.name.substr(0, index);
866 info.arguments = cmdline;
867 info.arguments =
info.arguments.substr(index + 1);
875 info.schedPriority = param.__sched_priority;
884 info.name = filename;
921 hr = result->Get(L
"ProcessId", 0, &
ProcessId, 0, 0);
926 info.arguments.resize(res);
928 size_t idx =
info.arguments.find(
' ');
929 if (
idx ==
info.arguments.npos) {
930 info.arguments.clear();
952#elif defined(__APPLE__)
995 std::stringstream arguments;
1006 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 interface for reading from a network connection.
An interface for writing to a network connection.
Holds the current cpu load information.
std::int32_t cpuLoadInstant
Holds the system memory information.
An abstraction for a periodic thread.
Holds the operating system process information.
Holds the processor information.
A class for storing options and configuration information.
A class for thread synchronization and mutual exclusion.
Holds the system storage information.
bool write(const yarp::os::idl::WireWriter &writer) const override
bool read(yarp::os::idl::WireReader &reader) override
ProcessorInfoData processor
PlatformInfoData platform
static MemoryInfo getMemoryInfo()
getMemoryInfo
bool write(yarp::os::ConnectionWriter &connection) const override
write the SystemInfo structs using a ConnectionWriter.
static ProcessInfo getProcessInfo(int pid=0)
gets the operating system process information given by its PID.
static PlatformInfo getPlatformInfo()
getPlatformInfo
static UserInfo getUserInfo()
getUserInfo
bool read(yarp::os::ConnectionReader &connection) override
reads from a ConnectionReader and fill into the SystemInfo structs.
static LoadInfo getLoadInfo()
getLoadInfo
static StorageInfo getStorageInfo()
getStorageInfo
static ProcessorInfo getProcessorInfo()
getProcessorInfo
void updateSystemInfo()
updates the system information by calling the static methods to retrieve the latest data.
Holds the current user information.
#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.