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

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: 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..06ed8c6e215702f4436107138bd1d7003843266a
--- /dev/null
+++ b/base/trace_event/startup_tracing.cc
@@ -0,0 +1,62 @@
+// 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-trace-config.json
dsinclair 2015/06/11 14:37:08 Why not /data/local/chrome-telemetry/chrome-tracin
Zhen Wang 2015/06/12 01:26:05 Done.
+// - POSIX other than Android: $HOME/.chrome-telemetry/chrome-trace-config.json
+// - Win: %USERPROFILE%/.chrome-telemetry/chrome-trace-config.json
+#if defined(OS_ANDROID)
+const FilePath::CharType kAndroidTraceConfigDir[] =
+ FILE_PATH_LITERAL("/data/local");
+#elif defined(OS_POSIX) || defined(OS_WIN)
+const FilePath::CharType kChromeTelemetryDir[] =
+ FILE_PATH_LITERAL(".chrome-telemetry");
+#endif
+
+#if defined(OS_POSIX) || defined(OS_WIN)
dsinclair 2015/06/11 14:37:09 Is this ifdef needed? This is always the name of t
Zhen Wang 2015/06/12 01:26:05 This is for the cases where it is neither POSIX no
dsinclair 2015/06/12 14:04:14 I think we can still have those constant defined o
Zhen Wang 2015/06/12 15:41:34 OK. defined is now removed.
+const FilePath::CharType kTraceConfigFileName[] =
+ FILE_PATH_LITERAL("chrome-trace-config.json");
+#endif
+
+FilePath GetTraceConfigFilePath() {
+#if defined(OS_ANDROID)
+ FilePath path(kAndroidTraceConfigDir);
+ path = path.Append(kTraceConfigFileName);
+#elif defined(OS_POSIX) || defined(OS_WIN)
+ FilePath path;
+ PathService::Get(DIR_HOME, &path);
+ path = path.Append(kChromeTelemetryDir);
+ path = path.Append(kTraceConfigFileName);
+#else
+ FilePath path;
dsinclair 2015/06/11 14:37:09 Should this log a warning that the config file pat
Zhen Wang 2015/06/12 01:26:05 This is for the cases where it is neither POSIX no
+#endif
+ return path;
+}
+
+} // namespace
+
+void EnableStartupTracingFromConfigFile() {
dsinclair 2015/06/11 14:37:09 This seems slightly misnamed? EnableStartupTracin
Zhen Wang 2015/06/12 01:26:05 Makes sense. Renamed.
+ base::FilePath trace_config_file_path = GetTraceConfigFilePath();
+ if (!trace_config_file_path.empty() && PathExists(trace_config_file_path)) {
dsinclair 2015/06/11 14:37:09 if (trace_config_file_path.empty() || !PathExists(
Zhen Wang 2015/06/12 01:26:05 Done.
+ std::string trace_config_str;
+ base::ReadFileToString(trace_config_file_path, &trace_config_str);
dsinclair 2015/06/11 14:37:09 Can this fail?
Zhen Wang 2015/06/12 01:26:05 Thanks for catching this. Now checking the return
+ TraceConfig trace_config(trace_config_str);
dsinclair 2015/06/11 14:37:09 Was TraceConfig converted over to SafeJSONReader?
Zhen Wang 2015/06/12 01:26:05 No. It still uses normal json reader. So the decis
+ 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