Index: base/trace_event/startup_tracing.cc |
diff --git a/base/trace_event/startup_tracing.cc b/base/trace_event/startup_tracing.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..06ed8c6e215702f4436107138bd1d7003843266a |
--- /dev/null |
+++ b/base/trace_event/startup_tracing.cc |
@@ -0,0 +1,62 @@ |
+// Copyright (c) 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "base/trace_event/startup_tracing.h" |
+ |
+#include "base/files/file_path.h" |
+#include "base/files/file_util.h" |
+#include "base/path_service.h" |
+#include "base/trace_event/trace_event_impl.h" |
+ |
+namespace base { |
+namespace trace_event { |
+ |
+namespace { |
+ |
+// Trace config file path: |
+// - Android: /data/local/chrome-trace-config.json |
dsinclair
2015/06/11 14:37:08
Why not /data/local/chrome-telemetry/chrome-tracin
Zhen Wang
2015/06/12 01:26:05
Done.
|
+// - POSIX other than Android: $HOME/.chrome-telemetry/chrome-trace-config.json |
+// - Win: %USERPROFILE%/.chrome-telemetry/chrome-trace-config.json |
+#if defined(OS_ANDROID) |
+const FilePath::CharType kAndroidTraceConfigDir[] = |
+ FILE_PATH_LITERAL("/data/local"); |
+#elif defined(OS_POSIX) || defined(OS_WIN) |
+const FilePath::CharType kChromeTelemetryDir[] = |
+ FILE_PATH_LITERAL(".chrome-telemetry"); |
+#endif |
+ |
+#if defined(OS_POSIX) || defined(OS_WIN) |
dsinclair
2015/06/11 14:37:09
Is this ifdef needed? This is always the name of t
Zhen Wang
2015/06/12 01:26:05
This is for the cases where it is neither POSIX no
dsinclair
2015/06/12 14:04:14
I think we can still have those constant defined o
Zhen Wang
2015/06/12 15:41:34
OK. defined is now removed.
|
+const FilePath::CharType kTraceConfigFileName[] = |
+ FILE_PATH_LITERAL("chrome-trace-config.json"); |
+#endif |
+ |
+FilePath GetTraceConfigFilePath() { |
+#if defined(OS_ANDROID) |
+ FilePath path(kAndroidTraceConfigDir); |
+ path = path.Append(kTraceConfigFileName); |
+#elif defined(OS_POSIX) || defined(OS_WIN) |
+ FilePath path; |
+ PathService::Get(DIR_HOME, &path); |
+ path = path.Append(kChromeTelemetryDir); |
+ path = path.Append(kTraceConfigFileName); |
+#else |
+ FilePath path; |
dsinclair
2015/06/11 14:37:09
Should this log a warning that the config file pat
Zhen Wang
2015/06/12 01:26:05
This is for the cases where it is neither POSIX no
|
+#endif |
+ return path; |
+} |
+ |
+} // namespace |
+ |
+void EnableStartupTracingFromConfigFile() { |
dsinclair
2015/06/11 14:37:09
This seems slightly misnamed?
EnableStartupTracin
Zhen Wang
2015/06/12 01:26:05
Makes sense. Renamed.
|
+ base::FilePath trace_config_file_path = GetTraceConfigFilePath(); |
+ if (!trace_config_file_path.empty() && PathExists(trace_config_file_path)) { |
dsinclair
2015/06/11 14:37:09
if (trace_config_file_path.empty() || !PathExists(
Zhen Wang
2015/06/12 01:26:05
Done.
|
+ std::string trace_config_str; |
+ base::ReadFileToString(trace_config_file_path, &trace_config_str); |
dsinclair
2015/06/11 14:37:09
Can this fail?
Zhen Wang
2015/06/12 01:26:05
Thanks for catching this. Now checking the return
|
+ TraceConfig trace_config(trace_config_str); |
dsinclair
2015/06/11 14:37:09
Was TraceConfig converted over to SafeJSONReader?
Zhen Wang
2015/06/12 01:26:05
No. It still uses normal json reader. So the decis
|
+ TraceLog::GetInstance()->SetEnabled(trace_config, TraceLog::RECORDING_MODE); |
+ } |
+} |
+ |
+} // namespace trace_event |
+} // namespace base |