Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Side by Side Diff: content/browser/debugger/devtools_tracing_handler.cc

Issue 11548032: Telemetry / Devtools TraceHandler: exposes tracing via dev tools. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More comments Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/debugger/devtools_tracing_handler.h"
6
7 #include "base/bind.h"
8 #include "base/callback.h"
9 #include "base/location.h"
10 #include "base/values.h"
11 #include "content/browser/debugger/devtools_http_handler_impl.h"
12 #include "content/public/browser/browser_thread.h"
13 #include "content/public/browser/trace_controller.h"
14 #include "content/public/browser/trace_subscriber.h"
15
16 namespace content {
17
18 DevToolsTracingHandler::DevToolsTracingHandler()
19 : has_completed_(false) {
20 }
21
22 DevToolsTracingHandler::~DevToolsTracingHandler() {
23 }
24
25 void DevToolsTracingHandler::OnEndTracingComplete() {
26 has_completed_ = true;
27 }
28
29 void DevToolsTracingHandler::OnTraceDataCollected(
30 const scoped_refptr<base::RefCountedString>& trace_fragment) {
31 buffer_.push_back(trace_fragment->data());
32 }
33
34 base::Value* DevToolsTracingHandler::OnProtocolCommand(
35 const std::string& method,
36 const base::DictionaryValue* params) {
37 if (method == "Tracing.start")
38 return Start(params);
39 else if (method == "Tracing.end")
40 return End(params);
41 else if (method == "Tracing.hasCompleted")
42 return HasCompleted(params);
43 else if (method == "Tracing.getTraceAndReset")
44 return GetTraceAndReset(params);
45 return NULL;
46 }
47
48 base::Value* DevToolsTracingHandler::Start(
49 const base::DictionaryValue* params) {
50 std::string categories;
51 if (params && params->HasKey("categories"))
52 params->GetString("categories", &categories);
53 TraceController::GetInstance()->BeginTracing(this, categories);
54
55 return base::Value::CreateBooleanValue(true);
56 }
57
58 base::Value* DevToolsTracingHandler::End(
59 const base::DictionaryValue* /* params */) {
60 TraceController::GetInstance()->EndTracingAsync(this);
61
62 return base::Value::CreateBooleanValue(true);
63 }
64
65
66 base::Value* DevToolsTracingHandler::HasCompleted(
67 const base::DictionaryValue* /* params */) {
68
69 return base::Value::CreateBooleanValue(has_completed_);
70 }
71
72 base::Value* DevToolsTracingHandler::GetTraceAndReset(
73 const base::DictionaryValue* /* params */) {
74 std::string ret;
pfeldman 2012/12/14 18:35:05 Since you anyways use append with no pre-allocated
bulach 2012/12/14 19:53:39 tracking the size and reserve'ing..
75 for (std::vector<std::string>::const_iterator i = buffer_.begin();
76 i != buffer_.end(); ++i) {
77 if (!ret.empty())
78 ret.append(",");
79 ret.append(*i);
80 }
81 buffer_.clear();
82 has_completed_ = false;
83
84 return base::Value::CreateStringValue(ret);
85 }
86
87 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698