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