diff --git a/src/os/hpux/hpux_sigar.c b/src/os/hpux/hpux_sigar.c index c718a69c..a0a027a9 100644 --- a/src/os/hpux/hpux_sigar.c +++ b/src/os/hpux/hpux_sigar.c @@ -4,6 +4,7 @@ #include "sigar_util.h" #include +#include #include int sigar_os_open(sigar_t **sigar) @@ -439,11 +440,26 @@ int sigar_proc_modules_get(sigar_t *sigar, sigar_pid_t pid, return SIGAR_ENOTIMPL; } +#define TIME_NSEC(t) \ + (SIGAR_SEC2NANO((t).tv_sec) + (sigar_uint64_t)(t).tv_nsec) + int sigar_thread_cpu_get(sigar_t *sigar, sigar_uint64_t id, sigar_thread_cpu_t *cpu) { - return SIGAR_ENOTIMPL; + struct lwpinfo info; + + if (id != 0) { + return SIGAR_ENOTIMPL; + } + + _lwp_info(&info); + + cpu->user = TIME_NSEC(info.lwp_utime); + cpu->sys = TIME_NSEC(info.lwp_stime); + cpu->total = TIME_NSEC(info.lwp_utime) + TIME_NSEC(info.lwp_stime); + + return SIGAR_OK; } #include diff --git a/src/os/linux/linux_sigar.c b/src/os/linux/linux_sigar.c index bdd1c34a..128dc6d7 100644 --- a/src/os/linux/linux_sigar.c +++ b/src/os/linux/linux_sigar.c @@ -4,6 +4,7 @@ #include #include #include +#include #include "sigar.h" #include "sigar_private.h" @@ -899,11 +900,26 @@ int sigar_proc_modules_get(sigar_t *sigar, sigar_pid_t pid, return SIGAR_OK; } +#define TIME_NSEC(t) \ + SIGAR_SEC2NANO(((sigar_uint64_t)(t) / sigar->ticks)) + int sigar_thread_cpu_get(sigar_t *sigar, sigar_uint64_t id, sigar_thread_cpu_t *cpu) { - return SIGAR_ENOTIMPL; + struct tms now; + + if (id != 0) { + return SIGAR_ENOTIMPL; + } + + times(&now); + + cpu->user = TIME_NSEC(now.tms_utime); + cpu->sys = TIME_NSEC(now.tms_stime); + cpu->total = TIME_NSEC(now.tms_utime + now.tms_stime); + + return SIGAR_OK; } #include diff --git a/src/os/solaris/solaris_sigar.c b/src/os/solaris/solaris_sigar.c index 45fc20e1..308fcff5 100644 --- a/src/os/solaris/solaris_sigar.c +++ b/src/os/solaris/solaris_sigar.c @@ -4,6 +4,7 @@ #include "sigar_util.h" #include +#include #include #include #include @@ -1038,11 +1039,26 @@ int sigar_proc_modules_get(sigar_t *sigar, sigar_pid_t pid, } } +#define TIME_NSEC(t) \ + (SIGAR_SEC2NANO((t).tv_sec) + (sigar_uint64_t)(t).tv_nsec) + int sigar_thread_cpu_get(sigar_t *sigar, sigar_uint64_t id, sigar_thread_cpu_t *cpu) { - return SIGAR_ENOTIMPL; + struct lwpinfo info; + + if (id != 0) { + return SIGAR_ENOTIMPL; + } + + _lwp_info(&info); + + cpu->user = TIME_NSEC(info.lwp_utime); + cpu->sys = TIME_NSEC(info.lwp_stime); + cpu->total = TIME_NSEC(info.lwp_utime) + TIME_NSEC(info.lwp_stime); + + return SIGAR_OK; } #include