summaryrefslogtreecommitdiff
path: root/chromium/components/tracing
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2022-05-12 15:59:20 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2022-05-25 06:57:22 +0000
commitf7eaed5286974984ba5f9e3189d8f49d03e99f81 (patch)
treecaed19b2af2024f35449fb0b781d0a25e09d4f8f /chromium/components/tracing
parent9729c4479fe23554eae6e6dd1f30ff488f470c84 (diff)
downloadqtwebengine-chromium-f7eaed5286974984ba5f9e3189d8f49d03e99f81.tar.gz
BASELINE: Update Chromium to 100.0.4896.167
Change-Id: I98cbeb5d7543d966ffe04d8cefded0c493a11333 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/components/tracing')
-rw-r--r--chromium/components/tracing/BUILD.gn16
-rw-r--r--chromium/components/tracing/DEPS3
-rw-r--r--chromium/components/tracing/common/background_tracing_metrics_provider.cc64
-rw-r--r--chromium/components/tracing/common/background_tracing_metrics_provider.h53
-rw-r--r--chromium/components/tracing/common/trace_startup_config.cc48
-rw-r--r--chromium/components/tracing/common/trace_startup_config.h2
6 files changed, 165 insertions, 21 deletions
diff --git a/chromium/components/tracing/BUILD.gn b/chromium/components/tracing/BUILD.gn
index 92b69ee2c8b..79940ddc927 100644
--- a/chromium/components/tracing/BUILD.gn
+++ b/chromium/components/tracing/BUILD.gn
@@ -34,6 +34,22 @@ component("startup_tracing") {
deps = [ "//base" ]
}
+component("background_tracing_metrics_provider") {
+ sources = [
+ "common/background_tracing_metrics_provider.cc",
+ "common/background_tracing_metrics_provider.h",
+ "tracing_export.h",
+ ]
+
+ defines = [ "TRACING_IMPLEMENTATION" ]
+
+ deps = [
+ "//base",
+ "//components/metrics:content",
+ "//content/public/browser",
+ ]
+}
+
source_set("unit_tests") {
testonly = true
diff --git a/chromium/components/tracing/DEPS b/chromium/components/tracing/DEPS
index 08980e5e0dc..116393a7b5c 100644
--- a/chromium/components/tracing/DEPS
+++ b/chromium/components/tracing/DEPS
@@ -1,5 +1,8 @@
include_rules = [
"+ipc",
+ "+components/metrics",
+ "+third_party/metrics_proto",
+ "+content/public/browser/background_tracing_manager.h",
]
specific_include_rules = {
diff --git a/chromium/components/tracing/common/background_tracing_metrics_provider.cc b/chromium/components/tracing/common/background_tracing_metrics_provider.cc
new file mode 100644
index 00000000000..3ce2c68fdca
--- /dev/null
+++ b/chromium/components/tracing/common/background_tracing_metrics_provider.cc
@@ -0,0 +1,64 @@
+// Copyright 2022 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.
+
+#include "components/tracing/common/background_tracing_metrics_provider.h"
+
+#include "base/time/time.h"
+
+#include "components/metrics/content/gpu_metrics_provider.h"
+#include "components/metrics/cpu_metrics_provider.h"
+#include "content/public/browser/background_tracing_manager.h"
+#include "third_party/metrics_proto/chrome_user_metrics_extension.pb.h"
+#include "third_party/metrics_proto/trace_log.pb.h"
+
+namespace tracing {
+
+BackgroundTracingMetricsProvider::BackgroundTracingMetricsProvider() = default;
+BackgroundTracingMetricsProvider::~BackgroundTracingMetricsProvider() = default;
+
+void BackgroundTracingMetricsProvider::Init() {
+ system_profile_providers_.emplace_back(
+ std::make_unique<metrics::CPUMetricsProvider>());
+ system_profile_providers_.emplace_back(
+ std::make_unique<metrics::GPUMetricsProvider>());
+}
+
+bool BackgroundTracingMetricsProvider::HasIndependentMetrics() {
+ return content::BackgroundTracingManager::GetInstance()->HasTraceToUpload();
+}
+
+void BackgroundTracingMetricsProvider::ProvideIndependentMetrics(
+ base::OnceCallback<void(bool)> done_callback,
+ metrics::ChromeUserMetricsExtension* uma_proto,
+ base::HistogramSnapshotManager* snapshot_manager) {
+ auto* tracing_manager = content::BackgroundTracingManager::GetInstance();
+ // TODO(crbug.com/1290887): remove this when
+ // content::BackgroundTracingManager::GetInstance() is updated to return a
+ // reference.
+ DCHECK(tracing_manager);
+
+ auto serialized_trace = tracing_manager->GetLatestTraceToUpload();
+ if (serialized_trace.empty()) {
+ std::move(done_callback).Run(false);
+ return;
+ }
+ metrics::TraceLog* log = uma_proto->add_trace_log();
+ log->set_raw_data(std::move(serialized_trace));
+
+ auto* system_profile = uma_proto->mutable_system_profile();
+
+ for (auto& provider : system_profile_providers_) {
+ provider->ProvideSystemProfileMetricsWithLogCreationTime(
+ base::TimeTicks::Now(), system_profile);
+ }
+
+ ProvideEmbedderMetrics(uma_proto, snapshot_manager);
+ std::move(done_callback).Run(true);
+}
+
+void BackgroundTracingMetricsProvider::ProvideEmbedderMetrics(
+ metrics::ChromeUserMetricsExtension* uma_proto,
+ base::HistogramSnapshotManager* snapshot_manager) {}
+
+} // namespace tracing
diff --git a/chromium/components/tracing/common/background_tracing_metrics_provider.h b/chromium/components/tracing/common/background_tracing_metrics_provider.h
new file mode 100644
index 00000000000..602ef50a4a8
--- /dev/null
+++ b/chromium/components/tracing/common/background_tracing_metrics_provider.h
@@ -0,0 +1,53 @@
+// Copyright 2022 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 COMPONENTS_TRACING_COMMON_BACKGROUND_TRACING_METRICS_PROVIDER_H_
+#define COMPONENTS_TRACING_COMMON_BACKGROUND_TRACING_METRICS_PROVIDER_H_
+
+#include <vector>
+
+#include "components/metrics/metrics_provider.h"
+#include "components/tracing/tracing_export.h"
+
+namespace tracing {
+
+// Provides trace log metrics collected using BackgroundTracingManager to UMA
+// proto. Background tracing uploads metrics of larger size compared to UMA
+// histograms and it is better to upload them as independent metrics rather
+// than part of UMA histograms log. The background tracing manager will make
+// sure the traces are small when uploading over data.
+class TRACING_EXPORT BackgroundTracingMetricsProvider
+ : public metrics::MetricsProvider {
+ public:
+ BackgroundTracingMetricsProvider();
+
+ BackgroundTracingMetricsProvider(const BackgroundTracingMetricsProvider&) =
+ delete;
+ BackgroundTracingMetricsProvider& operator=(
+ const BackgroundTracingMetricsProvider&) = delete;
+
+ ~BackgroundTracingMetricsProvider() override;
+
+ // metrics::MetricsProvider:
+ bool HasIndependentMetrics() override;
+ void ProvideIndependentMetrics(
+ base::OnceCallback<void(bool)> done_callback,
+ metrics::ChromeUserMetricsExtension* uma_proto,
+ base::HistogramSnapshotManager* snapshot_manager) override;
+ void Init() override;
+
+ protected:
+ // Embedders can override this to do any additional processing of the log
+ // before it is sent.
+ virtual void ProvideEmbedderMetrics(
+ metrics::ChromeUserMetricsExtension* uma_proto,
+ base::HistogramSnapshotManager* snapshot_manager);
+
+ std::vector<std::unique_ptr<metrics::MetricsProvider>>
+ system_profile_providers_;
+};
+
+} // namespace tracing
+
+#endif // COMPONENTS_TRACING_COMMON_BACKGROUND_TRACING_METRICS_PROVIDER_H_
diff --git a/chromium/components/tracing/common/trace_startup_config.cc b/chromium/components/tracing/common/trace_startup_config.cc
index 45ef92a5dbd..a1db0ce9ef2 100644
--- a/chromium/components/tracing/common/trace_startup_config.cc
+++ b/chromium/components/tracing/common/trace_startup_config.cc
@@ -21,7 +21,7 @@
#include "build/build_config.h"
#include "components/tracing/common/tracing_switches.h"
-#if defined(OS_ANDROID)
+#if BUILDFLAG(IS_ANDROID)
#include "base/android/early_trace_event_binding.h"
#endif
@@ -35,7 +35,7 @@ const size_t kTraceConfigFileSizeLimit = 64 * 1024;
// Trace config file path:
// - Android: /data/local/chrome-trace-config.json
// - Others: specified by --trace-config-file flag.
-#if defined(OS_ANDROID)
+#if BUILDFLAG(IS_ANDROID)
const base::FilePath::CharType kAndroidTraceConfigFile[] =
FILE_PATH_LITERAL("/data/local/chrome-trace-config.json");
#endif
@@ -50,7 +50,7 @@ const char kResultDirectoryParam[] = "result_directory";
// static
const char TraceStartupConfig::kDefaultStartupCategories[] =
-#if defined(OS_ANDROID)
+#if BUILDFLAG(IS_ANDROID)
"startup,browser,toplevel,toplevel.flow,ipc,EarlyJava,cc,Java,navigation,"
"loading,gpu,ui,disabled-by-default-cpu_profiler,download_service,"
"disabled-by-default-histogram_samples,"
@@ -135,7 +135,7 @@ base::FilePath TraceStartupConfig::GetResultFile() const {
}
void TraceStartupConfig::SetBackgroundStartupTracingEnabled(bool enabled) {
-#if defined(OS_ANDROID)
+#if BUILDFLAG(IS_ANDROID)
base::android::SetBackgroundStartupTracingFlag(enabled);
#endif
}
@@ -157,6 +157,10 @@ bool TraceStartupConfig::AttemptAdoptBySessionOwner(SessionOwner owner) {
bool TraceStartupConfig::EnableFromCommandLine() {
auto* command_line = base::CommandLine::ForCurrentProcess();
+ bool tracing_enabled_from_command_line =
+ command_line->HasSwitch(switches::kTraceStartup) ||
+ command_line->HasSwitch(switches::kEnableTracing);
+
if (command_line->HasSwitch(switches::kTraceStartupDuration)) {
std::string startup_duration_str =
command_line->GetSwitchValueASCII(switches::kTraceStartupDuration);
@@ -173,19 +177,23 @@ bool TraceStartupConfig::EnableFromCommandLine() {
if (command_line->HasSwitch(switches::kTraceStartupFormat)) {
if (command_line->GetSwitchValueASCII(switches::kTraceStartupFormat) ==
- "proto") {
- // Default is "json".
- output_format_ = OutputFormat::kProto;
+ "json") {
+ // Default is "proto", so switch to json only if the "json" string is
+ // provided.
+ output_format_ = OutputFormat::kLegacyJSON;
+ }
+ } else if (command_line->HasSwitch(switches::kEnableTracingFormat)) {
+ if (command_line->GetSwitchValueASCII(switches::kEnableTracingFormat) ==
+ "json") {
+ output_format_ = OutputFormat::kLegacyJSON;
}
- } else if (command_line->GetSwitchValueASCII(
- switches::kEnableTracingFormat) == "proto") {
- output_format_ = OutputFormat::kProto;
}
- if (!command_line->HasSwitch(switches::kTraceStartup) &&
- !command_line->HasSwitch(switches::kEnableTracing)) {
+ // This check is intentionally performed after setting duration and output
+ // format to ensure that setting them from the command-line takes effect for
+ // config file-based tracing as well.
+ if (!tracing_enabled_from_command_line)
return false;
- }
std::string categories;
if (command_line->HasSwitch(switches::kTraceStartup)) {
@@ -214,7 +222,7 @@ bool TraceStartupConfig::EnableFromCommandLine() {
}
bool TraceStartupConfig::EnableFromATrace() {
-#if defined(OS_ANDROID)
+#if BUILDFLAG(IS_ANDROID)
auto atrace_config =
base::trace_event::TraceLog::GetInstance()->TakeATraceStartupConfig();
if (!atrace_config)
@@ -226,13 +234,13 @@ bool TraceStartupConfig::EnableFromATrace() {
// command line flags to control startup tracing instead of ATrace.
session_owner_ = SessionOwner::kSystemTracing;
return true;
-#else // defined(OS_ANDROID)
+#else // BUILDFLAG(IS_ANDROID)
return false;
-#endif // !defined(OS_ANDROID)
+#endif // !BUILDFLAG(IS_ANDROID)
}
bool TraceStartupConfig::EnableFromConfigFile() {
-#if defined(OS_ANDROID)
+#if BUILDFLAG(IS_ANDROID)
base::FilePath trace_config_file(kAndroidTraceConfigFile);
#else
auto* command_line = base::CommandLine::ForCurrentProcess();
@@ -268,7 +276,7 @@ bool TraceStartupConfig::EnableFromConfigFile() {
bool TraceStartupConfig::EnableFromBackgroundTracing() {
bool enabled = enable_background_tracing_for_testing_;
-#if defined(OS_ANDROID)
+#if BUILDFLAG(IS_ANDROID)
// Tests can enable this value.
enabled |= base::android::GetBackgroundStartupTracingFlag();
#else
@@ -305,8 +313,8 @@ bool TraceStartupConfig::ParseTraceConfigFileContent(
trace_config_ = base::trace_event::TraceConfig(*trace_config_dict);
- if (!dict->GetInteger(kStartupDurationParam, &startup_duration_in_seconds_))
- startup_duration_in_seconds_ = 0;
+ startup_duration_in_seconds_ =
+ dict->FindIntKey(kStartupDurationParam).value_or(0);
if (startup_duration_in_seconds_ < 0)
startup_duration_in_seconds_ = 0;
diff --git a/chromium/components/tracing/common/trace_startup_config.h b/chromium/components/tracing/common/trace_startup_config.h
index 5d48a284783..3fa05c2c91c 100644
--- a/chromium/components/tracing/common/trace_startup_config.h
+++ b/chromium/components/tracing/common/trace_startup_config.h
@@ -169,7 +169,7 @@ class TRACING_EXPORT TraceStartupConfig {
base::FilePath result_file_;
SessionOwner session_owner_ = SessionOwner::kTracingController;
bool session_adopted_ = false;
- OutputFormat output_format_ = OutputFormat::kLegacyJSON;
+ OutputFormat output_format_ = OutputFormat::kProto;
};
} // namespace tracing