-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCcpProcess.cpp
More file actions
38 lines (30 loc) · 877 Bytes
/
CcpProcess.cpp
File metadata and controls
38 lines (30 loc) · 877 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright © 2013 CCP ehf.
#include "include/CcpProcess.h"
#if defined( _WIN32 )
CcpProcessId_t CcpGetCurrentProcessId()
{
return GetCurrentProcessId();
}
bool CcpGetProcessTimes( int64_t& kernelTime, int64_t& userTime )
{
FILETIME dummy;
return GetProcessTimes( GetCurrentProcess(), &dummy, &dummy, (LPFILETIME)&kernelTime, (LPFILETIME)&userTime ) != 0;
}
#else
#include <sys/resource.h>
CcpProcessId_t CcpGetCurrentProcessId()
{
return getpid();
}
bool CcpGetProcessTimes( int64_t& kernelTime, int64_t& userTime )
{
struct rusage usage;
if( !getrusage( RUSAGE_SELF, &usage ) )
{
kernelTime = int64_t( usage.ru_stime.tv_sec ) * 10000000 + int64_t( usage.ru_stime.tv_usec ) * 10;
userTime = int64_t( usage.ru_utime.tv_sec ) * 10000000 + int64_t( usage.ru_utime.tv_usec ) * 10;
return true;
}
return false;
}
#endif