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