OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/trace_event.h" | 5 #include "base/trace_event.h" |
6 | 6 |
| 7 #include "base/file_path.h" |
7 #include "base/file_util.h" | 8 #include "base/file_util.h" |
8 #include "base/path_service.h" | 9 #include "base/path_service.h" |
9 #include "base/platform_thread.h" | 10 #include "base/platform_thread.h" |
10 #include "base/process_util.h" | 11 #include "base/process_util.h" |
11 #include "base/string_util.h" | 12 #include "base/string_util.h" |
12 #include "base/time.h" | 13 #include "base/time.h" |
13 | 14 |
14 #define USE_UNRELIABLE_NOW | 15 #define USE_UNRELIABLE_NOW |
15 | 16 |
16 namespace base { | 17 namespace base { |
17 | 18 |
18 static const char* kEventTypeNames[] = { | 19 static const char* kEventTypeNames[] = { |
19 "BEGIN", | 20 "BEGIN", |
20 "END", | 21 "END", |
21 "INSTANT" | 22 "INSTANT" |
22 }; | 23 }; |
23 | 24 |
24 static const wchar_t* kLogFileName = L"trace_%d.log"; | 25 static const FilePath::CharType* kLogFileName = |
| 26 FILE_PATH_LITERAL("trace_%d.log"); |
25 | 27 |
26 TraceLog::TraceLog() : enabled_(false), log_file_(NULL) { | 28 TraceLog::TraceLog() : enabled_(false), log_file_(NULL) { |
27 ProcessHandle proc = process_util::GetCurrentProcessHandle(); | 29 ProcessHandle proc = process_util::GetCurrentProcessHandle(); |
28 process_metrics_.reset(process_util::ProcessMetrics::CreateProcessMetrics(proc
)); | 30 process_metrics_.reset(process_util::ProcessMetrics::CreateProcessMetrics(proc
)); |
29 } | 31 } |
30 | 32 |
31 TraceLog::~TraceLog() { | 33 TraceLog::~TraceLog() { |
32 Stop(); | 34 Stop(); |
33 } | 35 } |
34 | 36 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 TRACE_EVENT_INSTANT("heartbeat.cpu", 0, cpu); | 78 TRACE_EVENT_INSTANT("heartbeat.cpu", 0, cpu); |
77 } | 79 } |
78 | 80 |
79 void TraceLog::CloseLogFile() { | 81 void TraceLog::CloseLogFile() { |
80 if (log_file_) { | 82 if (log_file_) { |
81 file_util::CloseFile(log_file_); | 83 file_util::CloseFile(log_file_); |
82 } | 84 } |
83 } | 85 } |
84 | 86 |
85 bool TraceLog::OpenLogFile() { | 87 bool TraceLog::OpenLogFile() { |
86 std::wstring pid_filename = | 88 FilePath::StringType pid_filename = |
87 StringPrintf(kLogFileName, process_util::GetCurrentProcId()); | 89 StringPrintf(kLogFileName, process_util::GetCurrentProcId()); |
88 std::wstring log_file_name; | 90 FilePath log_file_path; |
89 PathService::Get(base::DIR_EXE, &log_file_name); | 91 if (!PathService::Get(base::DIR_EXE, &log_file_path)) |
90 file_util::AppendToPath(&log_file_name, pid_filename); | 92 return false; |
91 log_file_ = file_util::OpenFile(log_file_name, "a"); | 93 log_file_path = log_file_path.Append(pid_filename); |
| 94 log_file_ = file_util::OpenFile(log_file_path, "a"); |
92 if (!log_file_) { | 95 if (!log_file_) { |
93 // try the current directory | 96 // try the current directory |
94 log_file_ = file_util::OpenFile(pid_filename, "a"); | 97 log_file_ = file_util::OpenFile(FilePath(pid_filename), "a"); |
95 if (!log_file_) { | 98 if (!log_file_) { |
96 return false; | 99 return false; |
97 } | 100 } |
98 } | 101 } |
99 return true; | 102 return true; |
100 } | 103 } |
101 | 104 |
102 void TraceLog::Trace(const std::string& name, | 105 void TraceLog::Trace(const std::string& name, |
103 EventType type, | 106 EventType type, |
104 const void* id, | 107 const void* id, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 Log(msg); | 146 Log(msg); |
144 } | 147 } |
145 | 148 |
146 void TraceLog::Log(const std::string& msg) { | 149 void TraceLog::Log(const std::string& msg) { |
147 AutoLock lock(file_lock_); | 150 AutoLock lock(file_lock_); |
148 | 151 |
149 fprintf(log_file_, "%s", msg.c_str()); | 152 fprintf(log_file_, "%s", msg.c_str()); |
150 } | 153 } |
151 | 154 |
152 } // namespace base | 155 } // namespace base |
OLD | NEW |