Commit f0d70102 authored by Jonghyun Ahn's avatar Jonghyun Ahn Committed by Commit Bot

Add chromeos hardware class to memory traces uploaded to memlog.

Bug: 994989
Change-Id: I92f7cf9a1ee321e46cd5d3cf65ea50e0c18b9f4b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1761334Reviewed-by: default avataroysteine <oysteine@chromium.org>
Reviewed-by: default avatarErik Chen <erikchen@chromium.org>
Commit-Queue: Jong Ahn <jongahn@google.com>
Cr-Commit-Position: refs/heads/master@{#689183}
parent 5b3edee6
...@@ -2555,6 +2555,7 @@ jumbo_source_set("browser") { ...@@ -2555,6 +2555,7 @@ jumbo_source_set("browser") {
"//chromeos/dbus/power", "//chromeos/dbus/power",
"//chromeos/dbus/power:power_manager_proto", "//chromeos/dbus/power:power_manager_proto",
"//chromeos/network", "//chromeos/network",
"//chromeos/system",
"//components/session_manager/core", "//components/session_manager/core",
] ]
} else { } else {
......
...@@ -30,6 +30,11 @@ ...@@ -30,6 +30,11 @@
#include "services/tracing/public/cpp/trace_event_agent.h" #include "services/tracing/public/cpp/trace_event_agent.h"
#include "services/tracing/public/cpp/tracing_features.h" #include "services/tracing/public/cpp/tracing_features.h"
#if defined(OS_CHROMEOS)
#include "chromeos/system/fake_statistics_provider.h"
#include "chromeos/system/statistics_provider.h"
#endif
using base::trace_event::RECORD_CONTINUOUSLY; using base::trace_event::RECORD_CONTINUOUSLY;
using base::trace_event::RECORD_UNTIL_FULL; using base::trace_event::RECORD_UNTIL_FULL;
using base::trace_event::TraceConfig; using base::trace_event::TraceConfig;
...@@ -108,6 +113,14 @@ class TracingControllerTest : public ContentBrowserTest { ...@@ -108,6 +113,14 @@ class TracingControllerTest : public ContentBrowserTest {
get_categories_done_callback_count_ = 0; get_categories_done_callback_count_ = 0;
enable_recording_done_callback_count_ = 0; enable_recording_done_callback_count_ = 0;
disable_recording_done_callback_count_ = 0; disable_recording_done_callback_count_ = 0;
#if defined(OS_CHROMEOS)
// Set statistic provider for hardware class tests.
chromeos::system::StatisticsProvider::SetTestProvider(
&fake_statistics_provider_);
fake_statistics_provider_.SetMachineStatistic(
chromeos::system::kHardwareClassKey, "test-hardware-class");
#endif
ContentBrowserTest::SetUp(); ContentBrowserTest::SetUp();
} }
...@@ -156,7 +169,7 @@ class TracingControllerTest : public ContentBrowserTest { ...@@ -156,7 +169,7 @@ class TracingControllerTest : public ContentBrowserTest {
last_actual_recording_file_path_ = file_path; last_actual_recording_file_path_ = file_path;
} }
int get_categories_done_callback_count() const { int get_categories_done_callback_count() const {
return get_categories_done_callback_count_; return get_categories_done_callback_count_;
} }
...@@ -331,6 +344,11 @@ class TracingControllerTest : public ContentBrowserTest { ...@@ -331,6 +344,11 @@ class TracingControllerTest : public ContentBrowserTest {
} }
} }
#if defined(OS_CHROMEOS)
protected:
chromeos::system::ScopedFakeStatisticsProvider fake_statistics_provider_;
#endif
private: private:
int get_categories_done_callback_count_; int get_categories_done_callback_count_;
int enable_recording_done_callback_count_; int enable_recording_done_callback_count_;
...@@ -380,6 +398,11 @@ IN_PROC_BROWSER_TEST_F(TracingControllerTest, ...@@ -380,6 +398,11 @@ IN_PROC_BROWSER_TEST_F(TracingControllerTest,
std::string trace_config; std::string trace_config;
last_metadata()->GetString("trace-config", &trace_config); last_metadata()->GetString("trace-config", &trace_config);
EXPECT_EQ(TraceConfig().ToString(), trace_config); EXPECT_EQ(TraceConfig().ToString(), trace_config);
#if defined(OS_CHROMEOS)
std::string hardware_class;
last_metadata()->GetString("hardware-class", &hardware_class);
EXPECT_EQ(hardware_class, "test-hardware-class");
#endif
} }
IN_PROC_BROWSER_TEST_F(TracingControllerTest, NotWhitelistedMetadataStripped) { IN_PROC_BROWSER_TEST_F(TracingControllerTest, NotWhitelistedMetadataStripped) {
...@@ -398,6 +421,11 @@ IN_PROC_BROWSER_TEST_F(TracingControllerTest, NotWhitelistedMetadataStripped) { ...@@ -398,6 +421,11 @@ IN_PROC_BROWSER_TEST_F(TracingControllerTest, NotWhitelistedMetadataStripped) {
last_metadata()->GetString("user-agent", &user_agent); last_metadata()->GetString("user-agent", &user_agent);
EXPECT_FALSE(user_agent.empty()); EXPECT_FALSE(user_agent.empty());
EXPECT_TRUE(user_agent != "__stripped__"); EXPECT_TRUE(user_agent != "__stripped__");
#if defined(OS_CHROMEOS)
std::string hardware_class;
last_metadata()->GetString("hardware-class", &hardware_class);
EXPECT_EQ(hardware_class, "test-hardware-class");
#endif
// Check that the not whitelisted metadata is stripped. // Check that the not whitelisted metadata is stripped.
std::string not_whitelisted; std::string not_whitelisted;
...@@ -417,6 +445,9 @@ IN_PROC_BROWSER_TEST_F(TracingControllerTest, NotWhitelistedMetadataStripped) { ...@@ -417,6 +445,9 @@ IN_PROC_BROWSER_TEST_F(TracingControllerTest, NotWhitelistedMetadataStripped) {
EXPECT_TRUE(KeyNotEquals(metadata_json, "network-type", "__stripped__")); EXPECT_TRUE(KeyNotEquals(metadata_json, "network-type", "__stripped__"));
EXPECT_TRUE(KeyNotEquals(metadata_json, "os-name", "__stripped__")); EXPECT_TRUE(KeyNotEquals(metadata_json, "os-name", "__stripped__"));
EXPECT_TRUE(KeyNotEquals(metadata_json, "user-agent", "__stripped__")); EXPECT_TRUE(KeyNotEquals(metadata_json, "user-agent", "__stripped__"));
#if defined(OS_CHROMEOS)
EXPECT_TRUE(KeyNotEquals(metadata_json, "hardware-class", "__stripped__"));
#endif
// The following field is not whitelisted and is supposed to be stripped. // The following field is not whitelisted and is supposed to be stripped.
EXPECT_TRUE(KeyEquals(metadata_json, "v8-version", "__stripped__")); EXPECT_TRUE(KeyEquals(metadata_json, "v8-version", "__stripped__"));
......
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
#include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/debug_daemon_client.h" #include "chromeos/dbus/debug_daemon_client.h"
#include "chromeos/system/statistics_provider.h"
#include "content/browser/tracing/cros_tracing_agent.h" #include "content/browser/tracing/cros_tracing_agent.h"
#endif #endif
...@@ -176,6 +177,14 @@ TracingControllerImpl::TracingControllerImpl() ...@@ -176,6 +177,14 @@ TracingControllerImpl::TracingControllerImpl()
// process however. // process however.
if (PerfettoFileTracer::ShouldEnable()) if (PerfettoFileTracer::ShouldEnable())
perfetto_file_tracer_ = std::make_unique<PerfettoFileTracer>(); perfetto_file_tracer_ = std::make_unique<PerfettoFileTracer>();
#if defined(OS_CHROMEOS)
// Bind hwclass once the statistics are available.
chromeos::system::StatisticsProvider::GetInstance()
->ScheduleOnMachineStatisticsLoaded(
base::BindOnce(&TracingControllerImpl::OnMachineStatisticsLoaded,
weak_ptr_factory_.GetWeakPtr()));
#endif
} }
TracingControllerImpl::~TracingControllerImpl() = default; TracingControllerImpl::~TracingControllerImpl() = default;
...@@ -258,9 +267,11 @@ TracingControllerImpl::GenerateMetadataDict() { ...@@ -258,9 +267,11 @@ TracingControllerImpl::GenerateMetadataDict() {
// OS // OS
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
metadata_dict->SetString("os-name", "CrOS"); metadata_dict->SetString("os-name", "CrOS");
if (are_statistics_loaded_)
metadata_dict->SetString("hardware-class", hardware_class_);
#else #else
metadata_dict->SetString("os-name", base::SysInfo::OperatingSystemName()); metadata_dict->SetString("os-name", base::SysInfo::OperatingSystemName());
#endif #endif // defined(OS_CHROMEOS)
metadata_dict->SetString("os-version", metadata_dict->SetString("os-version",
base::SysInfo::OperatingSystemVersion()); base::SysInfo::OperatingSystemVersion());
#if defined(OS_WIN) #if defined(OS_WIN)
...@@ -621,6 +632,14 @@ void TracingControllerImpl::OnMetadataAvailable(base::Value metadata) { ...@@ -621,6 +632,14 @@ void TracingControllerImpl::OnMetadataAvailable(base::Value metadata) {
CompleteFlush(); CompleteFlush();
} }
#if defined(OS_CHROMEOS)
void TracingControllerImpl::OnMachineStatisticsLoaded() {
chromeos::system::StatisticsProvider::GetInstance()->GetMachineStatistic(
chromeos::system::kHardwareClassKey, &hardware_class_);
are_statistics_loaded_ = true;
}
#endif
void TracingControllerImpl::SetTracingDelegateForTesting( void TracingControllerImpl::SetTracingDelegateForTesting(
std::unique_ptr<TracingDelegate> delegate) { std::unique_ptr<TracingDelegate> delegate) {
if (!delegate) { if (!delegate) {
......
...@@ -107,6 +107,9 @@ class TracingControllerImpl : public TracingController, ...@@ -107,6 +107,9 @@ class TracingControllerImpl : public TracingController,
void InitStartupTracingForDuration(); void InitStartupTracingForDuration();
void EndStartupTracing(); void EndStartupTracing();
#if defined(OS_CHROMEOS)
void OnMachineStatisticsLoaded();
#endif
base::FilePath GetStartupTraceFileName() const; base::FilePath GetStartupTraceFileName() const;
std::unique_ptr<PerfettoFileTracer> perfetto_file_tracer_; std::unique_ptr<PerfettoFileTracer> perfetto_file_tracer_;
...@@ -125,6 +128,12 @@ class TracingControllerImpl : public TracingController, ...@@ -125,6 +128,12 @@ class TracingControllerImpl : public TracingController,
// This timer initiates trace file saving. // This timer initiates trace file saving.
base::OneShotTimer startup_trace_timer_; base::OneShotTimer startup_trace_timer_;
#if defined(OS_CHROMEOS)
bool are_statistics_loaded_ = false;
std::string hardware_class_;
base::WeakPtrFactory<TracingControllerImpl> weak_ptr_factory_{this};
#endif
DISALLOW_COPY_AND_ASSIGN(TracingControllerImpl); DISALLOW_COPY_AND_ASSIGN(TracingControllerImpl);
}; };
......
...@@ -1383,6 +1383,7 @@ test("content_browsertests") { ...@@ -1383,6 +1383,7 @@ test("content_browsertests") {
deps += [ deps += [
"//chromeos/audio", "//chromeos/audio",
"//chromeos/dbus/audio", "//chromeos/dbus/audio",
"//chromeos/system",
] ]
} }
......
...@@ -87,6 +87,7 @@ const char* kMetadataWhitelist[] = {"chrome-bitness", ...@@ -87,6 +87,7 @@ const char* kMetadataWhitelist[] = {"chrome-bitness",
"field-trials", "field-trials",
"gpu-*", "gpu-*",
"highres-ticks", "highres-ticks",
"hardware-class",
"last_triggered_rule", "last_triggered_rule",
"network-type", "network-type",
"num-cpus", "num-cpus",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment