From cfa5ffb952785b3d66f6a0a817664d63108f3387 Mon Sep 17 00:00:00 2001 From: Abdirahim Musse Date: Fri, 10 Aug 2018 08:58:25 -0500 Subject: [PATCH] Added support for PASE installs --- .gitignore | 1 + AUTHORS.md | 1 + binding.gyp | 27 ++++++++++++-- org.eclipse.paho.mqtt.c/src/MQTTAsync.c | 4 +- src/ibmras/common/util/LibraryUtils.cpp | 2 +- src/ibmras/common/util/sysUtils.cpp | 2 +- .../plugins/common/cpu/cpuplugin.cpp | 37 ++++++++++++++++++- .../plugins/common/environment/envplugin.cpp | 6 +++ .../plugins/common/memory/MemoryPlugin.cpp | 22 ++++++++--- 9 files changed, 86 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 80ac3e0..b0ffaf4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ build/ libagentcore.so plugins/ +libagentcore.a diff --git a/AUTHORS.md b/AUTHORS.md index dc4e815..b25126d 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -10,4 +10,5 @@ Authors ordered by first contribution: - Julie Stalley (https://github.com/stalleyj) - Richard Lau (https://github.com/richardlau) - Gibson Fahnestock (https://github.com/gibfahn) + - Abdirahim Musse (https://github.com/ab-m) diff --git a/binding.gyp b/binding.gyp index 00c76b6..0cb06e7 100644 --- a/binding.gyp +++ b/binding.gyp @@ -43,8 +43,20 @@ ], "conditions": [ ['OS=="aix"', { - "defines": [ "_AIX", "AIX" ], - "libraries": [ "-Wl,-bexpall,-brtllib,-G,-bernotok,-brtl,-L.,-bnoipath" ], + 'variables': { + 'os_name': ' #elif defined(LINUX) || defined(__MACH__) || defined(__APPLE__) #include -#elif defined(AIX) +#elif defined(_AIX) #include #elif defined(_ZOS) #include diff --git a/src/ibmras/monitoring/plugins/common/cpu/cpuplugin.cpp b/src/ibmras/monitoring/plugins/common/cpu/cpuplugin.cpp index 2e71cce..339de27 100644 --- a/src/ibmras/monitoring/plugins/common/cpu/cpuplugin.cpp +++ b/src/ibmras/monitoring/plugins/common/cpu/cpuplugin.cpp @@ -24,10 +24,15 @@ #include #include #include -#if defined(_AIX) +#if defined(_AIX) && !defined(__PASE__) #include #include #endif +#if defined(__PASE__) +#include +#include +#include +#endif #if defined(__MACH__) || defined(__APPLE__) #include #include @@ -306,7 +311,7 @@ struct CPUTime* CpuPlugin::getCPUTime() { aCF.logMessage(debug, ">>>CpuPlugin::getCPUTime"); -#if defined(_AIX) +#if defined(_AIX) && !defined(__PASE__) static const uint32 NS_PER_CPU_TICK = 10000000; static const uint32 NS_PER_MS = 1000000; struct CPUTime* cputime = new CPUTime; @@ -426,6 +431,34 @@ struct CPUTime* CpuPlugin::getCPUTime() { } return cputime; +#elif defined(__PASE__) + struct CPUTime* cputime = new CPUTime; + struct rusage usage; + //microseconds->nanoseconds + uint64 nsStart = time_microseconds() *1000; + if (getrusage(RUSAGE_SELF, &usage) < 0){ + std::stringstream errorss; + errorss << "[env_os] Could not get process cpu time, error: "; + errorss << strerror(errno); + aCF.logMessage(warning, errorss.str().c_str()); + } + //microseconds->nanoseconds + uint64 nsEnd = time_microseconds() *1000; + + //seconds->microsecond + uint64 userTimeSec = static_cast(usage.ru_utime.tv_sec * 1000000); + uint64 userTimeMs = static_cast(usage.ru_utime.tv_usec); + + //seconds->microsecond + uint64 sysTimeSec = static_cast(usage.ru_stime.tv_sec * 1000000); + uint64 sysTimeMs = static_cast(usage.ru_stime.tv_usec); + + //microseconds->nanoseconds + cputime->process = ((userTimeSec + userTimeMs + sysTimeSec + sysTimeMs) *1000); + cputime->time = nsStart + ((nsEnd - nsStart) /2); + //TODO: figure out how to get global cpu time, For now place hold with 1. + cputime->total = uint64(1); + return cputime; #else return NULL; #endif diff --git a/src/ibmras/monitoring/plugins/common/environment/envplugin.cpp b/src/ibmras/monitoring/plugins/common/environment/envplugin.cpp index d7c921f..7a539c7 100644 --- a/src/ibmras/monitoring/plugins/common/environment/envplugin.cpp +++ b/src/ibmras/monitoring/plugins/common/environment/envplugin.cpp @@ -59,6 +59,12 @@ #include // get_nprocs() #include // gethostname() #include +#if defined(__PASE__) + //on PASE procinfo.h does not declare getargs() + extern "C"{ + extern int getargs(void *, int, char *, int); + } +#endif #include #endif diff --git a/src/ibmras/monitoring/plugins/common/memory/MemoryPlugin.cpp b/src/ibmras/monitoring/plugins/common/memory/MemoryPlugin.cpp index 7dd1eaf..f6ecd6b 100644 --- a/src/ibmras/monitoring/plugins/common/memory/MemoryPlugin.cpp +++ b/src/ibmras/monitoring/plugins/common/memory/MemoryPlugin.cpp @@ -59,7 +59,7 @@ #pragma comment(lib, "psapi.lib") #endif -#if defined(AIXPPC) +#if defined(_AIX) #include #include #include @@ -315,7 +315,7 @@ int64 MemoryPlugin::getProcessPhysicalMemorySize() { size_t size = t_info.resident_size; return size; -#elif defined(AIXPPC) +#elif defined(_AIX) /* * There is no API on AIX to get the rss of the shared memory used by this process. * If such an API was available, this function should return the following: @@ -367,7 +367,7 @@ int64 MemoryPlugin::getProcessPrivateMemorySize() { } } #undef SHARED_FIELD_INDEX -#elif defined(AIXPPC) +#elif defined(_AIX) struct procentry64 pe; pid_t pid = getpid(); @@ -416,7 +416,7 @@ int64 MemoryPlugin::getProcessVirtualMemorySize() { task_info(current_task(), TASK_BASIC_INFO, (task_info_t)&t_info, &t_info_count); size_t size = t_info.virtual_size; return size; -#elif defined(AIXPPC) +#elif defined(_AIX) /* There is no API on AIX to get shared memory usage for the process. If such an * API existed, we could return getProcessPrivateMemorySize() + sharedSize here. * @@ -459,7 +459,7 @@ int64 MemoryPlugin::getFreePhysicalMemorySize() { } return vm_stat.free_count*pageSize; -#elif defined(AIXPPC) +#elif defined(_AIX) && !defined(__PASE__) /* NOTE: This works on AIX 5.3 and later. */ IDATA numPageSizes = vmgetinfo(NULL, VMINFO_GETPSIZES, 0); @@ -496,13 +496,18 @@ int64 MemoryPlugin::getFreePhysicalMemorySize() { return statex.ullAvailPhys; } return -1; +#elif defined (__PASE__) + //TODO: Working on PASE Implementation + //AIXPPC implementation fails on PASE ... + // ...@ line 482 size never gets changed therefore -1 is returned + return -1; #else return -1; #endif } int64 MemoryPlugin::getTotalPhysicalMemorySize() { -#if defined (_AIX) +#if defined (_AIX) && !defined(__PASE__) return (int64)(sysconf(_SC_AIX_REALMEM) * 1024); #elif defined(_LINUX) ||defined(__MACH__)&&defined(_SC_PAGESIZE)&&defined(_SC_PHYS_PAGES) ||defined(__APPLE__)&&defined(_SC_PAGESIZE)&&defined(_SC_PHYS_PAGES) @@ -558,6 +563,11 @@ int64 MemoryPlugin::getTotalPhysicalMemorySize() { #elif defined(_S390) /* Get_Physical_Memory returns "SIZE OF ACTUAL REAL STORAGE ONLINE IN 'K'" */ return Get_Physical_Memory() * 1024; +#elif defined (__PASE__) + //TODO: Working on PASE implementation. + //AIX implementation: sysconf(_SC_AIX_REALMEM) returns -1 + //errno is set to 109 Function not implemented POSIX + return -1; #else return -1; #endif