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 <string> | |
6 #include <vector> | |
7 | |
5 #include "chrome/test/chromedriver/performance_logger.h" | 8 #include "chrome/test/chromedriver/performance_logger.h" |
6 | 9 |
7 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
8 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
9 #include "base/values.h" | 12 #include "base/values.h" |
10 #include "chrome/test/chromedriver/chrome/devtools_client.h" | 13 #include "chrome/test/chromedriver/chrome/devtools_client.h" |
11 #include "chrome/test/chromedriver/chrome/devtools_client_impl.h" | 14 #include "chrome/test/chromedriver/chrome/devtools_client_impl.h" |
12 #include "chrome/test/chromedriver/chrome/log.h" | 15 #include "chrome/test/chromedriver/chrome/log.h" |
13 #include "chrome/test/chromedriver/chrome/status.h" | 16 #include "chrome/test/chromedriver/chrome/status.h" |
14 | 17 |
15 namespace { | 18 namespace { |
16 | 19 |
17 // DevTools event domain prefixes to intercept. | 20 // DevTools event domain prefixes to intercept. |
18 const char* const kDomains[] = {"Network.", "Page.", "Timeline."}; | 21 const char* const kDomains[] = {"Network.", "Page.", "Timeline."}; |
19 | 22 |
20 const char* const kDomainEnableCommands[] = { | |
21 "Network.enable", "Page.enable", "Timeline.start" | |
22 }; | |
23 | |
24 // Returns whether the event belongs to one of kDomains. | 23 // Returns whether the event belongs to one of kDomains. |
25 bool ShouldLogEvent(const std::string& method) { | 24 bool ShouldLogEvent(const std::string& method) { |
26 for (size_t i_domain = 0; i_domain < arraysize(kDomains); ++i_domain) { | 25 for (size_t i_domain = 0; i_domain < arraysize(kDomains); ++i_domain) { |
27 if (StartsWithASCII(method, kDomains[i_domain], true /* case_sensitive */)) | 26 if (StartsWithASCII(method, kDomains[i_domain], true /* case_sensitive */)) |
28 return true; | 27 return true; |
29 } | 28 } |
30 return false; | 29 return false; |
31 } | 30 } |
32 | 31 |
33 } // namespace | 32 } // namespace |
34 | 33 |
35 PerformanceLogger::PerformanceLogger(Log* log) | 34 PerformanceLogger::PerformanceLogger(Log* log) |
36 : log_(log) {} | 35 : log_(log) {} |
37 | 36 |
37 PerformanceLogger::PerformanceLogger(Log* log, const PerfLoggingPrefs& prefs) | |
38 : log_(log), | |
39 prefs_(prefs) { | |
40 if (prefs_.trace_categories != "") { | |
samuong
2014/08/04 06:08:22
!prefs_.trace_categories.empty()
johnmoore
2014/08/04 17:37:58
Done.
| |
41 LOG(WARNING) << "Ignoring trace categories because tracing support not yet " | |
42 << "implemented: " << prefs_.trace_categories; | |
43 prefs_.trace_categories = ""; | |
44 } | |
45 } | |
46 | |
38 bool PerformanceLogger::subscribes_to_browser() { | 47 bool PerformanceLogger::subscribes_to_browser() { |
39 return true; | 48 return true; |
40 } | 49 } |
41 | 50 |
42 Status PerformanceLogger::OnConnected(DevToolsClient* client) { | 51 Status PerformanceLogger::OnConnected(DevToolsClient* client) { |
43 if (client->GetId() == DevToolsClientImpl::kBrowserwideDevToolsClientId) { | 52 if (client->GetId() == DevToolsClientImpl::kBrowserwideDevToolsClientId) { |
44 // TODO(johnmoore): Implement tracing log. | 53 // TODO(johnmoore): Implement tracing log. |
45 return Status(kOk); | 54 return Status(kOk); |
46 } | 55 } |
47 base::DictionaryValue params; // All our enable commands have empty params. | 56 std::vector<std::string> enable_commands; |
48 for (size_t i_cmd = 0; i_cmd < arraysize(kDomainEnableCommands); ++i_cmd) { | 57 if (PerfLoggingPrefs::IsEnabled(prefs_.network)) |
49 Status status = client->SendCommand(kDomainEnableCommands[i_cmd], params); | 58 enable_commands.push_back("Network.enable"); |
59 if (PerfLoggingPrefs::IsEnabled(prefs_.page)) | |
60 enable_commands.push_back("Page.enable"); | |
61 if (PerfLoggingPrefs::IsEnabled(prefs_.timeline)) { | |
62 // Timeline feed implicitly disabled when trace categories are specified. | |
63 // So even if kDefaultEnabled, don't enable unless empty |trace_categories|. | |
64 if (prefs_.trace_categories == "" || prefs_.timeline == | |
samuong
2014/08/04 06:08:22
use prefs_.trace_categories.empty()
johnmoore
2014/08/04 17:37:58
Done.
| |
65 PerfLoggingPrefs::InspectorDomainStatus::kExplicitlyEnabled) | |
66 enable_commands.push_back("Timeline.start"); | |
67 } | |
68 for (std::vector<std::string>::const_iterator it = enable_commands.begin(); | |
69 it != enable_commands.end(); ++it) { | |
70 base::DictionaryValue params; // All the enable commands have empty params. | |
71 Status status = client->SendCommand(*it, params); | |
50 if (status.IsError()) | 72 if (status.IsError()) |
51 return status; | 73 return status; |
52 } | 74 } |
53 return Status(kOk); | 75 return Status(kOk); |
54 } | 76 } |
55 | 77 |
56 Status PerformanceLogger::OnEvent( | 78 Status PerformanceLogger::OnEvent( |
57 DevToolsClient* client, | 79 DevToolsClient* client, |
58 const std::string& method, | 80 const std::string& method, |
59 const base::DictionaryValue& params) { | 81 const base::DictionaryValue& params) { |
(...skipping 10 matching lines...) Expand all Loading... | |
70 base::JSONWriter::Write(&log_message_dict, &log_message_json); | 92 base::JSONWriter::Write(&log_message_dict, &log_message_json); |
71 | 93 |
72 log_->AddEntry(Log::kInfo, log_message_json); | 94 log_->AddEntry(Log::kInfo, log_message_json); |
73 return Status(kOk); | 95 return Status(kOk); |
74 } | 96 } |
75 | 97 |
76 // TODO(johnmoore): Use BeforeCommand to implement tracing log. | 98 // TODO(johnmoore): Use BeforeCommand to implement tracing log. |
77 Status PerformanceLogger::BeforeCommand(const std::string& command_name) { | 99 Status PerformanceLogger::BeforeCommand(const std::string& command_name) { |
78 return Status(kOk); | 100 return Status(kOk); |
79 } | 101 } |
OLD | NEW |