2 # The MIT License (MIT)
4 # Copyright (c) 2020 Philippe Proulx <pproulx@efficios.com>
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:
14 # The above copyright notice and this permission notice shall be
15 # included in all copies or substantial portions of the Software.
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.
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
37 {% include 'license-header.j2' %}
46 {% if header_opts.identifier_prefix_definition %}
47 /* Backward compatibility */
48 #define _BARECTF_PREFIX {{ prefix }}
50 #define _BARECTF_IDENTIFIER_PREFIX {{ prefix }}
52 {% if def_dst and header_opts.default_data_stream_type_name_definition %}
53 /* Backward compatibility */
54 #define _BARECTF_DEFAULT_STREAM {{ def_dst.name }}
56 #define _BARECTF_DEFAULT_DATA_STREAM_TYPE_NAME {{ def_dst.name }}
60 {% for ert in def_dst.event_record_types | sort %}
61 #define {{ prefix }}trace_{{ ert.name }} {{ c_common.trace_func_name(def_dst, ert) }}
65 struct {{ prefix }}ctx;
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);
81 /* barectf platform callbacks */
82 struct {{ prefix }}platform_callbacks {
83 {% set clk_types = trace_type.clock_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 *);
91 /* Is the back end full? */
92 int (*is_backend_full)(void *);
95 void (*open_packet)(void *);
98 void (*close_packet)(void *);
101 /* Common barectf context */
102 struct {{ prefix }}ctx {
103 /* Platform callbacks */
104 struct {{ prefix }}platform_callbacks cbs;
106 /* Platform data (passed to callbacks) */
109 /* Output buffer (will contain a CTF binary packet) */
112 /* Packet's total size (bits) */
113 uint32_t packet_size;
115 /* Packet's content size (bits) */
116 uint32_t content_size;
118 /* Current position from beginning of packet (bits) */
121 /* Size of packet header + context fields (content offset) */
122 uint32_t off_content;
124 /* Discarded event records counter snapshot */
125 uint32_t events_discarded;
127 /* Current packet is open? */
130 /* In tracing code? */
131 volatile int in_tracing_section;
133 /* Tracing is enabled? */
134 volatile int is_tracing_enabled;
136 /* Use current/last event record timestamp when opening/closing packets */
137 int use_cur_last_event_ts;
140 {% for dst in trace_type.data_stream_types | sort %}
141 /* Context for data stream type `{{ dst.name }}` */
142 struct {{ prefix }}{{ dst.name }}_ctx {
144 struct {{ prefix }}ctx parent;
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 }};
152 {% for member_name in dst._pkt_ctx_ft.members %}
153 uint32_t off_pc_{{ member_name }};
155 {% if dst.default_clock_type %}
156 {{ cg_opts.clock_type_c_types[dst.default_clock_type] }} cur_last_event_ts;
161 {% include 'c/ctx-init-func-proto.j2' %};
163 {% for dst in trace_type.data_stream_types | sort %}
164 {% include 'c/open-func-proto.j2' %};
166 {% include 'c/close-func-proto.j2' %};
167 {% for ert in dst.event_record_types | sort %}
169 {% include 'c/trace-func-proto.j2' %};
177 #endif /* _{{ ucprefix }}H */