barectf.h.j2: add barectf_discarded_event_records_count()
[barectf.git] / barectf / templates / c / barectf.h.j2
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 #}
25 {% import 'common.j2' as common %}
26 {% import 'c/common.j2' as c_common %}
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 %}
31 {% set def_dst = cg_opts.default_data_stream_type %}
32 {% set header_opts = cg_opts.header_options %}
33 {% set const_params = false %}
34 #ifndef _{{ ucprefix }}H
35 #define _{{ ucprefix }}H
36
37 {% include 'license-header.j2' %}
38
39
40 #include <stdint.h>
41
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45
46 {% if header_opts.identifier_prefix_definition %}
47 /* Backward compatibility */
48 #define _BARECTF_PREFIX {{ prefix }}
49
50 #define _BARECTF_IDENTIFIER_PREFIX {{ prefix }}
51 {% endif %}
52 {% if def_dst and header_opts.default_data_stream_type_name_definition %}
53 /* Backward compatibility */
54 #define _BARECTF_DEFAULT_STREAM {{ def_dst.name }}
55
56 #define _BARECTF_DEFAULT_DATA_STREAM_TYPE_NAME {{ def_dst.name }}
57 {% endif %}
58 {% if def_dst %}
59
60 {% for ert in def_dst.event_record_types | sort %}
61 #define {{ prefix }}trace_{{ ert.name }} {{ c_common.trace_func_name(def_dst, ert) }}
62 {% endfor %}
63 {% endif %}
64
65 struct {{ prefix }}ctx;
66
67 uint32_t {{ prefix }}packet_size(const void *ctx);
68 int {{ prefix }}packet_is_full(const void *ctx);
69 int {{ prefix }}packet_is_empty(const void *ctx);
70 uint32_t {{ prefix }}packet_events_discarded(const void *ctx);
71 uint32_t {{ prefix }}discarded_event_records_count(const void * const ctx);
72 uint8_t *{{ prefix }}packet_buf(const void *ctx);
73 void {{ prefix }}packet_set_buf(void *ctx, uint8_t *buf, uint32_t buf_size);
74 uint32_t {{ prefix }}packet_buf_size(const void *ctx);
75 int {{ prefix }}packet_is_open(const void *ctx);
76 int {{ prefix }}is_in_tracing_section(const void *ctx);
77 volatile const int *{{ prefix }}is_in_tracing_section_ptr(const void *ctx);
78 int {{ prefix }}is_tracing_enabled(const void *ctx);
79 void {{ prefix }}enable_tracing(void *ctx, int enable);
80
81 /* barectf platform callbacks */
82 struct {{ prefix }}platform_callbacks {
83 {% set clk_types = trace_type.clock_types %}
84 {% if clk_types %}
85 /* Clock source callbacks */
86 {% for clk_type in clk_types | sort %}
87 {{ cg_opts.clock_type_c_types[clk_type] }} (*{{ clk_type.name }}_clock_get_value)(void *);
88 {% endfor %}
89
90 {% endif %}
91 /* Is the back end full? */
92 int (*is_backend_full)(void *);
93
94 /* Open packet */
95 void (*open_packet)(void *);
96
97 /* Close packet */
98 void (*close_packet)(void *);
99 };
100
101 /* Common barectf context */
102 struct {{ prefix }}ctx {
103 /* Platform callbacks */
104 struct {{ prefix }}platform_callbacks cbs;
105
106 /* Platform data (passed to callbacks) */
107 void *data;
108
109 /* Output buffer (will contain a CTF binary packet) */
110 uint8_t *buf;
111
112 /* Packet's total size (bits) */
113 uint32_t packet_size;
114
115 /* Packet's content size (bits) */
116 uint32_t content_size;
117
118 /* Current position from beginning of packet (bits) */
119 uint32_t at;
120
121 /* Size of packet header + context fields (content offset) */
122 uint32_t off_content;
123
124 /* Discarded event records counter snapshot */
125 uint32_t events_discarded;
126
127 /* Current packet is open? */
128 int packet_is_open;
129
130 /* In tracing code? */
131 volatile int in_tracing_section;
132
133 /* Tracing is enabled? */
134 volatile int is_tracing_enabled;
135
136 /* Use current/last event record timestamp when opening/closing packets */
137 int use_cur_last_event_ts;
138 };
139
140 {% for dst in trace_type.data_stream_types | sort %}
141 /* Context for data stream type `{{ dst.name }}` */
142 struct {{ prefix }}{{ dst.name }}_ctx {
143 /* Parent */
144 struct {{ prefix }}ctx parent;
145
146 /* Config-specific members follow */
147 {% if trace_type._pkt_header_ft %}
148 {% for member_name in trace_type._pkt_header_ft.members %}
149 uint32_t off_ph_{{ member_name }};
150 {% endfor %}
151 {% endif %}
152 {% for member_name in dst._pkt_ctx_ft.members %}
153 uint32_t off_pc_{{ member_name }};
154 {% endfor %}
155 {% if dst.default_clock_type %}
156 {{ cg_opts.clock_type_c_types[dst.default_clock_type] }} cur_last_event_ts;
157 {% endif %}
158 };
159
160 {% endfor %}
161 {% include 'c/ctx-init-func-proto.j2' %};
162
163 {% for dst in trace_type.data_stream_types | sort %}
164 {% include 'c/open-func-proto.j2' %};
165
166 {% include 'c/close-func-proto.j2' %};
167 {% for ert in dst.event_record_types | sort %}
168
169 {% include 'c/trace-func-proto.j2' %};
170 {% endfor %}
171 {% endfor %}
172
173 #ifdef __cplusplus
174 }
175 #endif
176
177 #endif /* _{{ ucprefix }}H */
This page took 0.03468 seconds and 4 git commands to generate.