forked from Pissandshittium/pissandshittium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththread_profiler_configuration.h
137 lines (106 loc) · 5.22 KB
/
thread_profiler_configuration.h
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// Copyright 2015 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.
#ifndef CHROME_COMMON_PROFILER_THREAD_PROFILER_CONFIGURATION_H_
#define CHROME_COMMON_PROFILER_THREAD_PROFILER_CONFIGURATION_H_
#include <initializer_list>
#include <string>
#include "base/no_destructor.h"
#include "base/profiler/stack_sampling_profiler.h"
#include "components/metrics/call_stack_profile_params.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "third_party/abseil-cpp/absl/types/variant.h"
namespace base {
class CommandLine;
} // namespace base
class ThreadProfilerPlatformConfiguration;
// ThreadProfilerConfiguration chooses a configuration for the enable state of
// the stack sampling profiler across all processes. This configuration is
// determined once at browser process startup. Configurations for child
// processes are communicated via command line arguments.
class ThreadProfilerConfiguration {
public:
// Returns the ThreadProfilerConfiguration for the process.
static ThreadProfilerConfiguration* Get();
~ThreadProfilerConfiguration() = delete;
ThreadProfilerConfiguration(const ThreadProfilerConfiguration&) = delete;
ThreadProfilerConfiguration& operator=(const ThreadProfilerConfiguration&) =
delete;
// Get the stack sampling params to use.
base::StackSamplingProfiler::SamplingParams GetSamplingParams() const;
// True if the profiler is enabled for any thread in the current process.
bool IsProfilerEnabledForCurrentProcess() const;
// True if the profiler should be started for |thread| in the current process.
bool IsProfilerEnabledForCurrentProcessAndThread(
metrics::CallStackProfileParams::Thread thread) const;
// Get the synthetic field trial configuration. Returns true if a synthetic
// field trial should be registered. This should only be called from the
// browser process. When run at startup, the profiler must use a synthetic
// field trial since it runs before the metrics field trials are initialized.
bool GetSyntheticFieldTrial(std::string* trial_name,
std::string* group_name) const;
// Add a command line switch that instructs the child process to run the
// profiler. This should only be called from the browser process.
void AppendCommandLineSwitchForChildProcess(
base::CommandLine* command_line) const;
private:
friend base::NoDestructor<ThreadProfilerConfiguration>;
// The variation groups that represent the Chrome-wide profiling
// configurations.
enum VariationGroup {
// Disabled within the experiment.
kProfileDisabled,
// Disabled because the required module is not installed, and outside the
// experiment.
kProfileDisabledModuleNotInstalled,
// Enabled within the experiment (and paired with equal-sized
// kProfileDisabled group).
kProfileControl,
// Enabled outside of the experiment.
kProfileEnabled,
};
// The configuration state for the browser process. If !has_value() profiling
// is disabled and no variations state is reported. Otherwise profiling is
// enabled based on the VariationGroup and the variation state is reported.
using BrowserProcessConfiguration = absl::optional<VariationGroup>;
// The configuration state in child processes.
enum ChildProcessConfiguration {
kChildProcessProfileDisabled,
kChildProcessProfileEnabled,
};
// The configuration state for the current process, browser or child.
using Configuration =
absl::variant<BrowserProcessConfiguration, ChildProcessConfiguration>;
// Configuration variations, along with weights to use when randomly choosing
// one of a set of variations.
struct Variation {
VariationGroup group;
int weight;
};
ThreadProfilerConfiguration();
// True if the profiler is to be enabled for |variation_group|.
static bool EnableForVariationGroup(
absl::optional<VariationGroup> variation_group);
// Randomly chooses a variation from the weighted variations. Weights are
// expected to sum to 100 as a sanity check.
static VariationGroup ChooseVariationGroup(
std::initializer_list<Variation> variations);
// Generates a configuration for the browser process.
static BrowserProcessConfiguration GenerateBrowserProcessConfiguration(
const ThreadProfilerPlatformConfiguration& platform_configuration);
// Generates a configuration for a child process.
static ChildProcessConfiguration GenerateChildProcessConfiguration(
const base::CommandLine& command_line);
// Generates a configuration for the current process.
static Configuration GenerateConfiguration(
metrics::CallStackProfileParams::Process process,
const ThreadProfilerPlatformConfiguration& platform_configuration);
// NOTE: all state in this class must be const and initialized at construction
// time to ensure thread-safe access post-construction.
// Platform-dependent configuration upon which |configuration_| is based.
const std::unique_ptr<ThreadProfilerPlatformConfiguration>
platform_configuration_;
// Represents the configuration to use in the current process.
const Configuration configuration_;
};
#endif // CHROME_COMMON_PROFILER_THREAD_PROFILER_CONFIGURATION_H_