barectf.h.j2: add barectf_discarded_event_records_count()
[barectf.git] / barectf / templates / c / barectf.h.j2
CommitLineData
fdbf8740
PP
1{#
2 # The MIT License (MIT)
3 #
4 # Copyright (c) 2020 Philippe Proulx <pproulx@efficios.com>
5 #
6 # Permission is hereby granted, free of charge, to any person obtaining
7 # a copy of this software and associated documentation files (the
8 # "Software"), to deal in the Software without restriction, including
9 # without limitation the rights to use, copy, modify, merge, publish,
10 # distribute, sublicense, and/or sell copies of the Software, and to
11 # permit persons to whom the Software is furnished to do so, subject to
12 # the following conditions:
13 #
14 # The above copyright notice and this permission notice shall be
15 # included in all copies or substantial portions of the Software.
16 #
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 #}
1b49c7b8 25{% import 'common.j2' as common %}
d6483c83 26{% import 'c/common.j2' as c_common %}
1b49c7b8
PP
27{% set prefix = common.prefix %}
28{% set ucprefix = common.ucprefix %}
29{% set trace_type = cfg.trace.type %}
30{% set cg_opts = cfg.options.code_generation_options %}
e8f0d548 31{% set def_dst = cg_opts.default_data_stream_type %}
1b49c7b8 32{% set header_opts = cg_opts.header_options %}
e18cf9d6 33{% set const_params = false %}
1b49c7b8
PP
34#ifndef _{{ ucprefix }}H
35#define _{{ ucprefix }}H
36
1cf325c4 37{% include 'license-header.j2' %}
e72875eb 38
1b49c7b8
PP
39
40#include <stdint.h>
41
42#ifdef __cplusplus
43extern "C" {
44#endif
45
46{% if header_opts.identifier_prefix_definition %}
3b04a0d6 47/* Backward compatibility */
1b49c7b8 48#define _BARECTF_PREFIX {{ prefix }}
3b04a0d6
PP
49
50#define _BARECTF_IDENTIFIER_PREFIX {{ prefix }}
1b49c7b8 51{% endif %}
e8f0d548 52{% if def_dst and header_opts.default_data_stream_type_name_definition %}
3b04a0d6 53/* Backward compatibility */
e8f0d548 54#define _BARECTF_DEFAULT_STREAM {{ def_dst.name }}
3b04a0d6
PP
55
56#define _BARECTF_DEFAULT_DATA_STREAM_TYPE_NAME {{ def_dst.name }}
1b49c7b8 57{% endif %}
e8f0d548 58{% if def_dst %}
1b49c7b8 59
e8f0d548
PP
60 {% for ert in def_dst.event_record_types | sort %}
61#define {{ prefix }}trace_{{ ert.name }} {{ c_common.trace_func_name(def_dst, ert) }}
d6483c83 62 {% endfor %}
1b49c7b8
PP
63{% endif %}
64
65struct {{ prefix }}ctx;
66
e18cf9d6
PP
67uint32_t {{ prefix }}packet_size(const void *ctx);
68int {{ prefix }}packet_is_full(const void *ctx);
69int {{ prefix }}packet_is_empty(const void *ctx);
70uint32_t {{ prefix }}packet_events_discarded(const void *ctx);
ed4a69c0 71uint32_t {{ prefix }}discarded_event_records_count(const void * const ctx);
e18cf9d6 72uint8_t *{{ prefix }}packet_buf(const void *ctx);
1b49c7b8 73void {{ prefix }}packet_set_buf(void *ctx, uint8_t *buf, uint32_t buf_size);
e18cf9d6
PP
74uint32_t {{ prefix }}packet_buf_size(const void *ctx);
75int {{ prefix }}packet_is_open(const void *ctx);
76int {{ prefix }}is_in_tracing_section(const void *ctx);
77volatile const int *{{ prefix }}is_in_tracing_section_ptr(const void *ctx);
78int {{ prefix }}is_tracing_enabled(const void *ctx);
1b49c7b8
PP
79void {{ prefix }}enable_tracing(void *ctx, int enable);
80
81/* barectf platform callbacks */
82struct {{ prefix }}platform_callbacks {
83{% set clk_types = trace_type.clock_types %}
84{% if clk_types %}
a5435dc8 85 /* Clock source callbacks */
d6483c83 86 {% for clk_type in clk_types | sort %}
1b49c7b8 87 {{ cg_opts.clock_type_c_types[clk_type] }} (*{{ clk_type.name }}_clock_get_value)(void *);
d6483c83 88 {% endfor %}
1b49c7b8
PP
89
90{% endif %}
644b3b4f 91 /* Is the back end full? */
1b49c7b8
PP
92 int (*is_backend_full)(void *);
93
9318c705 94 /* Open packet */
1b49c7b8
PP
95 void (*open_packet)(void *);
96
9318c705 97 /* Close packet */
1b49c7b8
PP
98 void (*close_packet)(void *);
99};
100
9318c705 101/* Common barectf context */
1b49c7b8 102struct {{ prefix }}ctx {
9318c705 103 /* Platform callbacks */
1b49c7b8
PP
104 struct {{ prefix }}platform_callbacks cbs;
105
9318c705 106 /* Platform data (passed to callbacks) */
1b49c7b8
PP
107 void *data;
108
9318c705 109 /* Output buffer (will contain a CTF binary packet) */
1b49c7b8
PP
110 uint8_t *buf;
111
9318c705 112 /* Packet's total size (bits) */
1b49c7b8
PP
113 uint32_t packet_size;
114
9318c705 115 /* Packet's content size (bits) */
1b49c7b8
PP
116 uint32_t content_size;
117
9318c705 118 /* Current position from beginning of packet (bits) */
1b49c7b8
PP
119 uint32_t at;
120
9318c705 121 /* Size of packet header + context fields (content offset) */
1b49c7b8
PP
122 uint32_t off_content;
123
e8f0d548 124 /* Discarded event records counter snapshot */
1b49c7b8
PP
125 uint32_t events_discarded;
126
9318c705 127 /* Current packet is open? */
1b49c7b8
PP
128 int packet_is_open;
129
9318c705 130 /* In tracing code? */
1b49c7b8
PP
131 volatile int in_tracing_section;
132
9318c705 133 /* Tracing is enabled? */
1b49c7b8
PP
134 volatile int is_tracing_enabled;
135
462e49b3 136 /* Use current/last event record timestamp when opening/closing packets */
1b49c7b8
PP
137 int use_cur_last_event_ts;
138};
139
e8f0d548
PP
140{% for dst in trace_type.data_stream_types | sort %}
141/* Context for data stream type `{{ dst.name }}` */
142struct {{ prefix }}{{ dst.name }}_ctx {
9318c705 143 /* Parent */
1b49c7b8
PP
144 struct {{ prefix }}ctx parent;
145
9318c705 146 /* Config-specific members follow */
d6483c83
PP
147 {% if trace_type._pkt_header_ft %}
148 {% for member_name in trace_type._pkt_header_ft.members %}
1c650e47 149 uint32_t off_ph_{{ member_name }};
d6483c83
PP
150 {% endfor %}
151 {% endif %}
e8f0d548 152 {% for member_name in dst._pkt_ctx_ft.members %}
1c650e47 153 uint32_t off_pc_{{ member_name }};
d6483c83 154 {% endfor %}
e8f0d548
PP
155 {% if dst.default_clock_type %}
156 {{ cg_opts.clock_type_c_types[dst.default_clock_type] }} cur_last_event_ts;
d6483c83 157 {% endif %}
1b49c7b8
PP
158};
159
160{% endfor %}
d6483c83 161{% include 'c/ctx-init-func-proto.j2' %};
1b49c7b8 162
e8f0d548 163{% for dst in trace_type.data_stream_types | sort %}
d6483c83 164 {% include 'c/open-func-proto.j2' %};
1b49c7b8 165
d6483c83 166 {% include 'c/close-func-proto.j2' %};
e8f0d548 167 {% for ert in dst.event_record_types | sort %}
1b49c7b8 168
d6483c83
PP
169 {% include 'c/trace-func-proto.j2' %};
170 {% endfor %}
1b49c7b8
PP
171{% endfor %}
172
173#ifdef __cplusplus
174}
175#endif
176
177#endif /* _{{ ucprefix }}H */
This page took 0.032817 seconds and 4 git commands to generate.