Skip to main content

Core concepts

There are two central objects in the event ring C API. They are:
  1. struct monad_event_ring - represents an event ring whose shared memory segments have been mapped into the address space of the current process; the primary thing the client does with this object is use it to initialize iterators that point into the event ring, using the monad_event_ring_init_iterator function
  2. struct monad_event_iterator - the star of the show: this iterator object is used to read sequential events. The iterator’s try_next operation copies the current event descriptor (if it is available) and if successful, advances the iterator. Conceptually, it behaves like the expression descriptor = *i++, if an event descriptor is ready immediately (it does nothing otherwise)
The easiest way to understand the API is to compile and run the included eventwatch example program. This program dumps ASCII representations of execution events to stdout, as they are written by a execution daemon running on the same host. In eventwatch, the event descriptors are fully decoded, but the event payloads are only shown in hexdump form, because this simple program that does not include pretty-printing logic for all event payload types. The program is only 250 lines of code, and reading through it should explain how the various API calls fit together. The SDK also includes C++20 std::formatter specializations which can fully decode event payloads into human-readable form. These are used by the monad-event-cli utility program.

Using the API in your project

libmonad_event is designed for third party integration, so it does not have any library dependencies aside from a recent version of glibc. This also means it has no dependency on the rest of the monad repository or on its build system: the sole requirement is a C compiler supporting C23. The “Getting start” guide to building the C example program discusses several ways to use the SDK library as a third-party dependency in your code. Alternatively, the source files that make up the library target can be copied into your own codebase. A Rust client library is also available.

API overview

Event ring APIs

All functions which can fail will return an errno(3) domain error code diagnosing the reason for failure. The function monad_event_ring_get_last_error can be called to provide a human-readable string explanation of what failed.

Event iterator APIs

Event ring utility APIs

Library organization

Event ring files in libmonad_event: Execution event files in libmonad_event: Supporting files in libmonad_event: Other files in the SDK:

Footnotes

  1. By default, this returns the a path on a hugetlbfs mount, as computed by libhugetlbfs
  2. If compiling with MONAD_EVENT_USE_LIBHUGETLBFS=OFF, a default event ring directory must be specified; see here for details