1 = Write a barectf platform
4 A **_barectf platform_** is:
6 * Callback functions to xref:api.adoc#cb-open[open] and
7 xref:api.adoc#cb-close[close]
8 xref:how-barectf-works:ctf-primer.adoc#pkt[packets].
10 Those functions allow the platform to control
11 where the xref:how-barectf-works:ctf-primer.adoc#ds[data streams]
12 are stored (called the _back end_) and how full packets are appended to
15 The back end can be anything: files, memory, network, serial, and more.
17 * A callback function to indicate
18 xref:api.adoc#cb-is-back-end-full[whether or not the back end is full].
20 * Data stream xref:how-barectf-works:ctf-primer.adoc#def-clk[default
21 clock] xref:api.adoc#cb-clk-src[source callback functions].
23 * An API for applications to:
24 ** Initialize the platform.
25 ** xref:tracing-funcs:index.adoc#obtain-ctx-ptr[Obtain a barectf context
27 ** Finalize the platform.
29 The purpose of a barectf platform is to decouple the packet storing
30 and clock sourcing operations from
31 the xref:how-barectf-works:ctf-primer.adoc#er[event record] writing
32 operations. xref:tracing-funcs:index.adoc[Tracing functions], which the
33 application calls, handle the latter.
35 See xref:example.adoc[] for a complete barectf platform example.
39 To write a barectf platform:
41 . Write the xref:api.adoc#cbs[platform callback functions].
43 Each function receives some platform context pointer as its first
46 . Write a platform initialization function.
48 This function needs to allocate one or more xref:api.adoc#ctx[barectf
49 contexts], xref:api.adoc#init[initialize them] with the platform
50 callback functions of step{nbsp}1, and store them.
52 This function typically xref:api.adoc#open[opens] the first packet.
54 This function can return a pointer to a platform context structure. This
55 structure can also be global if needed.
57 . Write a platform finalization function.
59 This function can accept a platform context pointer parameter.
61 This function typically starts with this, for each barectf context
66 if (barectf_packet_is_open(barectf_ctx) &&
67 !barectf_packet_is_empty(barectf_ctx)) {
68 /* Close the packet here */
72 where `barectf_ctx` is a pointer to a xref:api.adoc#ctx[barectf
75 This function also needs to deallocate the platform's
76 xref:api.adoc#ctx[barectf contexts].
78 . Write one or more xref:api.adoc#ctx[barectf context] pointer accessor
81 This function can accept a platform context pointer parameter. It
82 returns the requested barectf context pointer.
84 See xref:example.adoc[] for a complete barectf platform example.
86 == YAML configuration file recommendation
88 The barectf project recommends that you create a
89 partial YAML file containing a base xref:yaml:trace-type-obj.adoc[trace
90 type object] for your platform.
92 This platform's base trace type object can be configured so that it
93 matches what your platform expects, for example:
95 * The xref:yaml:trace-type-obj.adoc#native-bo-prop[native byte order]
96 * Specific xref:yaml:clk-type-obj.adoc[clock type objects]
98 * Specific xref:yaml:dst-obj.adoc[Data stream type objects], possibly
100 ** xref:yaml:dst-obj.adoc#def-clk-type-name-prop[Default clock types]
101 ** xref:yaml:dst-obj.adoc#pkt-ctx-ft-extra-members-prop[Extra packet
102 context field type members]
104 An application-specific
105 xref:yaml:index.adoc[YAML configuration files]
106 can then xref:yaml:include.adoc[include] the platform's trace type
107 partial YAML file and augment it.
110 Consider this partial YAML file:
112 .`my-platform-trace-type.yaml`
115 native-byte-order: little-endian
120 origin-is-unix-epoch: false
123 $default-clock-type-name: sys3
124 packet-context-field-type-extra-members:
129 An application-specific YAML configuration file can
130 xref:yaml:include.adoc[include]
131 `my-platform-trace-type.yaml` at the xref:yaml:trace-type-obj.adoc[trace type
136 --- !<tag:barectf.org,2020/3/config>
140 - my-platform-trace-type.yaml
147 element-field-type: uint8
157 - dst_ip_addr: ipv4-addr
163 - src_ip_addr: ipv4-addr