OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/browser/devtools/protocol/tracing_handler.h" | 5 #include "content/browser/devtools/protocol/tracing_handler.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/format_macros.h" |
10 #include "base/strings/string_split.h" | 11 #include "base/strings/string_split.h" |
11 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
12 #include "base/time/time.h" | 13 #include "base/time/time.h" |
13 #include "base/timer/timer.h" | 14 #include "base/timer/timer.h" |
| 15 #include "base/trace_event/memory_dump_manager.h" |
14 #include "base/trace_event/trace_event_impl.h" | 16 #include "base/trace_event/trace_event_impl.h" |
15 | 17 |
16 namespace content { | 18 namespace content { |
17 namespace devtools { | 19 namespace devtools { |
18 namespace tracing { | 20 namespace tracing { |
19 | 21 |
20 typedef DevToolsProtocolClient::Response Response; | 22 typedef DevToolsProtocolClient::Response Response; |
21 | 23 |
22 namespace { | 24 namespace { |
23 | 25 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 DevToolsCommandId command_id, | 149 DevToolsCommandId command_id, |
148 const std::set<std::string>& category_set) { | 150 const std::set<std::string>& category_set) { |
149 std::vector<std::string> categories; | 151 std::vector<std::string> categories; |
150 for (const std::string& category : category_set) | 152 for (const std::string& category : category_set) |
151 categories.push_back(category); | 153 categories.push_back(category); |
152 client_->SendGetCategoriesResponse(command_id, | 154 client_->SendGetCategoriesResponse(command_id, |
153 GetCategoriesResponse::Create()->set_categories(categories)); | 155 GetCategoriesResponse::Create()->set_categories(categories)); |
154 } | 156 } |
155 | 157 |
156 Response TracingHandler::RequestMemoryDump(DevToolsCommandId command_id) { | 158 Response TracingHandler::RequestMemoryDump(DevToolsCommandId command_id) { |
157 return Response::InternalError("Not implemented"); | 159 if (!did_initiate_recording_) |
| 160 return Response::InternalError("Tracing is not started"); |
| 161 |
| 162 base::trace_event::MemoryDumpManager::GetInstance()->RequestGlobalDump( |
| 163 base::trace_event::MemoryDumpType::EXPLICITLY_TRIGGERED, |
| 164 base::Bind(&TracingHandler::OnMemoryDumpFinished, |
| 165 weak_factory_.GetWeakPtr(), command_id)); |
| 166 return Response::OK(); |
| 167 } |
| 168 |
| 169 void TracingHandler::OnMemoryDumpFinished(DevToolsCommandId command_id, |
| 170 uint64 dump_guid, |
| 171 bool success) { |
| 172 client_->SendRequestMemoryDumpResponse( |
| 173 command_id, |
| 174 RequestMemoryDumpResponse::Create() |
| 175 ->set_dump_guid(base::StringPrintf("0x%" PRIx64, dump_guid)) |
| 176 ->set_success(success)); |
158 } | 177 } |
159 | 178 |
160 void TracingHandler::SetupTimer(double usage_reporting_interval) { | 179 void TracingHandler::SetupTimer(double usage_reporting_interval) { |
161 if (usage_reporting_interval == 0) return; | 180 if (usage_reporting_interval == 0) return; |
162 | 181 |
163 if (usage_reporting_interval < kMinimumReportingInterval) | 182 if (usage_reporting_interval < kMinimumReportingInterval) |
164 usage_reporting_interval = kMinimumReportingInterval; | 183 usage_reporting_interval = kMinimumReportingInterval; |
165 | 184 |
166 base::TimeDelta interval = base::TimeDelta::FromMilliseconds( | 185 base::TimeDelta interval = base::TimeDelta::FromMilliseconds( |
167 std::ceil(usage_reporting_interval)); | 186 std::ceil(usage_reporting_interval)); |
(...skipping 14 matching lines...) Expand all Loading... |
182 did_initiate_recording_ = false; | 201 did_initiate_recording_ = false; |
183 } | 202 } |
184 | 203 |
185 bool TracingHandler::IsRecording() const { | 204 bool TracingHandler::IsRecording() const { |
186 return TracingController::GetInstance()->IsRecording(); | 205 return TracingController::GetInstance()->IsRecording(); |
187 } | 206 } |
188 | 207 |
189 } // namespace tracing | 208 } // namespace tracing |
190 } // namespace devtools | 209 } // namespace devtools |
191 } // namespace content | 210 } // namespace content |
OLD | NEW |