c++ - Determine user & system time used by a thread -


We have a qthreads-based workflow engine where workers choose bundles of thread inputs as they are placed on a queue , Then their output on another line to run the next stage for the second worker thread; And so long as all inputs have not been consumed and all the outputs have been generated.

Usually, many threads are going to run the same task and others will have to run other functions at the same time. We want to demonstrate the benchmark of these threaded tasks to target optimization efforts.

It is easy to get the actual (elapsed) time, which is the difference between the return value of the posics bar () function at the beginning and end of the run () process of the thread, by running a given task. Let's see. However, I can not understand how to get related users and system time. Receiving these from the struct tms which you do not work on time (), because in this structure, the system of total users and all threads runs while the thread is active in the question.

This is how Linux is happening on how to getrusage (with RUSAGE_THREAD) ? Solaris also provides RUSAGE_LWP which is similar and I think there are likely similarities to other POSIX-like systems.

Crude Examples:

  #define _GNU_SOURCE #include & lt; Sys / time h & gt; # Include & lt; Sys / source.h> # Include & lt; Stdio.h & gt; # Include & lt; Pthread.h & gt; # Include & lt; Assert.h & gt; # Include & lt; Unistd.h & gt; Struct tinfo {pthread_t thread; Int id; Straight rays start; Straight Rays End; }; Static zero * thread_start (zero * arg) {struct tinfo * inf = arg; Getrusage (RUSAGE_THREAD, & amp; inf-> Start); If (inf-> id) {sleep (10); } Else {const time_t start = time (zero); While (time (tap) - start <10); // Waste CPU time! } Getrusage (RUSAGE_THREAD, & amp; inf-> End); Return 0; } Int main () {static const int nrthr = 2; Structure Tinfo status [nrthr]; For (int i = 0; i  

I think that something like this is possible on Windows using GetProcessTimes ()


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -