From e7815dde1e3847841b260e700704da8f7b4f7a30 Mon Sep 17 00:00:00 2001 From: Brian Sullivan Date: Wed, 1 May 2019 10:45:39 -0700 Subject: [PATCH] In the PAL GetProcessTimes implement lpCreationTime using the current time returned by gettimeofday This allows IBC profile data to record a meaningful time of when the training scenario was run. Made EPOCH_DIFF a defined constant Change calcTime to be an unsigned 64-bit integer Change constants to units of 100NS instead of NS to avoid division and integer overflows. Use the defined constants SECS_TO_100NS and USECS_TO_100NS when performing time calculations Don't add a space after the Assembly arg when argc is zero --- src/pal/src/thread/process.cpp | 54 ++++++++++++++++++++++++++++++++++-------- src/vm/ceeload.cpp | 6 ++--- 2 files changed, 47 insertions(+), 13 deletions(-) diff --git a/src/pal/src/thread/process.cpp b/src/pal/src/thread/process.cpp index 74ec02f..445b75c 100644 --- a/src/pal/src/thread/process.cpp +++ b/src/pal/src/thread/process.cpp @@ -2413,10 +2413,10 @@ GetProcessTimes( { BOOL retval = FALSE; struct rusage resUsage; - __int64 calcTime; - const __int64 SECS_TO_NS = 1000000000; /* 10^9 */ - const __int64 USECS_TO_NS = 1000; /* 10^3 */ - + UINT64 calcTime; + const UINT64 SECS_TO_100NS = 10000000ULL; // 10^7 + const UINT64 USECS_TO_100NS = 10ULL; // 10 + const UINT64 EPOCH_DIFF = 11644473600ULL; // number of seconds from 1 Jan. 1601 00:00 to 1 Jan 1970 00:00 UTC PERF_ENTRY(GetProcessTimes); ENTRY("GetProcessTimes(hProcess=%p, lpExitTime=%p, lpKernelTime=%p," @@ -2448,12 +2448,46 @@ GetProcessTimes( resUsage.ru_utime.tv_sec, resUsage.ru_utime.tv_usec, resUsage.ru_stime.tv_sec, resUsage.ru_stime.tv_usec); + if (lpCreationTime) + { + // The IBC profile data uses this, instead of the actual + // process creation time we just return the current time + + struct timeval tv; + if (gettimeofday(&tv, NULL) == -1) + { + ASSERT("gettimeofday() failed; errno is %d (%s)\n", errno, strerror(errno)); + + // Assign zero to lpCreationTime + lpCreationTime->dwLowDateTime = 0; + lpCreationTime->dwHighDateTime = 0; + } + else + { + calcTime = EPOCH_DIFF; + calcTime += (UINT64)tv.tv_sec; + calcTime *= SECS_TO_100NS; + calcTime += ((UINT64)tv.tv_usec * USECS_TO_100NS); + + // Assign the time into lpCreationTime + lpCreationTime->dwLowDateTime = (DWORD)calcTime; + lpCreationTime->dwHighDateTime = (DWORD)(calcTime >> 32); + } + } + + if (lpExitTime) + { + // Assign zero to lpExitTime + lpExitTime->dwLowDateTime = 0; + lpExitTime->dwHighDateTime = 0; + } + if (lpUserTime) { /* Get the time of user mode execution, in 100s of nanoseconds */ - calcTime = (__int64)resUsage.ru_utime.tv_sec * SECS_TO_NS; - calcTime += (__int64)resUsage.ru_utime.tv_usec * USECS_TO_NS; - calcTime /= 100; /* Produce the time in 100s of ns */ + calcTime = (UINT64)resUsage.ru_utime.tv_sec * SECS_TO_100NS; + calcTime += (UINT64)resUsage.ru_utime.tv_usec * USECS_TO_100NS; + /* Assign the time into lpUserTime */ lpUserTime->dwLowDateTime = (DWORD)calcTime; lpUserTime->dwHighDateTime = (DWORD)(calcTime >> 32); @@ -2462,9 +2496,9 @@ GetProcessTimes( if (lpKernelTime) { /* Get the time of kernel mode execution, in 100s of nanoseconds */ - calcTime = (__int64)resUsage.ru_stime.tv_sec * SECS_TO_NS; - calcTime += (__int64)resUsage.ru_stime.tv_usec * USECS_TO_NS; - calcTime /= 100; /* Produce the time in 100s of ns */ + calcTime = (UINT64)resUsage.ru_stime.tv_sec * SECS_TO_100NS; + calcTime += (UINT64)resUsage.ru_stime.tv_usec * USECS_TO_100NS; + /* Assign the time into lpUserTime */ lpKernelTime->dwLowDateTime = (DWORD)calcTime; lpKernelTime->dwHighDateTime = (DWORD)(calcTime >> 32); diff --git a/src/vm/ceeload.cpp b/src/vm/ceeload.cpp index e1f2b2b..eb1dcb9 100644 --- a/src/vm/ceeload.cpp +++ b/src/vm/ceeload.cpp @@ -11654,7 +11654,7 @@ static bool GetBasename(LPCWSTR _src, __out_ecount(dstlen) __out_z LPWSTR _dst, static LPCWSTR s_pCommandLine = NULL; -// Rerieve the full command line for the current process. +// Retrieve the full command line for the current process. LPCWSTR GetManagedCommandLine() { LIMITED_METHOD_CONTRACT; @@ -11725,7 +11725,7 @@ void SaveManagedCommandLine(LPCWSTR pwzAssemblyPath, int argc, LPCWSTR *argv) LPWSTR pCursor = pNewCommandLine; Append_Next_Item(&pCursor, &remainingLen, osCommandLine, true); - Append_Next_Item(&pCursor, &remainingLen, pwzAssemblyPath, true); + Append_Next_Item(&pCursor, &remainingLen, pwzAssemblyPath, (argc > 0)); for (int i = 0; i < argc; i++) { @@ -11768,7 +11768,7 @@ static void ProfileDataAllocateScenarioInfo(ProfileEmitter * pEmitter, LPCSTR sc // Get the managed command line. LPCWSTR pCmdLine = GetManagedCommandLine(); - // If this process started as a service we won't havre a managed command line + // If this process started as a service we won't have a managed command line if (pCmdLine == nullptr) { // Use the result from GetCommandLineW() instead -- 2.7.4