WL#1023: Check if we can get CPU time used by thread

Affects: Benchmarks-3.0   —   Status: Un-Assigned   —   Priority: Medium

Check if there are a way (at least on primary platforms ) to account real
(possibly CPU+System) CPU utilization by the thread.

For process it is available in getrusage() as well in clock() function

If it is possible it shall be added to per thread performance counters.
Some other items from getrusage() are possibly good candidates to be available as 
global system statistics items.

[ Peter Gulutzan comment 2007-05-24 ]

It is possible with some operating systems using non-standard flags:
Solaris getrusage(RUSAGE_LWP) (LWP = "Light Weight Process")

It is not possible with NPTL thread library and Linux.
There has been some discussion about the possibility for later
Linux versions:
fa.linux.kernel thread "per-thread rusage"
[ Update 2008-10-29 ] Davi Arnaut says
"Linux supports per-thread resource usage since 2.6.25.
The RUSAGE_THREAD flag appeared in a later glibc version."

The analogous Windows function is GetThreadTimes
On some (older?) Windows versions GetThreadTimes may not be useful though:

Oracle uses a connection-per-process model for Unix-like systems while
MySQL uses a connection-per-thread model. That's why Oracle can take
advantage of getrusage in places that MySQL can't.

On some computers (e.g. testing with sol9x86) getrusage takes 2-3
microseconds. So be cautious about the suggestion of adding to
"per thread performance counters".

There is a contributed patch (SHOW PROFILE etc. in 5.0-community) which
depends on getrusage. See also dev-private thread
"BUG#28288 Query Profiler not available in MySQL 5.1 and 6.0"
[mysql intranet]/secure/mailarchive/mail.php?folder=4&mail=25818

On Dec 11, 2008 @ 16:42, Mark Callaghan wrote on mysql forge:
"This would be nice to have but you need new versions of Linux and/or
glibc to get this on Linux. And just because the getrusage interfaces
are there doesn't mean that you will get per-thread results.
We learned this the hard way."