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 "chrome/test/chromedriver/performance_logger.h" | 5 #include "chrome/test/chromedriver/performance_logger.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 for (auto* domain : kDomains) { | 54 for (auto* domain : kDomains) { |
55 if (base::StartsWith(method, domain, base::CompareCase::SENSITIVE)) | 55 if (base::StartsWith(method, domain, base::CompareCase::SENSITIVE)) |
56 return true; | 56 return true; |
57 } | 57 } |
58 return false; | 58 return false; |
59 } | 59 } |
60 | 60 |
61 } // namespace | 61 } // namespace |
62 | 62 |
63 PerformanceLogger::PerformanceLogger(Log* log, const Session* session) | 63 PerformanceLogger::PerformanceLogger(Log* log, const Session* session) |
64 : log_(log), | 64 : BaseLogger(log), |
65 session_(session), | 65 session_(session), |
66 browser_client_(nullptr), | 66 browser_client_(nullptr), |
67 trace_buffering_(false) {} | 67 trace_buffering_(false) {} |
68 | 68 |
69 PerformanceLogger::PerformanceLogger(Log* log, | 69 PerformanceLogger::PerformanceLogger(Log* log, |
70 const Session* session, | 70 const Session* session, |
71 const PerfLoggingPrefs& prefs) | 71 const PerfLoggingPrefs& prefs) |
72 : log_(log), | 72 : BaseLogger(log), |
73 session_(session), | 73 session_(session), |
74 prefs_(prefs), | 74 prefs_(prefs), |
75 browser_client_(nullptr), | 75 browser_client_(nullptr), |
76 trace_buffering_(false) {} | 76 trace_buffering_(false) {} |
77 | 77 |
78 bool PerformanceLogger::subscribes_to_browser() { | 78 bool PerformanceLogger::subscribes_to_browser() { |
79 return true; | 79 return true; |
80 } | 80 } |
81 | 81 |
82 Status PerformanceLogger::OnConnected(DevToolsClient* client) { | 82 Status PerformanceLogger::OnConnected(DevToolsClient* client) { |
(...skipping 20 matching lines...) Expand all Loading... |
103 Status PerformanceLogger::BeforeCommand(const std::string& command_name) { | 103 Status PerformanceLogger::BeforeCommand(const std::string& command_name) { |
104 // Only dump trace buffer after tracing has been started. | 104 // Only dump trace buffer after tracing has been started. |
105 if (trace_buffering_ && ShouldRequestTraceEvents(command_name)) { | 105 if (trace_buffering_ && ShouldRequestTraceEvents(command_name)) { |
106 Status status = CollectTraceEvents(); | 106 Status status = CollectTraceEvents(); |
107 if (status.IsError()) | 107 if (status.IsError()) |
108 return status; | 108 return status; |
109 } | 109 } |
110 return Status(kOk); | 110 return Status(kOk); |
111 } | 111 } |
112 | 112 |
113 void PerformanceLogger::AddLogEntry( | |
114 Log::Level level, | |
115 const std::string& webview, | |
116 const std::string& method, | |
117 const base::DictionaryValue& params) { | |
118 base::DictionaryValue log_message_dict; | |
119 log_message_dict.SetString("webview", webview); | |
120 log_message_dict.SetString("message.method", method); | |
121 log_message_dict.Set("message.params", params.DeepCopy()); | |
122 std::string log_message_json; | |
123 base::JSONWriter::Write(log_message_dict, &log_message_json); | |
124 | |
125 // TODO(klm): extract timestamp from params? | |
126 // Look at where it is for Page, Network, Timeline, and trace events. | |
127 log_->AddEntry(level, log_message_json); | |
128 } | |
129 | |
130 void PerformanceLogger::AddLogEntry( | |
131 const std::string& webview, | |
132 const std::string& method, | |
133 const base::DictionaryValue& params) { | |
134 AddLogEntry(Log::kInfo, webview, method, params); | |
135 } | |
136 | |
137 Status PerformanceLogger::EnableInspectorDomains(DevToolsClient* client) { | 113 Status PerformanceLogger::EnableInspectorDomains(DevToolsClient* client) { |
138 std::vector<std::string> enable_commands; | 114 std::vector<std::string> enable_commands; |
139 if (IsEnabled(prefs_.network)) | 115 if (IsEnabled(prefs_.network)) |
140 enable_commands.push_back("Network.enable"); | 116 enable_commands.push_back("Network.enable"); |
141 if (IsEnabled(prefs_.page)) | 117 if (IsEnabled(prefs_.page)) |
142 enable_commands.push_back("Page.enable"); | 118 enable_commands.push_back("Page.enable"); |
143 if (IsEnabled(prefs_.timeline)) { | 119 if (IsEnabled(prefs_.timeline)) { |
144 // Timeline feed implicitly disabled when trace categories are specified. | 120 // Timeline feed implicitly disabled when trace categories are specified. |
145 // So even if kDefaultEnabled, don't enable unless empty |trace_categories|. | 121 // So even if kDefaultEnabled, don't enable unless empty |trace_categories|. |
146 if (prefs_.trace_categories.empty() || prefs_.timeline == | 122 if (prefs_.trace_categories.empty() || prefs_.timeline == |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 if (status.IsError()) | 249 if (status.IsError()) |
274 return status; | 250 return status; |
275 | 251 |
276 return StartTrace(); | 252 return StartTrace(); |
277 } | 253 } |
278 | 254 |
279 Status PerformanceLogger::IsTraceDone(bool* trace_done) const { | 255 Status PerformanceLogger::IsTraceDone(bool* trace_done) const { |
280 *trace_done = !trace_buffering_; | 256 *trace_done = !trace_buffering_; |
281 return Status(kOk); | 257 return Status(kOk); |
282 } | 258 } |
OLD | NEW |