@@ -2413,10 +2413,10 @@ GetProcessTimes(
2413
2413
{
2414
2414
BOOL retval = FALSE ;
2415
2415
struct rusage resUsage;
2416
- __int64 calcTime;
2417
- const __int64 SECS_TO_NS = 1000000000 ; /* 10^9 */
2418
- const __int64 USECS_TO_NS = 1000 ; /* 10^3 */
2419
-
2416
+ UINT64 calcTime;
2417
+ const UINT64 SECS_TO_100NS = 10000000ULL ; // 10^7
2418
+ const UINT64 USECS_TO_100NS = 10ULL ; // 10
2419
+ const UINT64 EPOCH_DIFF = 11644473600ULL ; // number of seconds from 1 Jan. 1601 00:00 to 1 Jan 1970 00:00 UTC
2420
2420
2421
2421
PERF_ENTRY (GetProcessTimes);
2422
2422
ENTRY (" GetProcessTimes(hProcess=%p, lpExitTime=%p, lpKernelTime=%p,"
@@ -2448,12 +2448,46 @@ GetProcessTimes(
2448
2448
resUsage.ru_utime .tv_sec , resUsage.ru_utime .tv_usec ,
2449
2449
resUsage.ru_stime .tv_sec , resUsage.ru_stime .tv_usec );
2450
2450
2451
+ if (lpCreationTime)
2452
+ {
2453
+ // The IBC profile data uses this, instead of the actual
2454
+ // process creation time we just return the current time
2455
+
2456
+ struct timeval tv;
2457
+ if (gettimeofday (&tv, NULL ) == -1 )
2458
+ {
2459
+ ASSERT (" gettimeofday() failed; errno is %d (%s)\n " , errno, strerror (errno));
2460
+
2461
+ // Assign zero to lpCreationTime
2462
+ lpCreationTime->dwLowDateTime = 0 ;
2463
+ lpCreationTime->dwHighDateTime = 0 ;
2464
+ }
2465
+ else
2466
+ {
2467
+ calcTime = EPOCH_DIFF;
2468
+ calcTime += (UINT64)tv.tv_sec ;
2469
+ calcTime *= SECS_TO_100NS;
2470
+ calcTime += ((UINT64)tv.tv_usec * USECS_TO_100NS);
2471
+
2472
+ // Assign the time into lpCreationTime
2473
+ lpCreationTime->dwLowDateTime = (DWORD)calcTime;
2474
+ lpCreationTime->dwHighDateTime = (DWORD)(calcTime >> 32 );
2475
+ }
2476
+ }
2477
+
2478
+ if (lpExitTime)
2479
+ {
2480
+ // Assign zero to lpExitTime
2481
+ lpExitTime->dwLowDateTime = 0 ;
2482
+ lpExitTime->dwHighDateTime = 0 ;
2483
+ }
2484
+
2451
2485
if (lpUserTime)
2452
2486
{
2453
2487
/* Get the time of user mode execution, in 100s of nanoseconds */
2454
- calcTime = (__int64 )resUsage.ru_utime .tv_sec * SECS_TO_NS ;
2455
- calcTime += (__int64 )resUsage.ru_utime .tv_usec * USECS_TO_NS ;
2456
- calcTime /= 100 ; /* Produce the time in 100s of ns */
2488
+ calcTime = (UINT64 )resUsage.ru_utime .tv_sec * SECS_TO_100NS ;
2489
+ calcTime += (UINT64 )resUsage.ru_utime .tv_usec * USECS_TO_100NS ;
2490
+
2457
2491
/* Assign the time into lpUserTime */
2458
2492
lpUserTime->dwLowDateTime = (DWORD)calcTime;
2459
2493
lpUserTime->dwHighDateTime = (DWORD)(calcTime >> 32 );
@@ -2462,9 +2496,9 @@ GetProcessTimes(
2462
2496
if (lpKernelTime)
2463
2497
{
2464
2498
/* Get the time of kernel mode execution, in 100s of nanoseconds */
2465
- calcTime = (__int64 )resUsage.ru_stime .tv_sec * SECS_TO_NS ;
2466
- calcTime += (__int64 )resUsage.ru_stime .tv_usec * USECS_TO_NS ;
2467
- calcTime /= 100 ; /* Produce the time in 100s of ns */
2499
+ calcTime = (UINT64 )resUsage.ru_stime .tv_sec * SECS_TO_100NS ;
2500
+ calcTime += (UINT64 )resUsage.ru_stime .tv_usec * USECS_TO_100NS ;
2501
+
2468
2502
/* Assign the time into lpUserTime */
2469
2503
lpKernelTime->dwLowDateTime = (DWORD)calcTime;
2470
2504
lpKernelTime->dwHighDateTime = (DWORD)(calcTime >> 32 );
0 commit comments