-2

I am trying to calculate Avg cpu time of a certain thread, using rusage.

however, i am getting ‘RUSAGE_THREAD’ was not declared in this scope.

i am using

#include <sys/resource.h>

and compiling with -D_GNU_SOURCE

at the start of my code, and my Linux version is fine.

this is where i try to do the calculation:

struct rusage l_rusage;
int retVal = getrusage(RUSAGE_THREAD, &l_rusage);

u64 userUSeconds = (static_cast<u64>(l_rusage.ru_utime.tv_sec)) * 1000000 +
  (static_cast<u64>(l_rusage.ru_utime.tv_usec));

u64 systemUSeconds = (static_cast<u64>(l_rusage.ru_stime.tv_sec)) * 1000000 +
  (static_cast<u64>(l_rusage.ru_stime.tv_usec));

return (userUSeconds + systemUSeconds) / ACE_OS::num_processors_online();

Any ideas? or maybe even a different solution? i am using ACE libs as well, so i have the ACE_OS, but i couldn't find the equivalent for RUSAGE_THREAD when trying to use ACE_OS::rusage.

Thank you

EDIT: Also another thing, i cant access to where the thread making code is actually, i can only use code from within the thread.

Colonel Thirty Two
  • 23,953
  • 8
  • 45
  • 85
Dinari
  • 2,487
  • 13
  • 28

1 Answers1

1

The manual page says you need to define the macro _GNU_SOURCE not __USE_GNU.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
  • My bad, but this still wont work, same error, moved the define to the makefile to make sure it is defined before every thing else. – Dinari Mar 16 '16 at 12:08
  • @Dinari did you find a solution to this problem? – asad_nitp May 25 '21 at 06:15
  • Was a long time ago, so i'm not sure, however I had this followup question - https://stackoverflow.com/questions/36181225/impossible-cpu-time-for-process-thread-with-rusage which include code examples to to do what I intended to. – Dinari May 25 '21 at 11:41