File: getting-started.adoc

package info (click to toggle)
barectf 3.1.2-4
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 3,840 kB
  • sloc: python: 3,781; ansic: 1,585; makefile: 45; sh: 11
file content (282 lines) | stat: -rw-r--r-- 7,992 bytes parent folder | download | duplicates (3)
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
= Getting started

This introductory guide makes you create a very simple barectf YAML
configuration, generate a tracer out of it, and then use it.

You need Linux for this user guide.

The steps are:

. <<yaml,Write the YAML configuration file>>.
. <<cli,Generate the files with the `barectf` CLI tool>>.
. <<app,Write the application source file>>.
. <<build,Download the Linux FS platform source files and
  build the application>>.
. <<trace,Execute the application>> to produce
  xref:how-barectf-works:ctf-primer.adoc#ds[CTF data streams].
. <<read,Read the resulting CTF trace>>.

IMPORTANT: Make sure that barectf xref:install.adoc[is installed] before
you follow this guide.

[[yaml]]
== Write the YAML configuration file

. Create an empty directory and `cd` into it, for example:
+
[.cl]
[verse]
[.prompt]##$## cd $(mktemp --directory)

. Write the following xref:yaml:index.adoc[YAML configuration file]:
+
[[config.yaml]]
.`config.yaml`
[source,yaml]
----
# Needed YAML tag for the configuration object
--- !<tag:barectf.org,2020/3/config>

# Configuration's trace
trace:
  # Type of the trace
  type:
    # Add standard field type aliases
    $include:
      - stdint.yaml
      - stdmisc.yaml

    # Native byte order is little-endian
    native-byte-order: little-endian

    # One clock type
    clock-types:
      # The Linux FS platform requires a clock type named `default`
      # which has a 1-GHz frequency and the `uint64_t` C type.
      default:
        frequency: 1000000000
        $c-type: uint64_t

    # One data stream type
    data-stream-types:
      # Stream type named `default`
      default:
        # Default data stream type
        $is-default: true

        # Default clock type: `default`
        $default-clock-type-name: default

        # Two event record types
        event-record-types:
          # Event record type named `one_integer`
          one_integer:
            payload-field-type:
              class: structure
              members:
                # One payload member: a 32-bit signed integer field type
                # (`int32_t` C type)
                - the_integer: int32

          # Event record type named `one_string`
          one_string:
            payload-field-type:
              class: structure
              members:
                # One payload member: a string field type
                # (`const char *` C type)
                - the_string: string
----
+
barectf will <<cli,generate>> two
xref:tracing-funcs:index.adoc[tracing functions] named
`+barectf_trace_one_integer()+` and `+barectf_trace_one_string()+` from
this configuration.

[[cli]]
== Generate the files with the `barectf` CLI tool

. Create a directory which will contain the CTF trace:
+
--
[.cl]
[verse]
[.prompt]##$## mkdir trace
--
+
A CTF trace always contains a file named `metadata` and one or more data
stream files. barectf always generates the `metadata` file while the
user application writes the data stream files through the generated
tracer.

. Generate the CTF metadata stream and C{nbsp}source files with the
  xref:cli:index.adoc[`barectf` CLI tool]:
+
[.cl]
[verse]
--
[.prompt]##$## barectf generate --metadata-dir=trace config.yaml
--
+
`barectf generate` creates:
+
[%autowidth.stretch, cols="d,a"]
|===
|File name |Description

|`trace/metadata`
|The CTF metadata stream file.

It's in the `trace` directory because we used the
xref:cli:usage.adoc#generate-metadata-dir-option[`+--metadata-dir+`]
option.

|`barectf.h`
|The generated tracer's public C{nbsp}header file.

|`barectf-bitfield.h`
|Internal macros for the generated tracer (included by `barectf.c`).

|`barectf.c`
|The generated tracer's C{nbsp}source code.
|===

[[app]]
== Write the application source file

Write a simple application which uses the generated tracer:

.`app.c`
[source,c]
----
/* Include the Linux FS platform header */
#include "barectf-platform-linux-fs.h"

/* Include the barectf public header */
#include "barectf.h"

