Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(961)

Unified Diff: components/tracing/startup_tracing.cc

Issue 1312833007: Revert of Reland [Startup Tracing] Add --trace-config-file flag (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/tracing/startup_tracing.h ('k') | components/tracing/trace_config_file.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « components/tracing/startup_tracing.h ('k') | components/tracing/trace_config_file.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698