docs: cleanup: Rephrase and correct typos
[barectf.git] / docs / modules / platform / pages / index.adoc
CommitLineData
016a4d97
PP
1= Write a barectf platform
2:us: _
3
4A **_barectf platform_** is:
5
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].
9+
10Those functions allow the platform to control
11where the xref:how-barectf-works:ctf-primer.adoc#ds[data streams]
12are stored (called the _back end_) and how full packets are appended to
13them.
14+
15The back end can be anything: files, memory, network, serial, and more.
16
17* A callback function to indicate
18 xref:api.adoc#cb-is-back-end-full[whether or not the back end is full].
19
20* Data stream xref:how-barectf-works:ctf-primer.adoc#def-clk[default
21 clock] xref:api.adoc#cb-clk-src[source callback functions].
22
23* An API for applications to:
24** Initialize the platform.
25** xref:tracing-funcs:index.adoc#obtain-ctx-ptr[Obtain a barectf context
26 pointer].
27** Finalize the platform.
28
29The purpose of a barectf platform is to decouple the packet storing
30and clock sourcing operations from
31the xref:how-barectf-works:ctf-primer.adoc#er[event record] writing
32operations. xref:tracing-funcs:index.adoc[Tracing functions], which the
33application calls, handle the latter.
34
35See xref:example.adoc[] for a complete barectf platform example.
36
37== Steps
38
39To write a barectf platform:
40
41. Write the xref:api.adoc#cbs[platform callback functions].
42+
43Each function receives some platform context pointer as its first
44parameter.
45
46. Write a platform initialization function.
47+
48This function needs to allocate one or more xref:api.adoc#ctx[barectf
49contexts], xref:api.adoc#init[initialize them] with the platform
50callback functions of step{nbsp}1, and store them.
51+
52This function typically xref:api.adoc#open[opens] the first packet.
53+
54This function can return a pointer to a platform context structure. This
55structure can also be global if needed.
56
57. Write a platform finalization function.
58+
59This function can accept a platform context pointer parameter.
60+
61This function typically starts with this, for each barectf context
62of the platform:
63+
64[source,c]
65----
66if (barectf_packet_is_open(barectf_ctx) &&
67 !barectf_packet_is_empty(barectf_ctx)) {
68 /* Close the packet here */
69}
70----
71+
72where `barectf_ctx` is a pointer to a xref:api.adoc#ctx[barectf
73context].
74+
75This function also needs to deallocate the platform's
76xref:api.adoc#ctx[barectf contexts].
77
78. Write one or more xref:api.adoc#ctx[barectf context] pointer accessor
79 functions.
80+
81This function can accept a platform context pointer parameter. It
82returns the requested barectf context pointer.
83
84See xref:example.adoc[] for a complete barectf platform example.
85
fdacbf1f 86== YAML configuration file recommendation
016a4d97
PP
87
88The barectf project recommends that you create a
89partial YAML file containing a base xref:yaml:trace-type-obj.adoc[trace
fdacbf1f 90type object] for your platform.
016a4d97
PP
91
92This platform's base trace type object can be configured so that it
93matches what your platform expects, for example:
94
c24e3f21 95* The xref:yaml:trace-type-obj.adoc#native-bo-prop[native byte order]
016a4d97
PP
96* Specific xref:yaml:clk-type-obj.adoc[clock type objects]
97
98* Specific xref:yaml:dst-obj.adoc[Data stream type objects], possibly
99 with:
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]
103
104An application-specific
105xref:yaml:index.adoc[YAML configuration files]
106can then xref:yaml:include.adoc[include] the platform's trace type
107partial YAML file and augment it.
108
109====
110Consider this partial YAML file:
111
112.`my-platform-trace-type.yaml`
113[source,yaml]
114----
115native-byte-order: little-endian
116clock-types:
117 sys3:
118 frequency: 8000000
119 precision: 80
120 origin-is-unix-epoch: false
121data-stream-types:
122 main:
123 $default-clock-type-name: sys3
124 packet-context-field-type-extra-members:
125 - load: int8
126 - node_id: uint16
127----
128
129An application-specific YAML configuration file can
130xref:yaml:include.adoc[include]
131`my-platform-trace-type.yaml` at the xref:yaml:trace-type-obj.adoc[trace type
132object] level:
133
134[source,yaml]
135----
136--- !<tag:barectf.org,2020/3/config>
137trace:
138 type:
139 $include:
140 - my-platform-trace-type.yaml
141 - stdint.yaml
142 - stdmisc.yaml
143 $field-type-aliases:
144 ipv4-addr:
145 class: static-array
146 length: 4
147 element-field-type: uint8
148 data-stream-types:
149 main:
150 $is-default: true
151 event-record-types:
152 on_send:
153 payload-field-type:
154 class: structure
155 members:
156 - msg: string
157 - dst_ip_addr: ipv4-addr
158 on_recv:
159 payload-field-type:
160 class: structure
161 members:
162 - msg: string
163 - src_ip_addr: ipv4-addr
164----
165====
This page took 0.028 seconds and 4 git commands to generate.