YAC 3.21.0
Yet Another Coupler
Loading...
Searching...
No Matches
yac_pak_instrument.c
Go to the documentation of this file.
1// Copyright (c) 2026 The YAC Authors
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5/*
6 * YAC PAK: bridge from YAC core instrumentation interface to YAC PAK trace
7 * events.
8 */
9
10#include "yac_pak_instrument.h"
11#include "instrument.h"
12#include "yac_pak.h"
13#include "utils_common.h"
14
15/* State of single active tracing window. Only one window can be active
16 * in the process at a time, because core instrumentation callbacks are
17 * process-global (see yac_instrument_set_callbacks). */
18static struct yac_pak * window_pak = NULL;
20static char const * window_component = NULL;
21static char const * window_grid = NULL;
22static int window_active = 0;
23
24/* Pending YAC PAK event handle per instrumentation nesting depth. Core
25 * guarantees strict LIFO nesting and that a given region id is open at most
26 * once, so at most YAC_INSTR_REGION_COUNT regions can be open simultaneously
27 * and the depth never exceeds this bound. */
29
31 int id, void * region_handle, int depth, void * user_data) {
32
33 UNUSED(region_handle);
35
37 depth >= 0 && depth < YAC_INSTR_REGION_COUNT,
38 "instrumentation region depth %d out of range", depth)
39
40 window_handles[depth] =
45 -1, NULL, -1, window_level);
46}
47
49 int id, void * region_handle, int depth, void * user_data) {
50
51 UNUSED(id);
52 UNUSED(region_handle);
54
56 depth >= 0 && depth < YAC_INSTR_REGION_COUNT,
57 "instrumentation region depth %d out of range", depth)
58
60 window_handles[depth] = -1;
61}
62
64 struct yac_pak * pak, yac_pak_trace_level_t level,
65 char const * component, char const * grid) {
66
67 window_active = 0;
68
69 if (!yac_pak_region_trace_is_enabled(pak, level)) return;
70
71 window_pak = pak;
72 window_level = level;
73 window_component = component;
74 window_grid = grid;
75 for (int i = 0; i < YAC_INSTR_REGION_COUNT; ++i) window_handles[i] = -1;
76
79
80 window_active = 1;
81}
82
84
85 if (!window_active) return;
86
88
89 window_active = 0;
90 window_pak = NULL;
91 window_component = NULL;
92 window_grid = NULL;
93}
#define UNUSED(x)
Definition core.h:72
int yac_pak_region_trace_is_enabled(struct yac_pak const *pak, yac_pak_trace_level_t level)
Check whether region events at a given trace level will be recorded.
Definition yac_pak.c:913
yac_pak_trace_level_t
YAC PAK coupling trace level.
Definition yac_pak.h:71
int yac_pak_trace_stop(struct yac_pak *pak, int handle)
Stop a trace event.
Definition yac_pak.c:1055
int yac_pak_trace_start_ex(struct yac_pak *pak, char const *field, char const *component, char const *grid, yac_pak_event_type_t type, int put_idx, char const *datetime, int action, yac_pak_trace_level_t level)
Start a trace event with full metadata.
Definition yac_pak.c:1017
@ YAC_PAK_EVENT_TYPE_REGION
Definition yac_pak.h:57
@ YAC_PAK_TRACE_LEVEL_OFF
no coupling events
Definition yac_pak.h:72
void yac_instrument_set_callbacks(yac_instrument_create_cb create_cb, yac_instrument_start_cb start_cb, yac_instrument_stop_cb stop_cb, yac_instrument_destroy_cb destroy_cb, void *user_data)
Definition instrument.c:97
void yac_instrument_clear_callbacks(void)
Definition instrument.c:149
const char * yac_instrument_region_name(yac_instrument_region_id id)
Definition instrument.c:154
yac_instrument_region_id
Definition instrument.h:53
@ YAC_INSTR_REGION_COUNT
Definition instrument.h:57
void * user_data
#define YAC_ASSERT_F(exp, format,...)
Definition yac_assert.h:39
static struct yac_pak * window_pak
void yac_pak_instrument_end(void)
End the window opened by yac_pak_instrument_begin (clears the callbacks). Safe to call unconditionall...
static void pak_instrument_start_cb(int id, void *region_handle, int depth, void *user_data)
static char const * window_component
static int window_active
static void pak_instrument_stop_cb(int id, void *region_handle, int depth, void *user_data)
static int window_handles[YAC_INSTR_REGION_COUNT]
static char const * window_grid
void yac_pak_instrument_begin(struct yac_pak *pak, yac_pak_trace_level_t level, char const *component, char const *grid)
Begin a tracing window: record instrumented core regions until the matching yac_pak_instrument_end as...
static yac_pak_trace_level_t window_level
Bridge that turns YAC core instrumentation regions (see instrument.h) into nested YAC_PAK_EVENT_TYPE_...