Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/devtools_tracing_handler.h" | 5 #include "content/browser/devtools/devtools_tracing_handler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/string_split.h" | |
| 11 #include "base/values.h" | 12 #include "base/values.h" |
| 12 #include "content/browser/devtools/devtools_http_handler_impl.h" | 13 #include "content/browser/devtools/devtools_http_handler_impl.h" |
| 13 #include "content/public/browser/trace_controller.h" | 14 #include "content/public/browser/trace_controller.h" |
| 14 #include "content/public/browser/trace_subscriber.h" | 15 #include "content/public/browser/trace_subscriber.h" |
| 15 | 16 |
| 16 namespace content { | 17 namespace content { |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 20 const char kTracingStartCommand[] = "Tracing.start"; | 21 const char kTracingStartCommand[] = "Tracing.start"; |
| 21 const char kTracingEndCommand[] = "Tracing.end"; | 22 const char kTracingEndCommand[] = "Tracing.end"; |
| 22 | 23 |
| 23 const char kTracingCompleteNotification[] = "Tracing.tracingComplete"; | 24 const char kTracingCompleteNotification[] = "Tracing.tracingComplete"; |
| 24 const char kTracingDataCollected[] = "Tracing.dataCollected"; | 25 const char kTracingDataCollected[] = "Tracing.dataCollected"; |
| 25 | 26 |
| 26 const char kCategoriesParam[] = "categories"; | 27 const char kCategoriesParam[] = "categories"; |
| 27 | 28 |
| 29 const char kTraceOptionsParam[] = "trace-options"; | |
| 30 const char kRecordUntilFull[] = "record-until-full"; | |
| 31 | |
| 28 } // namespace | 32 } // namespace |
| 29 | 33 |
| 30 const char DevToolsTracingHandler::kDomain[] = "Tracing"; | 34 const char DevToolsTracingHandler::kDomain[] = "Tracing"; |
| 31 | 35 |
| 32 DevToolsTracingHandler::DevToolsTracingHandler() | 36 DevToolsTracingHandler::DevToolsTracingHandler() |
| 33 : is_running_(false) { | 37 : is_running_(false) { |
| 34 RegisterCommandHandler(kTracingStartCommand, | 38 RegisterCommandHandler(kTracingStartCommand, |
| 35 base::Bind(&DevToolsTracingHandler::OnStart, | 39 base::Bind(&DevToolsTracingHandler::OnStart, |
| 36 base::Unretained(this))); | 40 base::Unretained(this))); |
| 37 RegisterCommandHandler(kTracingEndCommand, | 41 RegisterCommandHandler(kTracingEndCommand, |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 49 | 53 |
| 50 void DevToolsTracingHandler::OnTraceDataCollected( | 54 void DevToolsTracingHandler::OnTraceDataCollected( |
| 51 const scoped_refptr<base::RefCountedString>& trace_fragment) { | 55 const scoped_refptr<base::RefCountedString>& trace_fragment) { |
| 52 if (is_running_) { | 56 if (is_running_) { |
| 53 base::DictionaryValue* params = new base::DictionaryValue(); | 57 base::DictionaryValue* params = new base::DictionaryValue(); |
| 54 params->SetString("value", trace_fragment->data()); | 58 params->SetString("value", trace_fragment->data()); |
| 55 SendNotification(kTracingDataCollected, params); | 59 SendNotification(kTracingDataCollected, params); |
| 56 } | 60 } |
| 57 } | 61 } |
| 58 | 62 |
| 63 // Note, if you add more options here you also need to update: | |
| 64 // base/debug/trace_event_impl:TraceOptionsFromString | |
| 65 int DevToolsTracingHandler::TraceOptionsFromString(const std::string& options) { | |
| 66 std::vector<std::string> split; | |
| 67 std::vector<std::string>::iterator iter; | |
| 68 int ret = 0; | |
| 69 | |
| 70 base::SplitString(options, ',', &split); | |
| 71 for (iter = split.begin(); iter != split.end(); ++iter) { | |
| 72 if (*iter == kRecordUntilFull) { | |
|
pfeldman
2013/02/21 16:33:05
Do you need to trim it before comparison?
dsinclair
2013/02/21 16:35:59
SplitString will trim leading and trailing whitesp
| |
| 73 ret |= base::debug::TraceLog::RECORD_UNTIL_FULL; | |
| 74 } | |
| 75 } | |
| 76 if (ret == 0) | |
| 77 ret = base::debug::TraceLog::RECORD_UNTIL_FULL; | |
| 78 | |
| 79 return ret; | |
|
pfeldman
2013/02/21 16:33:05
Not sure I follow, but it sounds like it always re
dsinclair
2013/02/21 16:35:59
It does at the moment. I have another patch in the
| |
| 80 } | |
| 81 | |
| 59 scoped_ptr<DevToolsProtocol::Response> | 82 scoped_ptr<DevToolsProtocol::Response> |
| 60 DevToolsTracingHandler::OnStart(DevToolsProtocol::Command* command) { | 83 DevToolsTracingHandler::OnStart(DevToolsProtocol::Command* command) { |
| 61 std::string categories; | 84 std::string categories; |
| 62 base::DictionaryValue* params = command->params(); | 85 base::DictionaryValue* params = command->params(); |
| 63 if (params && params->HasKey(kCategoriesParam)) | 86 if (params && params->HasKey(kCategoriesParam)) |
| 64 params->GetString(kCategoriesParam, &categories); | 87 params->GetString(kCategoriesParam, &categories); |
| 65 TraceController::GetInstance()->BeginTracing(this, categories); | 88 |
| 89 int options = base::debug::TraceLog::RECORD_UNTIL_FULL; | |
| 90 if (params && params->HasKey(kTraceOptionsParam)) { | |
| 91 std::string options_param; | |
| 92 params->GetString(kTraceOptionsParam, &options_param); | |
| 93 options = TraceOptionsFromString(options_param); | |
| 94 } | |
| 95 | |
| 96 TraceController::GetInstance()->BeginTracing(this, categories, options); | |
| 66 is_running_ = true; | 97 is_running_ = true; |
| 67 return command->SuccessResponse(NULL); | 98 return command->SuccessResponse(NULL); |
| 68 } | 99 } |
| 69 | 100 |
| 70 | 101 |
| 71 scoped_ptr<DevToolsProtocol::Response> | 102 scoped_ptr<DevToolsProtocol::Response> |
| 72 DevToolsTracingHandler::OnEnd(DevToolsProtocol::Command* command) { | 103 DevToolsTracingHandler::OnEnd(DevToolsProtocol::Command* command) { |
| 73 TraceController::GetInstance()->EndTracingAsync(this); | 104 TraceController::GetInstance()->EndTracingAsync(this); |
| 74 return command->SuccessResponse(NULL); | 105 return command->SuccessResponse(NULL); |
| 75 } | 106 } |
| 76 | 107 |
| 77 } // namespace content | 108 } // namespace content |
| OLD | NEW |