Skip to content

Commit dd814e2

Browse files
authored
Merge pull request dotnet#24339 from briansull/linux-creation-time
Fix the PAL implemention of GetProcessTimes to write the creation time
2 parents 299c9d5 + e7815dd commit dd814e2

File tree

2 files changed

+47
-13
lines changed

2 files changed

+47
-13
lines changed

src/pal/src/thread/process.cpp

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2413,10 +2413,10 @@ GetProcessTimes(
24132413
{
24142414
BOOL retval = FALSE;
24152415
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
24202420

24212421
PERF_ENTRY(GetProcessTimes);
24222422
ENTRY("GetProcessTimes(hProcess=%p, lpExitTime=%p, lpKernelTime=%p,"
@@ -2448,12 +2448,46 @@ GetProcessTimes(
24482448
resUsage.ru_utime.tv_sec, resUsage.ru_utime.tv_usec,
24492449
resUsage.ru_stime.tv_sec, resUsage.ru_stime.tv_usec);
24502450

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+
24512485
if (lpUserTime)
24522486
{
24532487
/* 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+
24572491
/* Assign the time into lpUserTime */
24582492
lpUserTime->dwLowDateTime = (DWORD)calcTime;
24592493
lpUserTime->dwHighDateTime = (DWORD)(calcTime >> 32);
@@ -2462,9 +2496,9 @@ GetProcessTimes(
24622496
if (lpKernelTime)
24632497
{
24642498
/* 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+
24682502
/* Assign the time into lpUserTime */
24692503
lpKernelTime->dwLowDateTime = (DWORD)calcTime;
24702504
lpKernelTime->dwHighDateTime = (DWORD)(calcTime >> 32);

src/vm/ceeload.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11654,7 +11654,7 @@ static bool GetBasename(LPCWSTR _src, __out_ecount(dstlen) __out_z LPWSTR _dst,
1165411654

1165511655
static LPCWSTR s_pCommandLine = NULL;
1165611656

11657-
// Rerieve the full command line for the current process.
11657+
// Retrieve the full command line for the current process.
1165811658
LPCWSTR GetManagedCommandLine()
1165911659
{
1166011660
LIMITED_METHOD_CONTRACT;
@@ -11725,7 +11725,7 @@ void SaveManagedCommandLine(LPCWSTR pwzAssemblyPath, int argc, LPCWSTR *argv)
1172511725
LPWSTR pCursor = pNewCommandLine;
1172611726

1172711727
Append_Next_Item(&pCursor, &remainingLen, osCommandLine, true);
11728-
Append_Next_Item(&pCursor, &remainingLen, pwzAssemblyPath, true);
11728+
Append_Next_Item(&pCursor, &remainingLen, pwzAssemblyPath, (argc > 0));
1172911729

1173011730
for (int i = 0; i < argc; i++)
1173111731
{
@@ -11768,7 +11768,7 @@ static void ProfileDataAllocateScenarioInfo(ProfileEmitter * pEmitter, LPCSTR sc
1176811768
// Get the managed command line.
1176911769
LPCWSTR pCmdLine = GetManagedCommandLine();
1177011770

11771-
// If this process started as a service we won't havre a managed command line
11771+
// If this process started as a service we won't have a managed command line
1177211772
if (pCmdLine == nullptr)
1177311773
{
1177411774
// Use the result from GetCommandLineW() instead

0 commit comments

Comments
 (0)