-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor get_time_stamp_ns #34536
Refactor get_time_stamp_ns #34536
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea of moving this, though I think I'd prefer to just move that whole batch of time functions instead of the one.
Also, if we're moving this into utils there should be an equivalent Windows implementation. It's not needed in mini-posix.c
given the name, but headers in utils are more general.
In some places, Maybe introduce different functions that will give different times? e.g. |
src/mono/mono/utils/mono-time.c
Outdated
@@ -229,3 +233,48 @@ mono_100ns_datetime_from_timeval (struct timeval tv) | |||
|
|||
#endif | |||
|
|||
#ifdef HOST_DARWIN | |||
|
|||
static clock_serv_t sampling_clock_service; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This used to be initialized in clock_init()
under mono-posix.c
, but it's now always 0
.
src/mono/mono/utils/mono-time.c
Outdated
|
||
#elif defined(HOST_LINUX) | ||
|
||
static clockid_t sampling_posix_clock; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same: the POSIX version of clock_init()
would initialize this, but it's now always zero. The POSIX version, also, will initialize this variable considering a MonoProfilerSampleMode
, so this patch will break profiling.
…ferent clock ID types for different os, and move back profiler specific function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good initial work! I have some structural concerns, particularly surrounding the use of void *
here.
src/mono/mono/utils/mono-time.c
Outdated
@@ -229,3 +235,84 @@ mono_100ns_datetime_from_timeval (struct timeval tv) | |||
|
|||
#endif | |||
|
|||
#if defined(HOST_DARWIN) || defined(HOST_LINUX) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to have distinct sections for Windows, Darwin, and Linux, given they do not seem to share any code.
src/mono/mono/utils/mono-time.h
Outdated
@@ -29,6 +29,10 @@ gint64 mono_100ns_datetime (void); | |||
gint64 mono_100ns_datetime_from_timeval (struct timeval tv); | |||
#endif | |||
|
|||
void mono_clock_init (void *clk_id); | |||
void mono_clock_cleanup (void *clk_id); | |||
guint64 mono_clock_get_time_ns (void *clk_id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm extremely uncomfortable casting everything to void *
when the argument is quite different on different platforms. We should use a platform-specific typedef or something instead.
The reason why I use |
I think a platform-specific typedef is a much better approach, since then you still benefit from type checking and avoid a lot of potential casting mistakes. It also would let you clean up the calling code a bit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a quick style nit, but looks good overall. Thanks!
Co-Authored-By: Ryan Lucia <[email protected]>
fixes #34074