oveRTOS C API
Embedded RTOS framework — build system, configuration, and portable C API
Loading...
Searching...
No Matches
Functions
profiler.h File Reference

Sampling profiler — periodic PC + call-stack capture. More...

#include <stddef.h>
#include <stdint.h>
#include "ove_config.h"
Include dependency graph for profiler.h:

Go to the source code of this file.

Functions

int ove_backend_profiler_start (void)
 Arm the backend sampling mechanism (install signal handler on POSIX, etc.).
 
void ove_backend_profiler_sample_tick (void)
 Drive one sampler tick.
 
void ove_backend_profiler_stop (void)
 Disarm the backend sampling mechanism.
 
void ove_backend_profiler_set_rate (uint32_t hz)
 Set the desired sampling rate in Hz.
 
uint32_t ove_backend_profiler_get_max_hz (void)
 Report the compile-time max sampling rate.
 
size_t ove_backend_profiler_drain_symbols (char *out, size_t out_max)
 Drain newly-interned symbol entries as a JSON array.
 

Detailed Description

Sampling profiler — periodic PC + call-stack capture.

When CONFIG_OVE_PROFILER is enabled, a backend-specific sampler interrupts each RUNNING thread at CONFIG_OVE_PROFILER_HZ and records up to CONFIG_OVE_PROFILER_MAX_DEPTH program counters into a lock-free ring. The sim_profiler plugin drains the ring and forwards samples to the dashboard, which aggregates them into a flat top-N table and a flame graph.

Backends provide:

The ring API (ove_profiler_ring.h) is shared.

Function Documentation

◆ ove_backend_profiler_start()

int ove_backend_profiler_start ( void  )

Arm the backend sampling mechanism (install signal handler on POSIX, etc.).

Idempotent. Does not spawn any thread — the consolidated sim-debug pump drives sampling by calling ove_backend_profiler_sample_tick on its schedule.

Returns
OVE_OK on success, negative ove error code on failure.

◆ ove_backend_profiler_sample_tick()

void ove_backend_profiler_sample_tick ( void  )

Drive one sampler tick.

Called from the sim-debug pump at CONFIG_OVE_PROFILER_HZ. Snapshots runnable threads and delivers the profiling signal to each. No-op if ove_backend_profiler_start has not succeeded.

◆ ove_backend_profiler_stop()

void ove_backend_profiler_stop ( void  )

Disarm the backend sampling mechanism.

Safe to call from any context.

◆ ove_backend_profiler_set_rate()

void ove_backend_profiler_set_rate ( uint32_t  hz)

Set the desired sampling rate in Hz.

The compile-time CONFIG_OVE_PROFILER_HZ is the ceiling; hz is silently clamped into [1, max]. Thread-safe. The dashboard changes rate by sending OVE_SIM_PROFILER_CMD_SET_RATE to the profiler plugin, which then calls this.

Parameters
[in]hzDesired sampling rate in Hz.

◆ ove_backend_profiler_get_max_hz()

uint32_t ove_backend_profiler_get_max_hz ( void  )

Report the compile-time max sampling rate.

Lets the dashboard know the ceiling without parsing Kconfig.

Returns
Maximum supported sampling rate in Hz.

◆ ove_backend_profiler_drain_symbols()

size_t ove_backend_profiler_drain_symbols ( char *  out,
size_t  out_max 
)

Drain newly-interned symbol entries as a JSON array.

Writes a JSON array of [pc_start,pc_end,"name"] triples into out, compatible with the dashboard's existing PROFILE_SUB_SYMBOLS parser.

Used by backends that symbolicate on-target (e.g. WASM uses emscripten_get_callstack and interns names to synthetic pseudo-PCs). POSIX returns 0 because symbolication is done host-side by the bridge via nm on the ELF.

Parameters
[out]outBuffer to receive the JSON fragment.
[in]out_maxSize of out in bytes.
Returns
Bytes written to out (0 if nothing to emit or out_max is too small).