1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
|
= Platform API
:us: _
include::ROOT:partial$def-prefix-note.adoc[]
The public header (usually named `barectf.h`) which barectf
xref:cli:index.adoc[generates] offers an API to write a
barectf platform.
[[ctx]]
== Context structure
For a given xref:yaml:dst-obj.adoc[data stream type] named `__NAME__`:
[source,c]
----
struct barectf_NAME_ctx {
/* ... */
};
----
A barectf platform is responsible for allocating and deallocating such
a structure for each data stream type.
What this structure actually contains is not important; a barectf
platform only needs to store it.
[[cbs]]
== Platform callback functions structure
[source,c]
----
struct barectf_platform_callbacks {
/* Clock source callback functions here */
/*
* Returns whether or not the back end is full.
*/
int (*is_backend_full)(void *user_data);
/*
* Opens the current packet.
*/
void (*open_packet)(void *user_data);
/*
* Closes the current packet.
*/
void (*close_packet)(void *user_data);
};
----
Each callback function receives as its `user_data` parameter what you
passed to the <<init,barectf context initialization function>> as the
`user_data` parameter.
[[cb-clk-src]]
=== Clock source
For each xref:yaml:clk-type-obj.adoc[clock type object] `__NAME__`
within the trace type's
xref:yaml:trace-type-obj.adoc#clk-types-prop[`clock-types` property],
the platform callback functions structure contains one clock source
callback function:
[source,c]
----
CTYPE (*NAME_clock_get_value)(void *user_data);
----
`__CTYPE__` is the clock type object's
xref:yaml:clk-type-obj.adoc#c-type-prop[`$c-type` property] (`uint32_t`
by default).
A clock source function returns the clock's current value. The clock
value must be monotonic.
[[cb-open]]
=== Packet opening
[source,c]
----
void (*open_packet)(void *user_data);
----
This function must call the <<open,packet opening function>>.
[[cb-close]]
=== Packet closing
[source,c]
----
void (*close_packet)(void *user_data);
----
This function must:
. Call the <<close,packet closing function>>.
. Copy or move the current packet to the back end.
After step{nbsp}2, this function _can_ set a new packet buffer with
<<barectf-packet-set-buf-func,`+barectf_packet_set_buf()+`>>. If it
doesn't, the next calls to the <<open,packet opening function>> and
xref:tracing-funcs:index.adoc[tracing functions] will write to the
current packet buffer.
[[cb-is-back-end-full]]
=== Is the back end full?
[source,c]
----
int (*is_backend_full)(void *user_data);
----
This function returns whether or not the back end is full.
In other words, if a new packet is <<cb-open,opened>> now, does this
packet have its reserved space in the back end?
[[accessors]]
== Context property accessors
* [[barectf-pkt-buf-addr-func]]{empty}
+
[source,c]
----
uint8_t *barectf_packet_buf_addr(const void *vctx);
----
+
Returns the packet buffer address of the barectf context `vctx`.
* {empty}
+
[source,c]
----
uint32_t barectf_packet_buf_size(const void *vctx);
----
+
Returns the packet buffer size (bytes) of the barectf context `vctx`.
* {empty}
+
[source,c]
----
int barectf_packet_is_full(const void *vctx);
----
+
Returns whether or not the packet of the barectf context `vctx` is full.
* {empty}
+
[source,c]
----
int barectf_packet_is_empty(const void *vctx);
----
+
Returns whether or not the packet of the barectf context `vctx` is empty.
* {empty}
+
[source,c]
----
int barectf_packet_is_open(const void *vctx);
----
+
Returns whether or not the packet of the barectf context `vctx` is
open.
* [[barectf-packet-set-buf-func]]{empty}
+
[source,c]
----
void barectf_packet_set_buf(void *vctx, uint8_t *addr, uint32_t size);
----
+
Sets the packet buffer of the barectf context `vctx` to the address `addr`
and the size `size` bytes.
+
You can only call this function from the <<cb-close,packet closing
callback function>>.
* [[barectf-disc-er-count-func]]{empty}
+
[source,c]
----
uint32_t barectf_discarded_event_records_count(const void *vctx);
----
+
Returns the number of
xref:how-barectf-works:ctf-primer.adoc#disc-er-counter[discarded event
records] in the barectf context `vctx`.
* [[barectf-pkt-seq-num-func]]{empty}
+
[source,c]
----
uint32_t barectf_packet_sequence_number(const void *vctx);
----
+
Returns the packet sequence number in the barectf context `vctx`.
* {empty}
+
[source,c]
----
int barectf_is_in_tracing_section(const void *vctx);
----
+
Returns whether or not there's a current
xref:tracing-funcs:index.adoc[tracing function] call for the barectf
context `vctx`.
* {empty}
+
[source,c]
----
volatile const int *barectf_is_in_tracing_section_ptr(const void *vctx);
----
+
Returns a pointer to an `int` variable which indicates whether or not
there's a current xref:tracing-funcs:index.adoc[tracing function] call
for the barectf context `vctx`.
[[init]]
== Context initialization
Initializes the <<ctx,barectf context>> `vctx` with the initial packet
buffer located at the address `buf_addr` and having `buf_size` bytes,
the <<cbs,platform callback functions>> `cbs`, and the
user data `data`.
[source,c]
----
void barectf_init(void *vctx, uint8_t *buf_addr, uint32_t buf_size,
struct barectf_platform_callbacks cbs, void *user_data);
----
`user_data` is what the platform callback functions receive as
their first parameter.
[[open]]
== Packet opening
For a given xref:yaml:dst-obj.adoc[data stream type] named `__NAME__`, a
packet opening function opens the current
xref:how-barectf-works:ctf-primer.adoc#pkt[packet] of a
<<ctx,barectf context>> `sctx`:
[source,c]
----
void barectf_NAME_open_packet(struct barectf_NAME_ctx *sctx);
----
[[open-params]]
=== Parameters
For each member `__MNAME__` of the data stream type object's
xref:yaml:dst-obj.adoc#pkt-ctx-ft-extra-members-prop[`packet-context-field-type-extra-members`
property], this function has an additional parameter named
`pc{us}__MNAME__`.
See xref:yaml:ft-obj.adoc#gen-c-types[Generated C{nbsp}types] to
determine the exact C{nbsp}type of each parameter.
Note that a member with a xref:yaml:dyn-array-ft-obj.adoc[dynamic array
field type] actually makes barectf generate _two_ adjacent parameters:
. One for the dynamic array's length.
+
Example: `uint32_t pc___my_array_len`
. One for the dynamic array's data.
+
Example: `const uint8_t *pc_my_array`
=== Role
A packet opening function:
. Writes initial
xref:how-barectf-works:ctf-primer.adoc#pkt[packet header and context]
fields.
+
The source of some of those fields can be <<open-params,parameters>>.
. Saves the offsets of some packet context fields to write them at
<<close,packet closing>> time.
. Marks the current packet as being open.
In general, a <<cb-open,packet opening platform callback function>> and
a platform initialization function (for the first packet) call this
function.
[[close]]
== Packet closing
For a given xref:yaml:dst-obj.adoc[data stream type] named `__NAME__`, a
packet closing function closes the current
xref:how-barectf-works:ctf-primer.adoc#pkt[packet] of a
<<ctx,barectf context>> `sctx`:
[source,c]
----
void barectf_NAME_close_packet(struct barectf_NAME_ctx *sctx);
----
=== Role
A packet closing function:
. Marks the current packet as being closed.
. Writes some xref:how-barectf-works:ctf-primer.adoc#pkt[packet context]
fields.
. If the
xref:yaml:dst-obj.adoc#seq-num-ft-prop[`sequence-number-field-type`
packet feature] of the corresponding data stream type is enabled:
increments the packet sequence number of `sctx`.
In general, a <<cb-close,packet closing platform callback function>> and
a platform finalization function (for the last packet) call this
function.
|