Expose a way to get current timestamp in runtime events - #13785
Conversation
it's useful to be able to access the current timestamp, to be able to correlate timestamps from the event buffer with other time sources such as `mtime` or `ptime`.
85664f6 to
d8a4b2a
Compare
|
Thanks for the ping @gasche . This looks like a good idea to me. My only question is do we want |
dra27
left a comment
There was a problem hiding this comment.
This applied to osdeps.h should fix the Windows build:
diff --git a/runtime/caml/osdeps.h b/runtime/caml/osdeps.h
index 5dd42bbd8b..0f5636481b 100644
--- a/runtime/caml/osdeps.h
+++ b/runtime/caml/osdeps.h
@@ -147,7 +147,7 @@ CAMLextern value caml_win32_get_temp_path(void);
millisecond). This makes it useful for benchmarking and timeouts, but not
for telling the time. The units are always nanoseconds, but the achieved
resolution may be less. The starting point is unspecified. */
-extern uint64_t caml_time_counter(void);
+CAMLextern uint64_t caml_time_counter(void);
extern void caml_init_os_params(void);Co-authored-by: David Allsopp <david.allsopp@metastack.com>
Co-authored-by: David Allsopp <david.allsopp@metastack.com>
Implementation corrected, but approval needed for @sadiqj for the PR overall
I hadn't even registered that the code returned |
| val get_current : unit -> int64 | ||
| (** Access the current timestamp. The timestamp is incremented by one | ||
| every nanosecond, but the starting point is unspecified. | ||
| @since 5.4 *) |
There was a problem hiding this comment.
@c-cube Could you say more about what properties you expect from this time source? If it's POSIX time then this comment is incorrect, since there will be instances where it pauses or jumps based on my understanding of this POSIX document
https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xbd_chap04.html#tag_21_04_15.
The Erlang docs have a good summary of the properties they include for time. For runtime events I expect you'd want monotonically increasing or strictly monotonically increasing, so you can give a happened-before ordering for events.
There was a problem hiding this comment.
Good point, it's a bit weird to have both the base unit be nanoseconds (as internal comments state), and at the same time a clock that can jump forward or stall.
Currently I use mtime, so I'd assume the guarantees are the same — a monotonic clock. If this gets merged I would default to it when it's present (no reconciliation needed) or else fallback on mtime.
There was a problem hiding this comment.
Ha! There can also be differences between monotonic clock, for example you can choose to "count time" where the system is suspended (or not), and some systems offer clocks with varying resolutions.
In general I think that computing the difference between two clocks only once would be okay in practice, but that a robust way to proceed would be to recompute the difference between the two clock sources regularly.
I'm not sure about that either.
I guess now's a good opportunity to decide on whether to keep |
Oops, I missed that the first time round. The unboxed version is already superfluous; either:
At the moment, we have an unboxed primitive whose output is immediately boxed by the compiler! Is there definitely value in being able to access the unboxed value, at least while the timestamps being passed to the callbacks are still boxed? |
|
Does the compiler always box, even if the int64 is used only locally?!
|
|
The compiler always boxes in all situations, but using an I think the PR is fine and works as intended, but changing the |
Heh, heh - another one I can chalk up to "things I thought I understood in the middleend which @lthls corrected" - I didn't realise the inliner could "see" through an abstract definition to the primitive underneath! |
|
Just checking (prior to the triage meeting) is there anything else we're waiting on here before merge? |
|
Nope, let's merge. Thanks! |
|
(We may want to amend the Changes) |
|
Thank you!! 😁 |
…for-13785 I didn't add the reviewers for #13785, apologies.
I have existing tracing libraries that rely on
mtimeto get timestamps, and runtime events don't really suffice to replace them. I'd still like to use runtime events to collect GC spans/GC events, but my problem is that the timestamps are totally opaque and it's not really possible to correlate them withmtime(since the instant I observe an event is not the timestamp at which the event was created). By exposing the timestamp, I can compute the offset (if any) with mtime and use that as a way to translateRuntime_events.Timestamp.tintoMtime.t.