int main(const int argc, const char * const argv[])
{
    /* Platform context */
    struct barectf_platform_linux_fs_ctx *platform_ctx;

    /* barectf context */
    struct barectf_default_ctx *ctx;

    int i;

    /*
     * Obtain a platform context.
     *
     * The platform is configured to write 512-byte packets to a data
     * stream file within the `trace` directory.
     */
    platform_ctx = barectf_platform_linux_fs_init(512, "trace/stream",
                                                  0, 0, 0);

    /* Obtain the barectf context from the platform context */
    ctx = barectf_platform_linux_fs_get_barectf_ctx(platform_ctx);

    /*
     * Write a `one_integer` event record which contains the number of
     * command arguments.
     */
    barectf_trace_one_integer(ctx, argc);

    /* For each command argument */
    for (i = 0; i < argc; ++i) {
        /*
         * Write a `one_integer` event record which contains the
         * argument's index.
         */
        barectf_trace_one_integer(ctx, i);

        /*
         * Write a `one_string` event record which contains the
         * argument.
         */
        barectf_trace_one_string(ctx, argv[i]);
    }

    /* Finalize (free) the platform context */
    barectf_platform_linux_fs_fini(platform_ctx);

    return 0;
}
----

This application calls the `+barectf_trace_one_integer()+` and
`+barectf_trace_one_string()+` functions which correspond to the
`one_integer` and `one_string` event record types in
<<config.yaml,`config.yaml`>>.

[[build]]
== Download platform source files and build the application

To build the final application, you need the Linux FS platform source
files.

The Linux FS platform only exists to demonstrate barectf; a barectf user
almost always xref:platform:index.adoc[writes its own platform] because
of the bare-metal/embedded nature of the target systems.

. Download the Linux FS platform source files:
+
[.cl]
[verse]
[.prompt]##$## wget https://raw.githubusercontent.com/efficios/barectf/stable-{page-component-version}/platforms/linux-fs/barectf-platform-linux-fs.h
[.prompt]##$## wget https://raw.githubusercontent.com/efficios/barectf/stable-{page-component-version}/platforms/linux-fs/barectf-platform-linux-fs.c

. Build the application:
+
[.cl]
[verse]
[.prompt]##$## gcc -o app app.c barectf.c barectf-platform-linux-fs.c

[[trace]]
== Execute the application

Run the <<build,built>> application, passing a few command-line
arguments:

[.cl]
[verse]
[.prompt]##$## ./app lorem ipsum nulla dolore consequat

This writes the xref:how-barectf-works:ctf-primer.adoc#ds[CTF data
stream] file `trace/stream`.

The `trace` directory is now a complete
xref:how-barectf-works:ctf-primer.adoc#trace[CTF trace].

[[read]]
== Read the CTF trace

Use https://babeltrace.org/[Babeltrace{nbsp}2] to read the resulting
CTF trace:

[.cl]
[verse]
[.prompt]##$## babeltrace2 trace

----
[15:52:24.202028327] (+?.?????????) one_integer: { the_integer = 6 }
[15:52:24.202029477] (+0.000001150) one_integer: { the_integer = 0 }
[15:52:24.202029988] (+0.000000511) one_string: { the_string = "./app" }
[15:52:24.202033362] (+0.000003374) one_integer: { the_integer = 1 }
[15:52:24.202033716] (+0.000000354) one_string: { the_string = "lorem" }
[15:52:24.202034147] (+0.000000431) one_integer: { the_integer = 2 }
[15:52:24.202034465] (+0.000000318) one_string: { the_string = "ipsum" }
[15:52:24.202034812] (+0.000000347) one_integer: { the_integer = 3 }
[15:52:24.202035147] (+0.000000335) one_string: { the_string = "nulla" }
[15:52:24.202035527] (+0.000000380) one_integer: { the_integer = 4 }
[15:52:24.202035848] (+0.000000321) one_string: { the_string = "dolore" }
[15:52:24.202036175] (+0.000000327) one_integer: { the_integer = 5 }
[15:52:24.202036553] (+0.000000378) one_string: { the_string = "consequat" }
----

You can also open the trace with
https://www.eclipse.org/tracecompass/[Trace{nbsp}Compass]:

.Trace Compass 5.3.0's event list view
image::getting-started-trace-compass.png[]