Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Use deterministic Process.StartTime for OS X #39434#39572

Merged
stephentoub merged 8 commits intodotnet:masterfrom
watfordgnf:issue-39434-macosx-process-starttime
Aug 6, 2019
Merged

Use deterministic Process.StartTime for OS X #39434#39572
stephentoub merged 8 commits intodotnet:masterfrom
watfordgnf:issue-39434-macosx-process-starttime

Conversation

@watfordgnf
Copy link
Contributor

This fixes #39434 by using a deterministic value for Process.StartTime from the pbi_start_* values returned by GetProcessInfoById on Mac OS X.

@danmoseley
Copy link
Member

Thanks. Whatever the right fix is, we should add a test that simply gets the start time several times for a process (eg., the tests process) to check it doesn't change. I assume that test would periodically fail with the current implementation.

@watfordgnf watfordgnf force-pushed the issue-39434-macosx-process-starttime branch from 53d523e to 9e3b1c4 Compare July 17, 2019 18:09
@danmoseley danmoseley requested review from krwq and wtgodbe July 17, 2019 18:15
@danmoseley danmoseley added this to the Future milestone Jul 17, 2019
Copy link
Member

@wtgodbe wtgodbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@watfordgnf watfordgnf marked this pull request as ready for review July 17, 2019 21:12
@danmoseley
Copy link
Member

Any more feedback @stephentoub

{
throw new Win32Exception(SR.RUsageFailure);
}
DateTime startTime = DateTime.UnixEpoch + TimeSpan.FromSeconds(info.Value.pbsd.pbi_start_tvsec + info.Value.pbsd.pbi_start_tvusec / MicrosecondsToSecondsFactor);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the division include a cast to double, e.g. pbsd.pbi_start_tvusec / (double)MicrosecondsToSecondsFactor?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related, have you done any manual testing of this to validate the results? It looks like our automated testing allows for a lot of wiggleroom on accuracy, around 6 seconds worth.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For point (1) the factor is already a double. For point (2), I've reached out in the original issue for manual testing beyond CI.

I'll remove the wiggle room and see what shakes out.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the factor is already a double

So it is. It's a bit strange that the two factors next to each other have different types.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disabling the wiggle room apparently fails on multiple platforms (other than OS X).

@watfordgnf watfordgnf force-pushed the issue-39434-macosx-process-starttime branch 3 times, most recently from bd4b6d3 to 2cea534 Compare July 19, 2019 13:00
@danmoseley
Copy link
Member

@stephentoub does this address your feedback? If so this can merge.

@stephentoub stephentoub merged commit b368697 into dotnet:master Aug 6, 2019
@krwq
Copy link
Member

krwq commented Aug 6, 2019

@stephentoub I think this has broken the build. We're getting:

##[error]System/Diagnostics/Process.OSX.cs(111,27): error CA1823: Unused field 'NanoSecondToSecondFactor'.

in #40063

@krwq krwq mentioned this pull request Aug 6, 2019
@krwq
Copy link
Member

krwq commented Aug 6, 2019

I've created #40080

@karelz karelz removed this from the Future milestone Aug 9, 2019
@karelz karelz added this to the 5.0 milestone Aug 9, 2019
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
…net/corefx#39572)

* Use pbi_start for StartTime on OS X fixes dotnet/corefx#39434

* Add test to ensure StartTime remains stable

* Reduce delay in test based on feedback

- Use the correct Assert.Equal too.

* Ensure StartTime is in Local Time

* Remove unnecessary test and reenable other test for OS X

* Remove unused OS X interop methods

- SystemNative_GetAbsoluteTime
- SystemNative_GetTimebaseInfo

* Remove cmake entries for unused HAVE_MACH_TIMEBASE_INFO

* Address review comment regarding constants


Commit migrated from dotnet/corefx@b368697
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Process.StartTime on macOS returns different values

6 participants