1 // Copyright 2014 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "components/metrics/metrics_switches.h"
7 #include "base/check.h"
8 #include "base/command_line.h"
13 // Enables the observing of all UMA logs created during the session and
14 // automatically exports them to the passed file path on shutdown (the file is
15 // created if it does not already exist). This also enables viewing all UMA logs
16 // in the chrome://metrics-internals debug page. The format of the exported file
17 // is outlined in MetricsServiceObserver::ExportLogsAsJson().
18 // Example usage: --export-uma-logs-to-file=/tmp/logs.json
19 const char kExportUmaLogsToFile[] = "export-uma-logs-to-file";
21 // Forces metrics reporting to be enabled. Should not be used for tests as it
22 // will send data to servers.
23 const char kForceEnableMetricsReporting[] = "force-enable-metrics-reporting";
25 // Forces MSBB setting to be on for UKM recording. Should only be used in
26 // automated testing browser sessions in which it is infeasible or impractical
27 // to toggle the setting manually.
28 const char kForceMsbbSettingOnForUkm[] = "force-msbb-setting-on-for-ukm";
30 // Enables the recording of metrics reports but disables reporting. In contrast
31 // to kForceEnableMetricsReporting, this executes all the code that a normal
32 // client would use for reporting, except the report is dropped rather than sent
33 // to the server. This is useful for finding issues in the metrics code during
34 // UI and performance tests.
35 const char kMetricsRecordingOnly[] = "metrics-recording-only";
37 // Override the standard time interval between each metrics report upload for
38 // UMA and UKM. It is useful to set to a short interval for debugging. Unit in
39 // seconds. (The default is 1800 seconds on desktop).
40 const char kMetricsUploadIntervalSec[] = "metrics-upload-interval";
42 // Forces a reset of the one-time-randomized FieldTrials on this client, also
43 // known as the Chrome Variations state.
44 const char kResetVariationState[] = "reset-variation-state";
46 // Overrides the URL of the server that UKM reports are uploaded to. This can
47 // only be used in debug builds.
48 const char kUkmServerUrl[] = "ukm-server-url";
50 // Overrides the URL of the server that UMA reports are uploaded to. This can
51 // only be used in debug builds.
52 const char kUmaServerUrl[] = "uma-server-url";
54 // Overrides the URL of the server that UMA reports are uploaded to when the
55 // connection to the default secure URL fails (see |kUmaServerUrl|). This can
56 // only be used in debug builds.
57 const char kUmaInsecureServerUrl[] = "uma-insecure-server-url";
59 } // namespace switches
61 bool IsMetricsRecordingOnlyEnabled() {
62 return base::CommandLine::ForCurrentProcess()->HasSwitch(
63 switches::kMetricsRecordingOnly);
66 bool IsMetricsReportingForceEnabled() {
67 return base::CommandLine::ForCurrentProcess()->HasSwitch(
68 switches::kForceEnableMetricsReporting);
71 bool IsMsbbSettingForcedOnForUkm() {
72 return base::CommandLine::ForCurrentProcess()->HasSwitch(
73 switches::kForceMsbbSettingOnForUkm);
76 void EnableMetricsRecordingOnlyForTesting(base::CommandLine* command_line) {
78 if (!command_line->HasSwitch(switches::kMetricsRecordingOnly))
79 command_line->AppendSwitch(switches::kMetricsRecordingOnly);
82 void ForceEnableMetricsReportingForTesting() {
83 auto* command_line = base::CommandLine::ForCurrentProcess();
85 if (!command_line->HasSwitch(switches::kForceEnableMetricsReporting))
86 command_line->AppendSwitch(switches::kForceEnableMetricsReporting);
89 } // namespace metrics