thread_cpu impl

This commit is contained in:
Doug MacEachern 2004-11-17 05:50:18 +00:00
parent cf93196a8a
commit 65fe21ae2b
3 changed files with 51 additions and 3 deletions

View File

@ -4,6 +4,7 @@
#include "sigar_util.h" #include "sigar_util.h"
#include <sys/dk.h> #include <sys/dk.h>
#include <sys/lwp.h>
#include <errno.h> #include <errno.h>
int sigar_os_open(sigar_t **sigar) 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; 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, int sigar_thread_cpu_get(sigar_t *sigar,
sigar_uint64_t id, sigar_uint64_t id,
sigar_thread_cpu_t *cpu) 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 <mntent.h> #include <mntent.h>

View File

@ -4,6 +4,7 @@
#include <errno.h> #include <errno.h>
#include <sys/param.h> #include <sys/param.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/times.h>
#include "sigar.h" #include "sigar.h"
#include "sigar_private.h" #include "sigar_private.h"
@ -899,11 +900,26 @@ int sigar_proc_modules_get(sigar_t *sigar, sigar_pid_t pid,
return SIGAR_OK; return SIGAR_OK;
} }
#define TIME_NSEC(t) \
SIGAR_SEC2NANO(((sigar_uint64_t)(t) / sigar->ticks))
int sigar_thread_cpu_get(sigar_t *sigar, int sigar_thread_cpu_get(sigar_t *sigar,
sigar_uint64_t id, sigar_uint64_t id,
sigar_thread_cpu_t *cpu) 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 <mntent.h> #include <mntent.h>

View File

@ -4,6 +4,7 @@
#include "sigar_util.h" #include "sigar_util.h"
#include <sys/link.h> #include <sys/link.h>
#include <sys/lwp.h>
#include <sys/proc.h> #include <sys/proc.h>
#include <sys/swap.h> #include <sys/swap.h>
#include <sys/stat.h> #include <sys/stat.h>
@ -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, int sigar_thread_cpu_get(sigar_t *sigar,
sigar_uint64_t id, sigar_uint64_t id,
sigar_thread_cpu_t *cpu) 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 <sys/mnttab.h> #include <sys/mnttab.h>