This repository was archived by the owner on Jun 21, 2024. It is now read-only.
Ring buffer-based runtime tracing (eventring)#793
Closed
sadiqj wants to merge 46 commits intoocaml-multicore:5.00from
Closed
Ring buffer-based runtime tracing (eventring)#793sadiqj wants to merge 46 commits intoocaml-multicore:5.00from
sadiqj wants to merge 46 commits intoocaml-multicore:5.00from
Conversation
…ingbuffer simpler. Add more documentation and a test for the OCAML_EVENTRING_START environment variable.
Collaborator
Author
|
Closing this for now, in preparation for a rebase and a PR on ocaml/ocaml. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Summary
Eventring is a low-overhead runtime tracing system designed for continuous monitoring of OCaml applications. It utilises per-domain memory-mapped ring buffers that enable consumption of tracing events both in and out of process. It replaces the existing eventlog system already present in runtime.
This PR
This is a draft PR as this eventring work has been built atop of the multicore 5.00 tree. The intention here is to gather feedback on the design and implementation and then propose a rebased-PR on ocaml/ocaml once the MVP has been merged.
Ring buffer
The ring buffer is structured as a flight recorder, overwriting old data when is insufficient space to write new events. This enables users to potentially only read the ring when some anomalous event occurs or a performance target is missed. No coordination is needed with consumers who read the events and then discard events where a race with the producer is detected.
Probes
Most of the existing instrumented runtime eventlog probes are moved in to the normal runtime. Only the most frequently hit probes on very hot paths (like allocation and marking) were left in the instrumented runtime. The probes themselves are very lightweight, having almost no cost (~2ns) when eventlog has not been started or is paused. When active, a span probes takes around ~50ns to emit the begin and end events together. A benchmark to reproduce these numbers is here. Most of this cost is actually getting the current timestamp and it's possible there's some options we could add to reduce that cost for certain use cases.
API
In terms of API, there is a an OCaml API where users can create a cursor for a particular set of eventrings (the current process or an external one), register callbacks for certain types of events and then poll with the cursor.
There is also a C API which mirrors the OCaml API and enables very low impact consumption of events for those use cases that require it.
Future
This implementation is designed to be open for extension to user tracing events in the future, as well as integration with statmemprof (e.g continuous allocation profiling).
Examples
Emitting minor and major slice GC pause times to stdout
Here's a simple consumer that prints the times of minor and major slices. It omits any support for multiple domains, error handling or lost events:
When compiled and run with this PR's branch you will get an output like:
Code such as the above could be spawned in a separate domain and send metrics data to an external service (such as graphite or prometheus) over a socket.
Chrome tracing
This is a simplified example of how Eventring can be used to log out runtime data in a format that can be simply ingested by Chrome's trace viewer. Running the above project with
OCAML_EVENTRING_START=1 _build/default/src/traceevents_lib.exeand then loading the resultant json file in to Chrome's tracing viewer will give something like the following:Tests
The tests/eventring directory contains some other exampel of using the different APIs.
PR structure
The producer
The producer code is contained here . By default an .eventring file is created in the current directory (overridable by setting OCAML_EVENTRING_PREFIX). This file contains a ring buffer for each possible domain (
Max_domains). It is laid out in a structure that enables sparsity - on-disk (or in-memory) footprint is proportional to the max number of concurrent domains the process has ever run.The consumer internals
Consumer code is contained in eventring_consumer.c. This contains both the implementations for the OCaml API and C API (the former being a thin layer over the latter).
APIs
The OCaml API is available in Eventring.mli, the C API is available in eventring.h.