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 @@
#include "base/process/memory.h"
#include "base/process/process_metrics_iocounters.h"
#include "base/sys_info.h"
#include "base/threading/scoped_blocking_call.h"
namespace base {
namespace {
......@@ -345,12 +346,15 @@ BASE_EXPORT bool GetSystemPerformanceInfo(SystemPerformanceInfo* info) {
return false;
SYSTEM_PERFORMANCE_INFORMATION counters = {};
const NTSTATUS status = query_system_information_ptr(
::SystemPerformanceInformation, &counters,
sizeof(SYSTEM_PERFORMANCE_INFORMATION), nullptr);
if (status != STATUS_SUCCESS)
{
// The call to NtQuerySystemInformation might block on a lock.
base::ScopedBlockingCall scoped_blocking_call(BlockingType::MAY_BLOCK);
if (query_system_information_ptr(::SystemPerformanceInformation, &counters,
sizeof(SYSTEM_PERFORMANCE_INFORMATION),
nullptr) != STATUS_SUCCESS) {
return false;
}
}
info->idle_time = counters.IdleTime.QuadPart;
info->read_transfer_count = counters.ReadTransferCount.QuadPart;
......
......@@ -6,6 +6,7 @@
#include <memory>
#include "base/bind.h"
#include "base/debug/leak_annotations.h"
#include "base/json/json_writer.h"
#include "base/lazy_instance.h"
......@@ -14,6 +15,7 @@
#include "base/process/process_metrics.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/task/post_task.h"
#include "base/threading/thread_local_storage.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/trace_event/trace_event.h"
......@@ -49,6 +51,17 @@ void SystemStatsHolder::GetSystemProfilingStats() {
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
//////////////////////////////////////////////////////////////////////////////
......@@ -102,15 +115,17 @@ void TraceEventSystemStatsMonitor::StartProfiling() {
weak_factory_.GetWeakPtr()));
}
// If system tracing is enabled, dumps a profile to the tracing system.
void TraceEventSystemStatsMonitor::DumpSystemStats() {
std::unique_ptr<SystemStatsHolder> dump_holder(new SystemStatsHolder());
dump_holder->GetSystemProfilingStats();
TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(
TRACE_DISABLED_BY_DEFAULT("system_stats"),
"base::TraceEventSystemStatsMonitor::SystemStats", this,
std::move(dump_holder));
// Calls to |DumpSystemStatsImpl| might be blocking.
//
// TODO(sebmarchand): Ideally the timer that calls this function should use a
// thread with the MayBlock trait to avoid having to use a trampoline here.
// This isn't currently possible due to https://crbug.com/896990.
base::PostTaskWithTraits(
FROM_HERE,
{base::MayBlock(), base::TaskPriority::BEST_EFFORT,
base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN},
base::BindOnce(&DumpSystemStatsImpl, base::Unretained(this)));
}
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