Peform table-based translation of runtime event names and tags #44
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR implements translation of runtime event names (and tags) using tables loaded at runtime, in order to allow consumption of runtime events from different versions of OCaml. It also adds a new command
olly{,_bare} gen-tables
to generate the table file from thecaml/runtime_events.h
C header file.Currently, when Olly profiles a program compiled with a newer (or older) version of OCaml than Olly was compiled for, two bugs may occur:
olly trace
generates nonsensical names for the slices1olly gc-stats
silently generates garbage output, if any of the runtime events it matches on have changedThis occurs because runtime events are read from a
mmap
ped ring buffer using C with absolutely zero regard for the version of the OCaml runtime it was produced with (and there is no way to check in the first place), and the integers written to the ring buffer are directly interpreted as elements of the enumerations inruntime_events.ml
. Since runtime events may have been inserted in arbitrary positions in the enum (e.g. ocaml/ocaml#12923), the integer values written into the ring buffer may differ from those that our version should interpret them as, leading to completely wrongRuntime_events.(
lifecycle
,runtime_phase
, andruntime_counter
)
values.Here is an annotated image of how the issue manifests and is fixed using Olly built on
5.1.0
currently (on the left) and performing name translation (on the right):Olly Perfetto Mistranslated Names Demo
ring_pause
(seen on the left) isn't even aruntime_phase
event name, but alifecycle
event name! Something has gone terribly wrong...The implementation is in two parts:
Firstly, I implement a library
olly_rte_shim
to unify all the different types of runtime events (runtime_phase
,runtime_counter
,lifecycle
,alloc
, and custom events) into a single manageableevent
type.Event.t
type forolly trace
to abstract the name/argument extraction of events from the trace format backendsEvent.t
type, which now also maintains the "tag" of the event (rather than just forgetting it for the name) – i.e. the kind ofruntime_phase
,runtime_counter
, custom event, etc. it is.olly
Secondly, I implement table-based translation of event names and tags
olly gen-tables
which creates a YAML2 or OCaml file, the former which can be read at runtime, and the latter which is linked into Olly to generate the builtin table of events existing in this version--table
(no short form [yet?]) option to botholly gc-stats
andolly trace
to load a source table from a fileObj.magic
) to index the tablesObj.magic
) to the corresponding event tag enumerationsFootnotes
and could, I believe, possibly crash, under bad circumstances, though I haven't seen it happen ↩
it's just three lines of
kind: [event_name,...]
, (and can only be parsed from that subset), having it be valid YAML means other tools can potentially use it, e.g. for diffing as json ↩