OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // Tool to log the execution of the process (Chrome). Writes logs containing | 5 // Tool to log the execution of the process (Chrome). Writes logs containing |
6 // time and address of the callback being called for the first time. | 6 // time and address of the callback being called for the first time. |
7 // | 7 // |
8 // To speed up the logging, buffering logs is implemented. Every thread have its | 8 // To speed up the logging, buffering logs is implemented. Every thread have its |
9 // own buffer and log file so the contention between threads is minimal. As a | 9 // own buffer and log file so the contention between threads is minimal. As a |
10 // side-effect, functions called might be mentioned in many thread logs. | 10 // side-effect, functions called might be mentioned in many thread logs. |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 (strtol((str_line.substr(dashindex + 1, | 201 (strtol((str_line.substr(dashindex + 1, |
202 spaceindex - dashindex - 1)).c_str(), | 202 spaceindex - dashindex - 1)).c_str(), |
203 &p, 16)); | 203 &p, 16)); |
204 CHECK(*p == 0); // Could not determine end address. | 204 CHECK(*p == 0); // Could not determine end address. |
205 | 205 |
206 if (this_fn >= start && this_fn < end) | 206 if (this_fn >= start && this_fn < end) |
207 header_line_ = str_line; | 207 header_line_ = str_line; |
208 } | 208 } |
209 } | 209 } |
210 mapsfile.close(); | 210 mapsfile.close(); |
211 header_line_.append("\nsecs\tmsecs\tpid:threadid\tfunc\n"); | 211 header_line_.append("\nsecs\tusecs\tpid:threadid\tfunc\n"); |
212 } | 212 } |
213 | 213 |
214 void CygTlsLog::LogEnter(void* this_fn) { | 214 void CygTlsLog::LogEnter(void* this_fn) { |
215 if (in_use_) | 215 if (in_use_) |
216 return; | 216 return; |
217 in_use_ = true; | 217 in_use_ = true; |
218 | 218 |
219 if (functions_called_.find(this_fn) == | 219 if (functions_called_.find(this_fn) == |
220 functions_called_.end()) { | 220 functions_called_.end()) { |
221 functions_called_.insert(this_fn); | 221 functions_called_.insert(this_fn); |
222 base::AutoLock lock(log_mutex_); | 222 base::AutoLock lock(log_mutex_); |
223 if (buf_.capacity() < kBufMaxSize) | 223 if (buf_.capacity() < kBufMaxSize) |
224 buf_.reserve(kBufMaxSize); | 224 buf_.reserve(kBufMaxSize); |
225 struct timeval timestamp; | 225 struct timespec timestamp; |
226 gettimeofday(×tamp, NULL); | 226 clock_gettime(CLOCK_MONOTONIC, ×tamp); |
227 buf_.push_back(CygLogEntry(time(NULL), timestamp.tv_usec, | 227 buf_.push_back(CygLogEntry(timestamp.tv_sec, timestamp.tv_nsec / 1000, |
228 getpid(), pthread_self(), this_fn)); | 228 getpid(), pthread_self(), this_fn)); |
229 if (buf_.size() == kBufMaxSize) { | 229 if (buf_.size() == kBufMaxSize) { |
230 FlushLog(); | 230 FlushLog(); |
231 } | 231 } |
232 } | 232 } |
233 | 233 |
234 in_use_ = false; | 234 in_use_ = false; |
235 } | 235 } |
236 | 236 |
237 void CygTlsLog::AtForkPrepare() { | 237 void CygTlsLog::AtForkPrepare() { |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 tls_current_log->LogEnter(this_fn); | 392 tls_current_log->LogEnter(this_fn); |
393 } | 393 } |
394 } | 394 } |
395 | 395 |
396 // Gcc Compiler callback, called after every function invocation providing | 396 // Gcc Compiler callback, called after every function invocation providing |
397 // addresses of caller and callee codes. | 397 // addresses of caller and callee codes. |
398 void __cyg_profile_func_exit(void* this_fn, void* call_site) { | 398 void __cyg_profile_func_exit(void* this_fn, void* call_site) { |
399 } | 399 } |
400 | 400 |
401 } // namespace cygprofile | 401 } // namespace cygprofile |
OLD | NEW |