PandA-2024.02
get_ticks.c
Go to the documentation of this file.
1 #include "get_ticks.h"
2 #include <sys/times.h>
3 #include <unistd.h>
4 
5 #if defined(_SC_CLK_TCK)
6 #define TIMES_TICKS_PER_SEC sysconf(_SC_CLK_TCK)
7 #elif defined(CLK_TCK)
8 #define TIMES_TICKS_PER_SEC CLK_TCK
9 #elif defined(HZ)
10 #define TIMES_TICKS_PER_SEC HZ
11 #else // !CLK_TCK && !_SC_CLK_TCK && !HZ
12 #define TIMES_TICKS_PER_SEC 60
13 #endif // !CLK_TCK && !_SC_CLK_TCK && !HZ
14 
19 unsigned int get_ticks(unsigned char restart_value)
20 {
21  unsigned int t;
22  struct tms now;
23  clock_t ret = times(&now);
24  if (ret == (clock_t)(-1))
25  now.tms_utime = now.tms_stime = now.tms_cutime = now.tms_cstime = ret = 0;
26  t = ((unsigned int)(now.tms_utime) * 1000) / (TIMES_TICKS_PER_SEC) + ((unsigned int)(now.tms_cutime) * 1000) / (TIMES_TICKS_PER_SEC);
27  return t;
28 }
29 
int times(int x, int y)
Definition: operations.c:3
unsigned int get_ticks(unsigned char restart_value)
return an unsigned int which represents the elapsed processor time in milliseconds since some constan...
Definition: get_ticks.c:19
#define TIMES_TICKS_PER_SEC
Definition: get_ticks.c:12

Generated on Mon Feb 12 2024 13:02:48 for PandA-2024.02 by doxygen 1.8.13