summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBrian Sullivan <briansul@microsoft.com>2019-05-02 18:07:46 -0700
committerGitHub <noreply@github.com>2019-05-02 18:07:46 -0700
commitdd814e26e2206c36589f88b2c58a6f3695f7dc4e (patch)
tree229b623ff3f18278f5f037525df5c451ee070b4d /src
parent299c9d5733368d101882eb89d897c88f094997c1 (diff)
parente7815dde1e3847841b260e700704da8f7b4f7a30 (diff)
downloadcoreclr-dd814e26e2206c36589f88b2c58a6f3695f7dc4e.tar.gz
coreclr-dd814e26e2206c36589f88b2c58a6f3695f7dc4e.tar.bz2
coreclr-dd814e26e2206c36589f88b2c58a6f3695f7dc4e.zip
Merge pull request #24339 from briansull/linux-creation-time
Fix the PAL implemention of GetProcessTimes to write the creation time
Diffstat (limited to 'src')
-rw-r--r--src/pal/src/thread/process.cpp54
-rw-r--r--src/vm/ceeload.cpp6
2 files changed, 47 insertions, 13 deletions
diff --git a/src/pal/src/thread/process.cpp b/src/pal/src/thread/process.cpp
index 74ec02ff18..445b75cc68 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 e1f2b2bfec..eb1dcb9eb3 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