Perf event buffer support for BPF event streaming
Perf event buffer support for BPF event streaming
(create-perf-consumer
&
{:keys [map callback deserializer buffer-pages cpu-count]
:or {deserializer identity buffer-pages 64 cpu-count (utils/get-cpu-count)}})Create a perf event consumer for BPF event streaming.
Parameters:
Returns PerfEventConsumer record.
Example: (create-perf-consumer {:map perf-map :callback (fn [event] (println "Event:" event)) :deserializer parse-my-event :buffer-pages 64})
Create a perf event consumer for BPF event streaming.
Parameters:
- map: Perf event array map
- callback: Function to call for each event (receives deserialized event)
- deserializer: Function to deserialize event bytes (default identity)
- buffer-pages: Number of pages per buffer (default 64, must be power of 2)
- cpu-count: Number of CPUs (default: all CPUs)
Returns PerfEventConsumer record.
Example:
(create-perf-consumer
{:map perf-map
:callback (fn [event] (println "Event:" event))
:deserializer parse-my-event
:buffer-pages 64})(create-perf-event-array max-entries
&
{:keys [map-name] :or {map-name "perf_event_array"}})Create a perf event array map for collecting BPF events.
A perf event array map is used to send events from BPF programs to userspace via perf event buffers.
Parameters:
Returns a BPF map.
Example: (create-perf-event-array (get-cpu-count) :map-name "events")
Create a perf event array map for collecting BPF events. A perf event array map is used to send events from BPF programs to userspace via perf event buffers. Parameters: - max-entries: Maximum number of entries (typically number of CPUs) - map-name: Optional map name Returns a BPF map. Example: (create-perf-event-array (get-cpu-count) :map-name "events")
(get-perf-stats consumer)Get statistics from perf event consumer.
Returns a map with:
Example: (get-perf-stats consumer)
Get statistics from perf event consumer. Returns a map with: - :events-read - Total events read from buffers - :events-processed - Total events successfully processed - :polls - Number of polling cycles - :errors - Number of errors - :uptime-ms - Consumer uptime in milliseconds - :events-per-second - Average events processed per second Example: (get-perf-stats consumer)
(perf-event-open attr pid cpu group-fd flags)Open a perf event file descriptor.
Parameters:
Returns the perf event file descriptor.
Example: (perf-event-open {:type :software :config :bpf-output} -1 0 -1 0)
Open a perf event file descriptor.
Parameters:
- attr: Perf event attribute map (see perf-event-attr->bytes)
- pid: Process ID (-1 for all processes)
- cpu: CPU number (-1 for all CPUs)
- group-fd: Group leader FD (-1 for no group)
- flags: Additional flags (default 0)
Returns the perf event file descriptor.
Example:
(perf-event-open {:type :software :config :bpf-output} -1 0 -1 0)(read-perf-events perf-buf)(read-perf-events perf-buf max-events)Read available events from perf buffer.
Returns a vector of event maps, each containing:
Parameters:
Example: (read-perf-events perf-buf 64)
Read available events from perf buffer. Returns a vector of event maps, each containing: - :type - Event record type - :size - Record size - :data - Raw event data (byte array) Parameters: - perf-buf: PerfBuffer record - max-events: Maximum number of events to read (default 128) Example: (read-perf-events perf-buf 64)
(start-perf-consumer consumer)(start-perf-consumer consumer poll-interval-ms)Start consuming events from perf buffers in a background thread.
Parameters:
Returns updated consumer with thread reference.
Example: (start-perf-consumer consumer 50)
Start consuming events from perf buffers in a background thread. Parameters: - consumer: PerfEventConsumer record - poll-interval-ms: Polling interval in milliseconds (default 100) Returns updated consumer with thread reference. Example: (start-perf-consumer consumer 50)
(stop-perf-consumer consumer)Stop the perf event consumer thread.
Parameters:
Example: (stop-perf-consumer consumer)
Stop the perf event consumer thread. Parameters: - consumer: PerfEventConsumer record Example: (stop-perf-consumer consumer)
(with-perf-consumer [binding config-expr] & body)Create and manage a perf event consumer with automatic cleanup.
Example: (with-perf-consumer [consumer {:map perf-map :callback println}] (start-perf-consumer consumer) (Thread/sleep 5000))
Create and manage a perf event consumer with automatic cleanup.
Example:
(with-perf-consumer [consumer {:map perf-map :callback println}]
(start-perf-consumer consumer)
(Thread/sleep 5000))cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |