int sigar_thread_cpu_get(sigar_t *sigar, sigar_uint64_t id, sigar_thread_cpu_t *cpu) { #ifdef __ia64__ /* XXX seems _lwp funcs were for solaris compat and dont exist * on itanium. hp docs claim that have equiv functions, * but wtf is it for _lwp_info? */ return SIGAR_ENOTIMPL; #else 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; #endif }
double get_cputime() { struct lwpinfo structtime; double total, floor(); struct timespec usertime; _lwp_info(&structtime); usertime = structtime.lwp_utime; total = (double) usertime.tv_sec + ((double) usertime.tv_nsec / 1e9); /* total = (floor(total * 1000.) / 1000.) - sttime; */ total -= sttime; return (total); }