OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "components/tracing/startup_tracing.h" |
| 6 |
| 7 #include "base/files/file_path.h" |
| 8 #include "base/files/file_util.h" |
| 9 #include "base/path_service.h" |
| 10 #include "base/trace_event/trace_event.h" |
| 11 |
| 12 namespace tracing { |
| 13 |
| 14 namespace { |
| 15 |
| 16 // Maximum trace config file size that will be loaded, in bytes. |
| 17 const size_t kTraceConfigFileSizeLimit = 64 * 1024; |
| 18 |
| 19 // Trace config file path: |
| 20 // - Android: /data/local/.config/chrome-trace-config.json |
| 21 // - POSIX other than Android: $HOME/.config/chrome-trace-config.json |
| 22 // - Win: %USERPROFILE%/.config/chrome-trace-config.json |
| 23 #if defined(OS_ANDROID) |
| 24 const base::FilePath::CharType kAndroidTraceConfigDir[] = |
| 25 FILE_PATH_LITERAL("/data/local"); |
| 26 #endif |
| 27 |
| 28 const base::FilePath::CharType kChromeConfigDir[] = |
| 29 FILE_PATH_LITERAL(".config"); |
| 30 const base::FilePath::CharType kTraceConfigFileName[] = |
| 31 FILE_PATH_LITERAL("chrome-trace-config.json"); |
| 32 |
| 33 base::FilePath GetTraceConfigFilePath() { |
| 34 #if defined(OS_ANDROID) |
| 35 base::FilePath path(kAndroidTraceConfigDir); |
| 36 #elif defined(OS_POSIX) || defined(OS_WIN) |
| 37 base::FilePath path; |
| 38 PathService::Get(base::DIR_HOME, &path); |
| 39 #else |
| 40 base::FilePath path; |
| 41 #endif |
| 42 path = path.Append(kChromeConfigDir); |
| 43 path = path.Append(kTraceConfigFileName); |
| 44 return path; |
| 45 } |
| 46 |
| 47 } // namespace |
| 48 |
| 49 void EnableStartupTracingIfConfigFileExists() { |
| 50 base::FilePath trace_config_file_path = GetTraceConfigFilePath(); |
| 51 if (!base::PathExists(trace_config_file_path)) |
| 52 return; |
| 53 |
| 54 std::string trace_config_str; |
| 55 if (!base::ReadFileToString(trace_config_file_path, |
| 56 &trace_config_str, |
| 57 kTraceConfigFileSizeLimit)) { |
| 58 return; |
| 59 } |
| 60 |
| 61 base::trace_event::TraceConfig trace_config(trace_config_str); |
| 62 base::trace_event::TraceLog::GetInstance()->SetEnabled( |
| 63 trace_config, base::trace_event::TraceLog::RECORDING_MODE); |
| 64 } |
| 65 |
| 66 } // namespace tracing |
OLD | NEW |