| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/trace_event/trace_event_system_stats_monitor.h" | 5 #include "base/trace_event/trace_event_system_stats_monitor.h" |
| 6 | 6 |
| 7 #include <memory> |
| 8 |
| 7 #include "base/debug/leak_annotations.h" | 9 #include "base/debug/leak_annotations.h" |
| 8 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| 9 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
| 10 #include "base/logging.h" | 12 #include "base/logging.h" |
| 11 #include "base/macros.h" | 13 #include "base/macros.h" |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 15 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
| 16 #include "base/threading/thread_local_storage.h" | 17 #include "base/threading/thread_local_storage.h" |
| 17 #include "base/trace_event/trace_event.h" | 18 #include "base/trace_event/trace_event.h" |
| 18 | 19 |
| 19 namespace base { | 20 namespace base { |
| 20 namespace trace_event { | 21 namespace trace_event { |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 dump_timer_.Start(FROM_HERE, | 98 dump_timer_.Start(FROM_HERE, |
| 98 TimeDelta::FromMilliseconds(TraceEventSystemStatsMonitor:: | 99 TimeDelta::FromMilliseconds(TraceEventSystemStatsMonitor:: |
| 99 kSamplingIntervalMilliseconds), | 100 kSamplingIntervalMilliseconds), |
| 100 base::Bind(&TraceEventSystemStatsMonitor:: | 101 base::Bind(&TraceEventSystemStatsMonitor:: |
| 101 DumpSystemStats, | 102 DumpSystemStats, |
| 102 weak_factory_.GetWeakPtr())); | 103 weak_factory_.GetWeakPtr())); |
| 103 } | 104 } |
| 104 | 105 |
| 105 // If system tracing is enabled, dumps a profile to the tracing system. | 106 // If system tracing is enabled, dumps a profile to the tracing system. |
| 106 void TraceEventSystemStatsMonitor::DumpSystemStats() { | 107 void TraceEventSystemStatsMonitor::DumpSystemStats() { |
| 107 scoped_ptr<SystemStatsHolder> dump_holder(new SystemStatsHolder()); | 108 std::unique_ptr<SystemStatsHolder> dump_holder(new SystemStatsHolder()); |
| 108 dump_holder->GetSystemProfilingStats(); | 109 dump_holder->GetSystemProfilingStats(); |
| 109 | 110 |
| 110 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID( | 111 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID( |
| 111 TRACE_DISABLED_BY_DEFAULT("system_stats"), | 112 TRACE_DISABLED_BY_DEFAULT("system_stats"), |
| 112 "base::TraceEventSystemStatsMonitor::SystemStats", this, | 113 "base::TraceEventSystemStatsMonitor::SystemStats", this, |
| 113 std::move(dump_holder)); | 114 std::move(dump_holder)); |
| 114 } | 115 } |
| 115 | 116 |
| 116 void TraceEventSystemStatsMonitor::StopProfiling() { | 117 void TraceEventSystemStatsMonitor::StopProfiling() { |
| 117 dump_timer_.Stop(); | 118 dump_timer_.Stop(); |
| 118 } | 119 } |
| 119 | 120 |
| 120 bool TraceEventSystemStatsMonitor::IsTimerRunningForTest() const { | 121 bool TraceEventSystemStatsMonitor::IsTimerRunningForTest() const { |
| 121 return dump_timer_.IsRunning(); | 122 return dump_timer_.IsRunning(); |
| 122 } | 123 } |
| 123 | 124 |
| 124 void AppendSystemProfileAsTraceFormat(const SystemMetrics& system_metrics, | 125 void AppendSystemProfileAsTraceFormat(const SystemMetrics& system_metrics, |
| 125 std::string* output) { | 126 std::string* output) { |
| 126 std::string tmp; | 127 std::string tmp; |
| 127 base::JSONWriter::Write(*system_metrics.ToValue(), &tmp); | 128 base::JSONWriter::Write(*system_metrics.ToValue(), &tmp); |
| 128 *output += tmp; | 129 *output += tmp; |
| 129 } | 130 } |
| 130 | 131 |
| 131 } // namespace trace_event | 132 } // namespace trace_event |
| 132 } // namespace base | 133 } // namespace base |
| OLD | NEW |