cpu_time.cpp
Go to the documentation of this file.
1 
8 /*****************************************************************************
9 ** Includes
10 *****************************************************************************/
11 
12 #include "../../include/ecl/time_lite/cpu_time.hpp"
13 #include <errno.h>
14 
15 /*****************************************************************************
16 ** Namespaces
17 *****************************************************************************/
18 
19 namespace ecl {
20 
21 #ifdef ECL_HAS_CPUTIME
22 TimeError cpu_time(TimeStructure &time) {
23  // On the man page, it says that this function should need _POSIX_CPUTIME
24  // defined, but in practice I'm a bit unusre about this. On one system,
25  // I've had _POSIX_CPUTIME defined to 0, but this function would still work.
26  // Just assuming that you need clock_gettime for now.
27  int result = clock_gettime(CLOCK_PROCESS_CPUTIME_ID,&time);
28  switch (result) {
29  case(0) : { return TimeError(NoError); }
30  case(EFAULT) : { return TimeError(MemoryError); } // time was not in addressable memory space
31  case(EINVAL) : { return TimeError(ArgNotSupportedError); } // clock id is not supported (actually impossible if cmake detects)
32  case(EPERM) : { return TimeError(PermissionsError); } // user does not have permissions to use the clock.
33  default : { return TimeError(UnknownError); }
34  }
35 }
36 #endif
37 
38 } // namespace ecl
PermissionsError
UnknownError
MemoryError
ArgNotSupportedError


ecl_time_lite
Author(s): Daniel Stonier
autogenerated on Fri Jun 7 2019 21:52:47