Chromium Code Reviews| 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..4b24d0c38227f45dff2b649cf15f6d2786649840 |
| --- /dev/null |
| +++ b/base/trace_event/startup_tracing.cc |
| @@ -0,0 +1,61 @@ |
| +// 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-telemetry/chrome-trace-config.json |
| +// - POSIX other than Android: $HOME/.chrome-telemetry/chrome-trace-config.json |
| +// - Win: %USERPROFILE%/.chrome-telemetry/chrome-trace-config.json |
|
nednguyen
2015/06/12 20:12:18
I am not sure whether putting the name "telemetry"
Zhen Wang
2015/06/13 03:48:03
Now changed to .config, which is the convention. h
|
| +#if defined(OS_ANDROID) |
| +const FilePath::CharType kAndroidTraceConfigDir[] = |
| + FILE_PATH_LITERAL("/data/local"); |
| +#endif |
| + |
| +const FilePath::CharType kChromeTelemetryDir[] = |
| + FILE_PATH_LITERAL(".chrome-telemetry"); |
| +const FilePath::CharType kTraceConfigFileName[] = |
| + FILE_PATH_LITERAL("chrome-trace-config.json"); |
| + |
| +FilePath GetTraceConfigFilePath() { |
| +#if defined(OS_ANDROID) |
| + FilePath path(kAndroidTraceConfigDir); |
| +#elif defined(OS_POSIX) || defined(OS_WIN) |
| + FilePath path; |
| + PathService::Get(DIR_HOME, &path); |
| +#else |
| + FilePath path; |
| +#endif |
| + path = path.Append(kChromeTelemetryDir); |
| + path = path.Append(kTraceConfigFileName); |
| + return path; |
| +} |
| + |
| +} // namespace |
| + |
| +void EnableStartupTracingIfConfigFileExists() { |
| + FilePath trace_config_file_path = GetTraceConfigFilePath(); |
| + if (trace_config_file_path.empty() || !PathExists(trace_config_file_path)) |
| + return; |
| + |
| + std::string trace_config_str; |
| + if (!ReadFileToString(trace_config_file_path, &trace_config_str)) |
| + return; |
| + |
| + TraceConfig trace_config(trace_config_str); |
| + TraceLog::GetInstance()->SetEnabled(trace_config, TraceLog::RECORDING_MODE); |
| +} |
| + |
| +} // namespace trace_event |
| +} // namespace base |