From: Philippe Proulx Date: Thu, 3 Sep 2020 15:48:48 +0000 (-0400) Subject: barectf.c.j2: do not pass useless parameters to _ev_size_*() functions X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=b622b24f5f229369a2645ec12006b829b50c062d;p=deliverable%2Fbarectf.git barectf.c.j2: do not pass useless parameters to _ev_size_*() functions This patch changes _CodeGen._proto_params_str() in `gen.py` to accept a `only_dyn` parameter. When `only_dyn` is `True`, then the function only generates function prototype parameter strings for field types which have a dynamic size (string field types, as of this version). This patch also changes the ft_call_params() macro to add an `only_dyn` parameter which serves the same purpose. The purpose of this is not calling the _ev_size_*() functions with parameters which correspond to statically-sized field types. Signed-off-by: Philippe Proulx --- diff --git a/barectf/cgen.py b/barectf/cgen.py index e566313..ebc85e1 100644 --- a/barectf/cgen.py +++ b/barectf/cgen.py @@ -419,7 +419,8 @@ class _CodeGen: # Each parameter has the prefix `name_prefix` followed with `_`. # # Members of which the name is in `exclude_set` are excluded. - def _proto_params_str(self, root_ft, name_prefix, const_params, exclude_set=None): + def _proto_params_str(self, root_ft, name_prefix, const_params, exclude_set=None, + only_dyn=False): if root_ft is None: return @@ -432,6 +433,9 @@ class _CodeGen: if member_name in exclude_set: continue + if only_dyn and not member.field_type.size_is_dynamic: + continue + params.append(_FtParam(member.field_type, member_name)) return self._func_proto_params_templ.render(params=params, prefix=name_prefix, @@ -457,26 +461,29 @@ class _CodeGen: # Returns the tracing function prototype parameters for the stream # and event types `stream_ev_types`. - def _trace_func_params_str(self, stream_ev_types, const_params): + def _trace_func_params_str(self, stream_ev_types, const_params, only_dyn=False): stream_type = stream_ev_types[0] ev_type = stream_ev_types[1] parts = [] if stream_type._ev_header_ft is not None: parts.append(self._proto_params_str(stream_type._ev_header_ft, _RootFtPrefixes.EH, - const_params, {'id', 'timestamp'})) + const_params, {'id', 'timestamp'}, + only_dyn=only_dyn)) if stream_type.event_common_context_field_type is not None: parts.append(self._proto_params_str(stream_type.event_common_context_field_type, - _RootFtPrefixes.ECC, const_params)) + _RootFtPrefixes.ECC, const_params, + only_dyn=only_dyn)) if ev_type.specific_context_field_type is not None: parts.append(self._proto_params_str(ev_type.specific_context_field_type, - _RootFtPrefixes.SC, const_params)) + _RootFtPrefixes.SC, const_params, + only_dyn=only_dyn)) if ev_type.payload_field_type is not None: parts.append(self._proto_params_str(ev_type.payload_field_type, _RootFtPrefixes.P, - const_params)) + const_params, only_dyn=only_dyn)) return ''.join(parts) diff --git a/barectf/templates/c/barectf.c-macros.j2 b/barectf/templates/c/barectf.c-macros.j2 index 4ed0add..4af1956 100644 --- a/barectf/templates/c/barectf.c-macros.j2 +++ b/barectf/templates/c/barectf.c-macros.j2 @@ -55,10 +55,12 @@ const int saved_in_tracing_section = ctx->in_tracing_section; # # , ecc_peer_id, ecc_addr, p_msg_id, p_msg #} -{% macro ft_call_params(param_prefix, ft) %} +{% macro ft_call_params(param_prefix, ft, only_dyn=false) %} {% if ft %} - {% for member_name in ft.members %} + {% for member_name, member in ft.members.items() %} + {% if not only_dyn or member.field_type.size_is_dynamic %} , {{ param_prefix }}_{{ member_name }} - {%- endfor %} + {%- endif %} + {% endfor %} {% endif %} {% endmacro %} diff --git a/barectf/templates/c/barectf.c.j2 b/barectf/templates/c/barectf.c.j2 index 258dd7c..c5655f3 100644 --- a/barectf/templates/c/barectf.c.j2 +++ b/barectf/templates/c/barectf.c.j2 @@ -456,7 +456,7 @@ static void _serialize_ev_{{ stream_type.name }}_{{ ev_type.name }}(void * const {% for ev_type in stream_type.event_types | sort %} {% set this_ev_ops = this_stream_ops.ev_ops[ev_type] %} -static uint32_t _ev_size_{{ stream_type.name }}_{{ ev_type.name }}(void * const vctx{{ (stream_type, ev_type) | trace_func_params_str(const_params) }}) +static uint32_t _ev_size_{{ stream_type.name }}_{{ ev_type.name }}(void * const vctx{{ (stream_type, ev_type) | trace_func_params_str(const_params, only_dyn=true) }}) { struct {{ ctx_struct_name }} * const ctx = _FROM_VOID_PTR(struct {{ ctx_struct_name }}, vctx); uint32_t at = ctx->at; @@ -527,9 +527,9 @@ static uint32_t _ev_size_{{ stream_type.name }}_{{ ev_type.name }}(void * const ctx->in_tracing_section = 1; /* Compute event size */ - {% set ev_common_ctx_params = macros.ft_call_params(root_ft_prefixes.ECC, stream_type.event_common_context_field_type) %} - {% set spec_ctx_params = macros.ft_call_params(root_ft_prefixes.SC, ev_type.specific_context_field_type) %} - {% set payload_params = macros.ft_call_params(root_ft_prefixes.P, ev_type.payload_field_type) %} + {% set ev_common_ctx_params = macros.ft_call_params(root_ft_prefixes.ECC, stream_type.event_common_context_field_type, true) %} + {% set spec_ctx_params = macros.ft_call_params(root_ft_prefixes.SC, ev_type.specific_context_field_type, true) %} + {% set payload_params = macros.ft_call_params(root_ft_prefixes.P, ev_type.payload_field_type, true) %} {% set params %}{{ ev_common_ctx_params }}{{ spec_ctx_params }}{{ payload_params }}{% endset %} ev_size = _ev_size_{{ stream_type.name }}_{{ ev_type.name }}(_TO_VOID_PTR(ctx){{ params }}); @@ -541,6 +541,10 @@ static uint32_t _ev_size_{{ stream_type.name }}_{{ ev_type.name }}(void * const } /* Serialize event */ + {% set ev_common_ctx_params = macros.ft_call_params(root_ft_prefixes.ECC, stream_type.event_common_context_field_type) %} + {% set spec_ctx_params = macros.ft_call_params(root_ft_prefixes.SC, ev_type.specific_context_field_type) %} + {% set payload_params = macros.ft_call_params(root_ft_prefixes.P, ev_type.payload_field_type) %} + {% set params %}{{ ev_common_ctx_params }}{{ spec_ctx_params }}{{ payload_params }}{% endset %} _serialize_ev_{{ stream_type.name }}_{{ ev_type.name }}(_TO_VOID_PTR(ctx){{ params }}); /* Commit event */