summaryrefslogtreecommitdiff
path: root/chromium/tools/metrics/structured/templates_events.py
blob: 75a2c4b1a0058e696021f8942b0c36201e74b323 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# -*- coding: utf-8 -*-
# Copyright 2021 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Templates for generating event builder classes for structured metrics."""

HEADER_FILE_TEMPLATE = """
// Generated from gen_events.py. DO NOT EDIT!
// source: structured.xml

#ifndef {file.guard_path}
#define {file.guard_path}

#include <cstdint>
#include <string>

#include "components/metrics/structured/event.h"

namespace metrics {{
namespace structured {{
namespace events {{
namespace v2 {{

{project_code}

}}  // namespace v2
}}  // namespace events
}}  // namespace structured
}}  // namespace metrics

#endif  // {file.guard_path}\
"""

HEADER_PROJECT_TEMPLATE = """\
namespace {project.namespace} {{

{event_code}\
}}  // namespace {project.namespace}

"""

HEADER_EVENT_TEMPLATE = """\
class {event.name} final : public ::metrics::structured::Event {{
 public:
  {event.name}();
  ~{event.name}() override;

  {metric_code}\
}};

"""

HEADER_METRIC_TEMPLATE = """\
  {event.name}& Set{metric.name}(const {metric.type} value);
"""

IMPL_FILE_TEMPLATE = """\
// Generated from gen_events.py. DO NOT EDIT!
// source: structured.xml

#include "components/metrics/structured/structured_events.h"

#include "base/strings/string_number_conversions.h"
#include "base/values.h"

namespace metrics {{
namespace structured {{
namespace events {{
namespace v2 {{

{project_code}
}}  // namespace v2
}}  // namespace events
}}  // namespace structured
}}  // namespace metrics\
"""

IMPL_PROJECT_TEMPLATE = """\
namespace {project.namespace} {{

{event_code}\
}}  // namespace {project.namespace}

"""

IMPL_EVENT_TEMPLATE = """\
{event.name}::{event.name}() :
  ::metrics::structured::Event(\"{event.project_name}\",
                               \"{event.name}\") {{}}
{event.name}::~{event.name}() = default;
{metric_code}\
"""

IMPL_METRIC_TEMPLATE = """\
{event.name}& {event.name}::Set{metric.name}(const {metric.type} value) {{
  AddMetric(\"{metric.name}\", Event::MetricType::{metric.type_enum},
            {metric.base_value});
  return *this;
}}

"""