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

Unified Diff: components/tracing/startup_tracing.cc

Issue 1177853003: [Startup Tracing] Enable startup tracing from config file (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add startup tracing to mojo common BUILD.gn Created 5 years, 6 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_nacl.gyp » ('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..e3946f0cf5b901e4c6e624f538a5c9c22a512c1f
--- /dev/null
+++ b/components/tracing/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 "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 {
+
+// 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 (trace_config_file_path.empty()
dsinclair 2015/06/15 13:49:45 This can never be empty given the above always app
Zhen Wang 2015/06/15 16:58:30 Done.
+ || !base::PathExists(trace_config_file_path))
+ return;
+
+ std::string trace_config_str;
+ if (!base::ReadFileToString(trace_config_file_path, &trace_config_str))
dsinclair 2015/06/15 13:49:45 Should we verify the file size before reading? Cou
nednguyen 2015/06/15 15:03:39 Looks like there is a ReadFileToString with a max
Zhen Wang 2015/06/15 16:58:30 Done.
+ 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_nacl.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698