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> | 7 #include <memory> |
8 | 8 |
9 #include "base/debug/leak_annotations.h" | 9 #include "base/debug/leak_annotations.h" |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 | 72 |
73 void TraceEventSystemStatsMonitor::OnTraceLogEnabled() { | 73 void TraceEventSystemStatsMonitor::OnTraceLogEnabled() { |
74 // Check to see if system tracing is enabled. | 74 // Check to see if system tracing is enabled. |
75 bool enabled; | 75 bool enabled; |
76 | 76 |
77 TRACE_EVENT_CATEGORY_GROUP_ENABLED(TRACE_DISABLED_BY_DEFAULT( | 77 TRACE_EVENT_CATEGORY_GROUP_ENABLED(TRACE_DISABLED_BY_DEFAULT( |
78 "system_stats"), &enabled); | 78 "system_stats"), &enabled); |
79 if (!enabled) | 79 if (!enabled) |
80 return; | 80 return; |
81 task_runner_->PostTask( | 81 task_runner_->PostTask( |
82 FROM_HERE, | 82 FROM_HERE, base::BindOnce(&TraceEventSystemStatsMonitor::StartProfiling, |
83 base::Bind(&TraceEventSystemStatsMonitor::StartProfiling, | 83 weak_factory_.GetWeakPtr())); |
84 weak_factory_.GetWeakPtr())); | |
85 } | 84 } |
86 | 85 |
87 void TraceEventSystemStatsMonitor::OnTraceLogDisabled() { | 86 void TraceEventSystemStatsMonitor::OnTraceLogDisabled() { |
88 task_runner_->PostTask( | 87 task_runner_->PostTask( |
89 FROM_HERE, | 88 FROM_HERE, base::BindOnce(&TraceEventSystemStatsMonitor::StopProfiling, |
90 base::Bind(&TraceEventSystemStatsMonitor::StopProfiling, | 89 weak_factory_.GetWeakPtr())); |
91 weak_factory_.GetWeakPtr())); | |
92 } | 90 } |
93 | 91 |
94 void TraceEventSystemStatsMonitor::StartProfiling() { | 92 void TraceEventSystemStatsMonitor::StartProfiling() { |
95 // Watch for the tracing framework sending enabling more than once. | 93 // Watch for the tracing framework sending enabling more than once. |
96 if (dump_timer_.IsRunning()) | 94 if (dump_timer_.IsRunning()) |
97 return; | 95 return; |
98 | 96 |
99 dump_timer_.Start(FROM_HERE, | 97 dump_timer_.Start(FROM_HERE, |
100 TimeDelta::FromMilliseconds(TraceEventSystemStatsMonitor:: | 98 TimeDelta::FromMilliseconds(TraceEventSystemStatsMonitor:: |
101 kSamplingIntervalMilliseconds), | 99 kSamplingIntervalMilliseconds), |
(...skipping 23 matching lines...) Expand all Loading... |
125 | 123 |
126 void AppendSystemProfileAsTraceFormat(const SystemMetrics& system_metrics, | 124 void AppendSystemProfileAsTraceFormat(const SystemMetrics& system_metrics, |
127 std::string* output) { | 125 std::string* output) { |
128 std::string tmp; | 126 std::string tmp; |
129 base::JSONWriter::Write(*system_metrics.ToValue(), &tmp); | 127 base::JSONWriter::Write(*system_metrics.ToValue(), &tmp); |
130 *output += tmp; | 128 *output += tmp; |
131 } | 129 } |
132 | 130 |
133 } // namespace trace_event | 131 } // namespace trace_event |
134 } // namespace base | 132 } // namespace base |
OLD | NEW |