I need to measure the cpu usage of individual threads on darwin. On linux I use getrusage(RUSAGE_THREAD, ...) but it's not available on darwin.
RUSAGE_THREAD flag of getrusage is Linux-specific.
getrusage of xnu does output only per-process sum.
Information about usage times of each thread is maintained in task_basic_info
struct of each thread.
Documentation is here http://www.gnu.org/software/hurd/gnumach-doc/Task-Information.html
Here is a simple example of how to get task_basic_info
struct
http://blog.kuriositaet.de/?p=257
task_info(mach_task_self(), TASK_BASIC_INFO, (task_info_t)&t_info, &t_info_count)