| 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 #include "tools/cygprofile/cygprofile.h" | 5 #include "tools/cygprofile/cygprofile.h" |
| 6 | 6 |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <pthread.h> | 8 #include <pthread.h> |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 #include <stdint.h> | 10 #include <stdint.h> |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 // though) due to OOM. | 242 // though) due to OOM. |
| 243 CHECK_LE(entries_.size(), kMaxBufferSize); | 243 CHECK_LE(entries_.size(), kMaxBufferSize); |
| 244 } | 244 } |
| 245 | 245 |
| 246 in_use_ = false; | 246 in_use_ = false; |
| 247 } | 247 } |
| 248 | 248 |
| 249 void ThreadLog::TakeEntries(std::vector<LogEntry>* destination) { | 249 void ThreadLog::TakeEntries(std::vector<LogEntry>* destination) { |
| 250 base::AutoLock auto_lock(lock_); | 250 base::AutoLock auto_lock(lock_); |
| 251 destination->swap(entries_); | 251 destination->swap(entries_); |
| 252 STLClearObject(&entries_); | 252 base::STLClearObject(&entries_); |
| 253 } | 253 } |
| 254 | 254 |
| 255 void ThreadLog::Flush(std::vector<LogEntry>* entries) const { | 255 void ThreadLog::Flush(std::vector<LogEntry>* entries) const { |
| 256 flush_callback_.Run(entries); | 256 flush_callback_.Run(entries); |
| 257 } | 257 } |
| 258 | 258 |
| 259 void ThreadLog::FlushInternal(std::vector<LogEntry>* entries) const { | 259 void ThreadLog::FlushInternal(std::vector<LogEntry>* entries) const { |
| 260 const std::string log_filename( | 260 const std::string log_filename( |
| 261 base::StringPrintf( | 261 base::StringPrintf( |
| 262 kLogFilenameFormat, kLogFileNamePrefix, getpid(), tid_, getppid())); | 262 kLogFilenameFormat, kLogFileNamePrefix, getpid(), tid_, getppid())); |
| 263 const base::ScopedFILE file(fopen(log_filename.c_str(), "a")); | 263 const base::ScopedFILE file(fopen(log_filename.c_str(), "a")); |
| 264 CHECK(file.get()); | 264 CHECK(file.get()); |
| 265 | 265 |
| 266 const long offset = ftell(file.get()); | 266 const long offset = ftell(file.get()); |
| 267 if (offset == 0) | 267 if (offset == 0) |
| 268 fprintf(file.get(), "%s", g_file_header_line.Get().value.c_str()); | 268 fprintf(file.get(), "%s", g_file_header_line.Get().value.c_str()); |
| 269 | 269 |
| 270 for (std::vector<LogEntry>::const_iterator it = entries->begin(); | 270 for (std::vector<LogEntry>::const_iterator it = entries->begin(); |
| 271 it != entries->end(); ++it) { | 271 it != entries->end(); ++it) { |
| 272 fprintf(file.get(), "%ld %ld\t%d:%d\t%p\n", it->time.tv_sec, | 272 fprintf(file.get(), "%ld %ld\t%d:%d\t%p\n", it->time.tv_sec, |
| 273 it->time.tv_nsec / 1000, it->pid, it->tid, it->address); | 273 it->time.tv_nsec / 1000, it->pid, it->tid, it->address); |
| 274 } | 274 } |
| 275 | 275 |
| 276 STLClearObject(entries); | 276 base::STLClearObject(entries); |
| 277 } | 277 } |
| 278 | 278 |
| 279 ThreadLogsManager::ThreadLogsManager() | 279 ThreadLogsManager::ThreadLogsManager() |
| 280 : wait_callback_(base::Bind(&SleepSec, kFlushThreadIdleTimeSec)) { | 280 : wait_callback_(base::Bind(&SleepSec, kFlushThreadIdleTimeSec)) { |
| 281 } | 281 } |
| 282 | 282 |
| 283 ThreadLogsManager::ThreadLogsManager(const base::Closure& wait_callback, | 283 ThreadLogsManager::ThreadLogsManager(const base::Closure& wait_callback, |
| 284 const base::Closure& notify_callback) | 284 const base::Closure& notify_callback) |
| 285 | 285 |
| 286 : wait_callback_(wait_callback), | 286 : wait_callback_(wait_callback), |
| 287 notify_callback_(notify_callback) { | 287 notify_callback_(notify_callback) { |
| 288 } | 288 } |
| 289 | 289 |
| 290 ThreadLogsManager::~ThreadLogsManager() { | 290 ThreadLogsManager::~ThreadLogsManager() { |
| 291 // Note that the internal thread does some work until it sees |flush_thread_| | 291 // Note that the internal thread does some work until it sees |flush_thread_| |
| 292 // = NULL. | 292 // = NULL. |
| 293 std::unique_ptr<Thread> flush_thread; | 293 std::unique_ptr<Thread> flush_thread; |
| 294 { | 294 { |
| 295 base::AutoLock auto_lock(lock_); | 295 base::AutoLock auto_lock(lock_); |
| 296 flush_thread_.swap(flush_thread); | 296 flush_thread_.swap(flush_thread); |
| 297 } | 297 } |
| 298 flush_thread.reset(); // Joins the flush thread. | 298 flush_thread.reset(); // Joins the flush thread. |
| 299 | 299 |
| 300 STLDeleteContainerPointers(logs_.begin(), logs_.end()); | 300 base::STLDeleteContainerPointers(logs_.begin(), logs_.end()); |
| 301 } | 301 } |
| 302 | 302 |
| 303 void ThreadLogsManager::AddLog(std::unique_ptr<ThreadLog> new_log) { | 303 void ThreadLogsManager::AddLog(std::unique_ptr<ThreadLog> new_log) { |
| 304 base::AutoLock auto_lock(lock_); | 304 base::AutoLock auto_lock(lock_); |
| 305 | 305 |
| 306 if (logs_.empty()) | 306 if (logs_.empty()) |
| 307 StartInternalFlushThread_Locked(); | 307 StartInternalFlushThread_Locked(); |
| 308 | 308 |
| 309 logs_.push_back(new_log.release()); | 309 logs_.push_back(new_log.release()); |
| 310 } | 310 } |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 } | 398 } |
| 399 | 399 |
| 400 if (thread_log != kMagicBeingConstructed) | 400 if (thread_log != kMagicBeingConstructed) |
| 401 thread_log->AddEntry(this_fn); | 401 thread_log->AddEntry(this_fn); |
| 402 } | 402 } |
| 403 | 403 |
| 404 void __cyg_profile_func_exit(void* this_fn, void* call_site) {} | 404 void __cyg_profile_func_exit(void* this_fn, void* call_site) {} |
| 405 | 405 |
| 406 } // extern "C" | 406 } // extern "C" |
| 407 } // namespace cygprofile | 407 } // namespace cygprofile |
| OLD | NEW |