From 65fe21ae2b370727e71d576b8fb516f38898197a Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Wed, 17 Nov 2004 05:50:18 +0000 Subject: [PATCH] thread_cpu impl --- src/os/hpux/hpux_sigar.c | 18 +++++++++++++++++- src/os/linux/linux_sigar.c | 18 +++++++++++++++++- src/os/solaris/solaris_sigar.c | 18 +++++++++++++++++- 3 files changed, 51 insertions(+), 3 deletions(-) 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