OLD | NEW |
| (Empty) |
1 // Copyright (c) 2015 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 #ifndef COMPONENTS_TRACING_BROWSER_TRACE_CONFIG_FILE_H_ | |
6 #define COMPONENTS_TRACING_BROWSER_TRACE_CONFIG_FILE_H_ | |
7 | |
8 #include "base/files/file_path.h" | |
9 #include "base/macros.h" | |
10 #include "base/trace_event/trace_config.h" | |
11 #include "build/build_config.h" | |
12 #include "components/tracing/tracing_export.h" | |
13 | |
14 namespace base { | |
15 template <typename Type> struct DefaultSingletonTraits; | |
16 } // namespace base | |
17 | |
18 namespace tracing { | |
19 | |
20 // TraceConfigFile is a singleton that contains the configurations of tracing. | |
21 // One can create a trace config file and use it to configure startup and/or | |
22 // shutdown tracing. | |
23 // | |
24 // The trace config file should be JSON formated. One example is: | |
25 // { | |
26 // "trace_config": { | |
27 // "record_mode": "record-until-full", | |
28 // "included_categories": ["cc", "skia"] | |
29 // }, | |
30 // "startup_duration": 5, | |
31 // "result_file": "chrometrace.log" | |
32 // } | |
33 // | |
34 // trace_config: The configuration of tracing. Please see the details in | |
35 // base/trace_event/trace_config.h. | |
36 // | |
37 // startup_duration: The duration for startup tracing in terms of seconds. | |
38 // Tracing will stop automatically after the duration. If this | |
39 // value is not specified, the duration is 0 and one needs | |
40 // to stop tracing by other ways, e.g., by DevTools, or get | |
41 // the result file after shutting the browser down. | |
42 // | |
43 // result_file: The file that contains the trace log. The default result | |
44 // file path is chrometrace.log. Chrome will dump the trace | |
45 // log to this file | |
46 // 1) after startup_duration if it is specified; | |
47 // 2) or after browser shutdown if startup duration is 0. | |
48 // One can also stop tracing and get the result by other ways, | |
49 // e.g., by DevTools. In that case, the trace log will not be | |
50 // saved to this file. | |
51 // Notice: This is not supported on Android. The result file | |
52 // path will be generated by tracing controller. | |
53 // | |
54 // The trace config file can be specified by the --trace-config-file flag on | |
55 // most platforms except on Android, e.g., --trace-config-file=path/to/file/. | |
56 // This flag should not be used with --trace-startup or --trace-shutdown. If | |
57 // those two flags are used, --trace-config-file flag will be ignored. If the | |
58 // --trace-config-file flag is used without the file path, Chrome will do | |
59 // startup tracing with 5 seconds' startup duration. | |
60 // | |
61 // On Android, Chrome does not read the --trace-config-file flag, because not | |
62 // all Chrome based browsers read customized flag, e.g., Android WebView. Chrome | |
63 // on Android reads from a fixed file location: | |
64 // /data/local/chrome-trace-config.json | |
65 // If this file exists, Chrome will start tracing according to the configuration | |
66 // specified in the file, otherwise, Chrome will not start tracing. | |
67 class TRACING_EXPORT TraceConfigFile { | |
68 public: | |
69 static TraceConfigFile* GetInstance(); | |
70 | |
71 bool IsEnabled() const; | |
72 base::trace_event::TraceConfig GetTraceConfig() const; | |
73 int GetStartupDuration() const; | |
74 #if !defined(OS_ANDROID) | |
75 base::FilePath GetResultFile() const; | |
76 #endif | |
77 | |
78 private: | |
79 // This allows constructor and destructor to be private and usable only | |
80 // by the Singleton class. | |
81 friend struct base::DefaultSingletonTraits<TraceConfigFile>; | |
82 TraceConfigFile(); | |
83 ~TraceConfigFile(); | |
84 | |
85 bool ParseTraceConfigFileContent(const std::string& content); | |
86 | |
87 bool is_enabled_; | |
88 base::trace_event::TraceConfig trace_config_; | |
89 int startup_duration_; | |
90 base::FilePath result_file_; | |
91 | |
92 DISALLOW_COPY_AND_ASSIGN(TraceConfigFile); | |
93 }; | |
94 | |
95 } // namespace tracing | |
96 | |
97 #endif // COMPONENTS_TRACING_BROWSER_TRACE_CONFIG_FILE_H_ | |
OLD | NEW |