Commit 05183ceb authored by Sebastien Marchand's avatar Sebastien Marchand Committed by Commit Bot

Move the calls to DumpSystemStats to a MayBlock thread.

Bug: 895309
Change-Id: Ib777900ba581c77e4e94d998cd36b3ca2ada9ba6
Reviewed-on: https://chromium-review.googlesource.com/c/1282393Reviewed-by: default avataroysteine <oysteine@chromium.org>
Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Reviewed-by: default avatarEtienne Pierre-Doray <etiennep@chromium.org>
Commit-Queue: Sébastien Marchand <sebmarchand@chromium.org>
Cr-Commit-Position: refs/heads/master@{#603743}
parent 11e35e68
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "base/process/memory.h" #include "base/process/memory.h"
#include "base/process/process_metrics_iocounters.h" #include "base/process/process_metrics_iocounters.h"
#include "base/sys_info.h" #include "base/sys_info.h"
#include "base/threading/scoped_blocking_call.h"
namespace base { namespace base {
namespace { namespace {
...@@ -345,12 +346,15 @@ BASE_EXPORT bool GetSystemPerformanceInfo(SystemPerformanceInfo* info) { ...@@ -345,12 +346,15 @@ BASE_EXPORT bool GetSystemPerformanceInfo(SystemPerformanceInfo* info) {
return false; return false;
SYSTEM_PERFORMANCE_INFORMATION counters = {}; SYSTEM_PERFORMANCE_INFORMATION counters = {};
const NTSTATUS status = query_system_information_ptr( {
::SystemPerformanceInformation, &counters, // The call to NtQuerySystemInformation might block on a lock.
sizeof(SYSTEM_PERFORMANCE_INFORMATION), nullptr); base::ScopedBlockingCall scoped_blocking_call(BlockingType::MAY_BLOCK);
if (query_system_information_ptr(::SystemPerformanceInformation, &counters,
if (status != STATUS_SUCCESS) sizeof(SYSTEM_PERFORMANCE_INFORMATION),
return false; nullptr) != STATUS_SUCCESS) {
return false;
}
}
info->idle_time = counters.IdleTime.QuadPart; info->idle_time = counters.IdleTime.QuadPart;
info->read_transfer_count = counters.ReadTransferCount.QuadPart; info->read_transfer_count = counters.ReadTransferCount.QuadPart;
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <memory> #include <memory>
#include "base/bind.h"
#include "base/debug/leak_annotations.h" #include "base/debug/leak_annotations.h"
#include "base/json/json_writer.h" #include "base/json/json_writer.h"
#include "base/lazy_instance.h" #include "base/lazy_instance.h"
...@@ -14,6 +15,7 @@ ...@@ -14,6 +15,7 @@
#include "base/process/process_metrics.h" #include "base/process/process_metrics.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/task/post_task.h"
#include "base/threading/thread_local_storage.h" #include "base/threading/thread_local_storage.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "base/trace_event/trace_event.h" #include "base/trace_event/trace_event.h"
...@@ -49,6 +51,17 @@ void SystemStatsHolder::GetSystemProfilingStats() { ...@@ -49,6 +51,17 @@ void SystemStatsHolder::GetSystemProfilingStats() {
system_stats_ = SystemMetrics::Sample(); system_stats_ = SystemMetrics::Sample();
} }
void DumpSystemStatsImpl(TraceEventSystemStatsMonitor* stats_monitor) {
std::unique_ptr<SystemStatsHolder> dump_holder =
std::make_unique<SystemStatsHolder>();
dump_holder->GetSystemProfilingStats();
TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(
TRACE_DISABLED_BY_DEFAULT("system_stats"),
"base::TraceEventSystemStatsMonitor::SystemStats", stats_monitor,
std::move(dump_holder));
}
} // namespace } // namespace
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
...@@ -102,15 +115,17 @@ void TraceEventSystemStatsMonitor::StartProfiling() { ...@@ -102,15 +115,17 @@ void TraceEventSystemStatsMonitor::StartProfiling() {
weak_factory_.GetWeakPtr())); weak_factory_.GetWeakPtr()));
} }
// If system tracing is enabled, dumps a profile to the tracing system.
void TraceEventSystemStatsMonitor::DumpSystemStats() { void TraceEventSystemStatsMonitor::DumpSystemStats() {
std::unique_ptr<SystemStatsHolder> dump_holder(new SystemStatsHolder()); // Calls to |DumpSystemStatsImpl| might be blocking.
dump_holder->GetSystemProfilingStats(); //
// TODO(sebmarchand): Ideally the timer that calls this function should use a
TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID( // thread with the MayBlock trait to avoid having to use a trampoline here.
TRACE_DISABLED_BY_DEFAULT("system_stats"), // This isn't currently possible due to https://crbug.com/896990.
"base::TraceEventSystemStatsMonitor::SystemStats", this, base::PostTaskWithTraits(
std::move(dump_holder)); FROM_HERE,
{base::MayBlock(), base::TaskPriority::BEST_EFFORT,
base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN},
base::BindOnce(&DumpSystemStatsImpl, base::Unretained(this)));
} }
void TraceEventSystemStatsMonitor::StopProfiling() { void TraceEventSystemStatsMonitor::StopProfiling() {
......
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