blob: c4f96a503ee294d50613abd74682b683b46a950e (
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
102
103
|
# -*- coding: utf-8 -*-
# Copyright 2020 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Templates for generating event 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/enums.h"
#include "components/metrics/structured/event_base.h"
namespace metrics {{
namespace structured {{
namespace events {{
{project_code}
}} // 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::EventBase {{
public:
{event.name}();
~{event.name}() override;
static constexpr uint64_t kEventNameHash = UINT64_C({event.name_hash});
static constexpr uint64_t kProjectNameHash = UINT64_C({project.name_hash});
static constexpr IdType kIdType = IdType::{project.id_type};
static constexpr IdScope kIdScope = IdScope::{project.id_scope};
static constexpr StructuredEventProto_EventType kEventType =
StructuredEventProto_EventType_{project.event_type};
{metric_code}\
}};
"""
HEADER_METRIC_TEMPLATE = """\
static constexpr uint64_t k{metric.name}NameHash = UINT64_C({metric.hash});
{event.name}& Set{metric.name}(const {metric.type} value);
"""
IMPL_FILE_TEMPLATE = """\
// Generated from gen_events.py. DO NOT EDIT!
// source: structured.xml
// #include "{file.dirname}/structured_events.h"
#include "components/metrics/structured/structured_events.h"
namespace metrics {{
namespace structured {{
namespace events {{
{project_code}
}} // 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::EventBase(kEventNameHash, kProjectNameHash,
kIdType, kIdScope, kEventType) {{}}
{event.name}::~{event.name}() = default;
{metric_code}\
"""
IMPL_METRIC_TEMPLATE = """\
{event.name}& {event.name}::Set{metric.name}(const {metric.type} value) {{
{metric.setter}(k{metric.name}NameHash, value);
return *this;
}}
"""
|