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 #ifndef CHROME_TEST_CHROMEDRIVER_PERFORMANCE_LOGGER_H_ | 5 #ifndef CHROME_TEST_CHROMEDRIVER_PERFORMANCE_LOGGER_H_ |
6 #define CHROME_TEST_CHROMEDRIVER_PERFORMANCE_LOGGER_H_ | 6 #define CHROME_TEST_CHROMEDRIVER_PERFORMANCE_LOGGER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "chrome/test/chromedriver/capabilities.h" | 12 #include "chrome/test/chromedriver/capabilities.h" |
13 #include "chrome/test/chromedriver/chrome/devtools_event_listener.h" | 13 #include "chrome/test/chromedriver/chrome/devtools_event_listener.h" |
14 #include "chrome/test/chromedriver/command_listener.h" | 14 #include "chrome/test/chromedriver/command_listener.h" |
15 | 15 |
16 class Log; | 16 class Log; |
| 17 struct Session; |
17 | 18 |
18 // Translates DevTools profiler events into Log messages with info level. | 19 // Translates DevTools profiler events into Log messages with info level. |
19 // | 20 // |
20 // The message is a JSON string of the following structure: | 21 // The message is a JSON string of the following structure: |
21 // { | 22 // { |
22 // "webview": <originating WebView ID>, | 23 // "webview": <originating WebView ID>, |
23 // "message": { "method": "...", "params": { ... }} // DevTools message. | 24 // "message": { "method": "...", "params": { ... }} // DevTools message. |
24 // } | 25 // } |
| 26 // |
| 27 // Also translates buffered trace events into Log messages of info level with |
| 28 // the same structure if tracing categories are specified. |
| 29 |
25 class PerformanceLogger : public DevToolsEventListener, public CommandListener { | 30 class PerformanceLogger : public DevToolsEventListener, public CommandListener { |
26 public: | 31 public: |
27 // Creates a |PerformanceLogger| with default preferences that creates entries | 32 // Creates a |PerformanceLogger| with default preferences that creates entries |
28 // in the given Log object. The log is owned elsewhere and must not be null. | 33 // in the given Log object. The log is owned elsewhere and must not be null. |
29 explicit PerformanceLogger(Log* log); | 34 PerformanceLogger(Log* log, const Session* session); |
30 | 35 |
31 // Creates a |PerformanceLogger| with specific preferences. | 36 // Creates a |PerformanceLogger| with specific preferences. |
32 PerformanceLogger(Log* log, const PerfLoggingPrefs& prefs); | 37 PerformanceLogger(Log* log, |
| 38 const Session* session, |
| 39 const PerfLoggingPrefs& prefs); |
33 | 40 |
34 // Enables Page,Network,Timeline events for client, which must not be null. | 41 // PerformanceLogger subscribes to browser-wide |DevToolsClient| for tracing. |
| 42 virtual bool subscribes_to_browser() OVERRIDE; |
| 43 |
| 44 // For browser-wide client: enables tracing if trace categories are specified, |
| 45 // sets |browser_client_|. For other clients: calls EnableInspectorDomains. |
35 virtual Status OnConnected(DevToolsClient* client) OVERRIDE; | 46 virtual Status OnConnected(DevToolsClient* client) OVERRIDE; |
36 // Translates an event into a log entry. | 47 |
| 48 // Calls HandleInspectorEvents or HandleTraceEvents depending on client type. |
37 virtual Status OnEvent(DevToolsClient* client, | 49 virtual Status OnEvent(DevToolsClient* client, |
38 const std::string& method, | 50 const std::string& method, |
39 const base::DictionaryValue& params) OVERRIDE; | 51 const base::DictionaryValue& params) OVERRIDE; |
40 | 52 |
| 53 // Before whitelisted commands, if tracing enabled, calls CollectTraceEvents. |
41 virtual Status BeforeCommand(const std::string& command_name) OVERRIDE; | 54 virtual Status BeforeCommand(const std::string& command_name) OVERRIDE; |
42 | 55 |
43 // PerformanceLogger subscribes to browser-wide |DevToolsClient| for tracing. | 56 private: |
44 virtual bool subscribes_to_browser() OVERRIDE; | 57 void AddLogEntry(Log::Level level, |
| 58 const std::string& webview, |
| 59 const std::string& method, |
| 60 const base::DictionaryValue& params); |
45 | 61 |
46 private: | 62 void AddLogEntry(const std::string& webview, |
| 63 const std::string& method, |
| 64 const base::DictionaryValue& params); |
| 65 |
| 66 // Enables Network, Page and Timeline domains according to |PerfLoggingPrefs|. |
| 67 Status EnableInspectorDomains(DevToolsClient* client); |
| 68 |
| 69 // Logs Network, Page, and Timeline events. |
| 70 Status HandleInspectorEvents(DevToolsClient* client, |
| 71 const std::string& method, |
| 72 const base::DictionaryValue& params); |
| 73 |
| 74 // Logs trace events and monitors trace buffer usage. |
| 75 Status HandleTraceEvents(DevToolsClient* client, |
| 76 const std::string& method, |
| 77 const base::DictionaryValue& params); |
| 78 |
| 79 bool ShouldReportTracingError(); |
| 80 Status StartTrace(); // Must not call before browser-wide client connects. |
| 81 Status CollectTraceEvents(); // Ditto. |
| 82 Status IsTraceDone(bool* trace_done) const; // True if trace is not buffering. |
| 83 |
47 Log* log_; // The log where to create entries. | 84 Log* log_; // The log where to create entries. |
| 85 const Session* session_; |
48 PerfLoggingPrefs prefs_; | 86 PerfLoggingPrefs prefs_; |
| 87 DevToolsClient* browser_client_; // Pointer to browser-wide |DevToolsClient|. |
| 88 bool trace_buffering_; // True unless trace stopped and all events received. |
49 | 89 |
50 DISALLOW_COPY_AND_ASSIGN(PerformanceLogger); | 90 DISALLOW_COPY_AND_ASSIGN(PerformanceLogger); |
51 }; | 91 }; |
52 | 92 |
53 #endif // CHROME_TEST_CHROMEDRIVER_PERFORMANCE_LOGGER_H_ | 93 #endif // CHROME_TEST_CHROMEDRIVER_PERFORMANCE_LOGGER_H_ |
OLD | NEW |