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 // Trace config file path: | |
17 // - Android: /data/local/.config/chrome-trace-config.json | |
18 // - POSIX other than Android: $HOME/.config/chrome-trace-config.json | |
19 // - Win: %USERPROFILE%/.config/chrome-trace-config.json | |
20 #if defined(OS_ANDROID) | |
21 const base::FilePath::CharType kAndroidTraceConfigDir[] = | |
22 FILE_PATH_LITERAL("/data/local"); | |
23 #endif | |
24 | |
25 const base::FilePath::CharType kChromeConfigDir[] = | |
26 FILE_PATH_LITERAL(".config"); | |
27 const base::FilePath::CharType kTraceConfigFileName[] = | |
28 FILE_PATH_LITERAL("chrome-trace-config.json"); | |
29 | |
30 base::FilePath GetTraceConfigFilePath() { | |
31 #if defined(OS_ANDROID) | |
32 base::FilePath path(kAndroidTraceConfigDir); | |
33 #elif defined(OS_POSIX) || defined(OS_WIN) | |
34 base::FilePath path; | |
35 PathService::Get(base::DIR_HOME, &path); | |
36 #else | |
37 base::FilePath path; | |
38 #endif | |
39 path = path.Append(kChromeConfigDir); | |
40 path = path.Append(kTraceConfigFileName); | |
41 return path; | |
42 } | |
43 | |
44 } // namespace | |
45 | |
46 void EnableStartupTracingIfConfigFileExists() { | |
47 base::FilePath trace_config_file_path = GetTraceConfigFilePath(); | |
48 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.
| |
49 || !base::PathExists(trace_config_file_path)) | |
50 return; | |
51 | |
52 std::string trace_config_str; | |
53 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.
| |
54 return; | |
55 | |
56 base::trace_event::TraceConfig trace_config(trace_config_str); | |
57 base::trace_event::TraceLog::GetInstance()->SetEnabled( | |
58 trace_config, base::trace_event::TraceLog::RECORDING_MODE); | |
59 } | |
60 | |
61 } // namespace tracing | |
OLD | NEW |