chromium/third_party/blink/renderer/build/scripts/templates/instrumenting_probes_inl.h.tmpl

// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

{% from 'macros.tmpl' import source_files_for_generated_file %}
{{source_files_for_generated_file(template_file, input_files)}}

#ifndef {{header_guard}}
#define {{header_guard}}

#include "third_party/blink/renderer/platform/heap/collection_support/heap_vector.h"
{% for include in config["settings"]["includes"] %}
#include "{{include}}"
{% endfor %}

{% set export_symbol = config["settings"]["export_symbol"] %}
{% set sink_class = (name | to_singular) + "Sink" %}

namespace blink {

{% for forward_decl in file.forward_declarations %}
{{forward_decl}}
{% endfor %}

namespace probe {
{% for probe in file.declarations %}

{%- macro params_decl(probe) %}
{%- for param in probe.params %}
{%- if probe.is_scoped and param.is_reference %}
std::reference_wrapper<std::remove_reference_t<{{param.type}}>>
{%- else %}
{{ param.type }}
{%- endif %}
{%- if param.default_value %} = {{ param.default_value }}
{%- endif %}
{%- if not loop.last %}, {% endif %}
{%- endfor %}
{%- endmacro -%}

{%- macro params_list(probe) %}
{%- for param in probe.params %}
{{param.type}} {{param.name}}
{%- if not loop.last %}, {% endif -%}
{%- endfor -%}
{%- endmacro %}

{% if probe.is_scoped %}

class {{export_symbol}} {{probe.name}} : public ProbeBase {
  STACK_ALLOCATED();

 public:
  explicit {{probe.name}}({{ params_decl(probe) }});
  ~{{probe.name}}();
  {{sink_class}}* probe_sink = nullptr;
{% for param in probe.params %}
  {{param.type}} {{param.name}};
{% endfor %}
};

{%- else %}

{{export_symbol}} void {{probe.name}}Impl({{ params_decl(probe) }});
inline void {{probe.name}}({{params_list(probe)}}) {
  if (!{{sink_class}}::HasAgentsGlobal(
    {%- for agent in probe.agents|sort %}
    {% if not loop.first %} | {% endif -%}
    {{sink_class}}::k{{agent}}
    {%- endfor %}))
    return;

  {{probe.name}}Impl(
    {%- for param in probe.params %}
      {% if not loop.first %}, {% endif %}{{param.name}}
    {%- endfor %});
}

{%- endif %}
{%- endfor %}


} // namespace probe
} // namespace blink

#endif // {{header_guard}}