8 #if defined(Q_OS_WIN32)
10 #elif defined(Q_OS_UNIX)
17 #if defined(Q_OS_WIN32)
19 static int getCpuTimeMs(
const FILETIME &kernelTime,
const FILETIME &userTime)
21 const ULARGE_INTEGER kernel { { kernelTime.dwLowDateTime, kernelTime.dwHighDateTime } };
22 const ULARGE_INTEGER user { { userTime.dwLowDateTime, userTime.dwHighDateTime } };
23 const quint64 usecs = (kernel.QuadPart + user.QuadPart) / 10ull;
24 return static_cast<int>(usecs / 1000ull);
28 FILETIME creationTime, exitTime, kernelTime, userTime;
29 GetProcessTimes(GetCurrentProcess(), &creationTime, &exitTime, &kernelTime, &userTime);
30 return getCpuTimeMs(kernelTime, userTime);
34 FILETIME creationTime, exitTime, kernelTime, userTime;
35 GetThreadTimes(GetCurrentThread(), &creationTime, &exitTime, &kernelTime, &userTime);
36 return getCpuTimeMs(kernelTime, userTime);
39 #elif defined(Q_OS_UNIX)
41 static int getCpuTimeMs(
const timespec &ts)
43 const double secs =
static_cast<double>(ts.tv_sec) +
static_cast<double>(ts.tv_nsec) / 1e9;
44 return static_cast<int>(secs * 1000);
49 clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts);
50 return getCpuTimeMs(ts);
55 clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts);
56 return getCpuTimeMs(ts);
Free functions in swift::misc.
int getProcessCpuTimeMs()
Get the time in milliseconds that the CPU has spent executing the current process.
int getThreadCpuTimeMs()
Get the time in milliseconds that the CPU has spent executing the current thread.