| Index: components/tracing/startup_tracing.cc
|
| diff --git a/components/tracing/startup_tracing.cc b/components/tracing/startup_tracing.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..321b95092a43ef15857474cf3474dafb0d3e1d7b
|
| --- /dev/null
|
| +++ b/components/tracing/startup_tracing.cc
|
| @@ -0,0 +1,66 @@
|
| +// 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 "components/tracing/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.h"
|
| +
|
| +namespace tracing {
|
| +
|
| +namespace {
|
| +
|
| +// Maximum trace config file size that will be loaded, in bytes.
|
| +const size_t kTraceConfigFileSizeLimit = 64 * 1024;
|
| +
|
| +// Trace config file path:
|
| +// - Android: /data/local/.config/chrome-trace-config.json
|
| +// - POSIX other than Android: $HOME/.config/chrome-trace-config.json
|
| +// - Win: %USERPROFILE%/.config/chrome-trace-config.json
|
| +#if defined(OS_ANDROID)
|
| +const base::FilePath::CharType kAndroidTraceConfigDir[] =
|
| + FILE_PATH_LITERAL("/data/local");
|
| +#endif
|
| +
|
| +const base::FilePath::CharType kChromeConfigDir[] =
|
| + FILE_PATH_LITERAL(".config");
|
| +const base::FilePath::CharType kTraceConfigFileName[] =
|
| + FILE_PATH_LITERAL("chrome-trace-config.json");
|
| +
|
| +base::FilePath GetTraceConfigFilePath() {
|
| +#if defined(OS_ANDROID)
|
| + base::FilePath path(kAndroidTraceConfigDir);
|
| +#elif defined(OS_POSIX) || defined(OS_WIN)
|
| + base::FilePath path;
|
| + PathService::Get(base::DIR_HOME, &path);
|
| +#else
|
| + base::FilePath path;
|
| +#endif
|
| + path = path.Append(kChromeConfigDir);
|
| + path = path.Append(kTraceConfigFileName);
|
| + return path;
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +void EnableStartupTracingIfConfigFileExists() {
|
| + base::FilePath trace_config_file_path = GetTraceConfigFilePath();
|
| + if (!base::PathExists(trace_config_file_path))
|
| + return;
|
| +
|
| + std::string trace_config_str;
|
| + if (!base::ReadFileToString(trace_config_file_path,
|
| + &trace_config_str,
|
| + kTraceConfigFileSizeLimit)) {
|
| + return;
|
| + }
|
| +
|
| + base::trace_event::TraceConfig trace_config(trace_config_str);
|
| + base::trace_event::TraceLog::GetInstance()->SetEnabled(
|
| + trace_config, base::trace_event::TraceLog::RECORDING_MODE);
|
| +}
|
| +
|
| +} // namespace tracing
|
|
|