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. 4 5 #include "components/metrics/metrics_switches.h" 6 7 #include "base/check.h" 8 #include "base/command_line.h" 9 10 namespace metrics { 11 namespace switches { 12 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"; 20 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"; 24 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"; 29 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"; 36 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"; 41 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"; 45 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"; 49 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"; 53 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"; 58 59 } // namespace switches 60 IsMetricsRecordingOnlyEnabled()61bool IsMetricsRecordingOnlyEnabled() { 62 return base::CommandLine::ForCurrentProcess()->HasSwitch( 63 switches::kMetricsRecordingOnly); 64 } 65 IsMetricsReportingForceEnabled()66bool IsMetricsReportingForceEnabled() { 67 return base::CommandLine::ForCurrentProcess()->HasSwitch( 68 switches::kForceEnableMetricsReporting); 69 } 70 IsMsbbSettingForcedOnForUkm()71bool IsMsbbSettingForcedOnForUkm() { 72 return base::CommandLine::ForCurrentProcess()->HasSwitch( 73 switches::kForceMsbbSettingOnForUkm); 74 } 75 EnableMetricsRecordingOnlyForTesting(base::CommandLine * command_line)76void EnableMetricsRecordingOnlyForTesting(base::CommandLine* command_line) { 77 CHECK(command_line); 78 if (!command_line->HasSwitch(switches::kMetricsRecordingOnly)) 79 command_line->AppendSwitch(switches::kMetricsRecordingOnly); 80 } 81 ForceEnableMetricsReportingForTesting()82void ForceEnableMetricsReportingForTesting() { 83 auto* command_line = base::CommandLine::ForCurrentProcess(); 84 CHECK(command_line); 85 if (!command_line->HasSwitch(switches::kForceEnableMetricsReporting)) 86 command_line->AppendSwitch(switches::kForceEnableMetricsReporting); 87 } 88 89 } // namespace metrics 90