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

Unified Diff: base/trace_event/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: review fix 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 | « base/trace_event/startup_tracing.h ('k') | base/trace_event/trace_event.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « base/trace_event/startup_tracing.h ('k') | base/trace_event/trace_event.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698