OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/debug/trace_event_impl.h" | 5 #include "base/debug/trace_event_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/base_switches.h" | 9 #include "base/base_switches.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 1516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1527 // 2. If thread_message_loops_ is not empty, threadA posts task to each message | 1527 // 2. If thread_message_loops_ is not empty, threadA posts task to each message |
1528 // loop to flush the thread local buffers; otherwise finish the flush; | 1528 // loop to flush the thread local buffers; otherwise finish the flush; |
1529 // 3. FlushCurrentThread() deletes the thread local event buffer: | 1529 // 3. FlushCurrentThread() deletes the thread local event buffer: |
1530 // - The last batch of events of the thread are flushed into the main buffer; | 1530 // - The last batch of events of the thread are flushed into the main buffer; |
1531 // - The message loop will be removed from thread_message_loops_; | 1531 // - The message loop will be removed from thread_message_loops_; |
1532 // If this is the last message loop, finish the flush; | 1532 // If this is the last message loop, finish the flush; |
1533 // 4. If any thread hasn't finish its flush in time, finish the flush. | 1533 // 4. If any thread hasn't finish its flush in time, finish the flush. |
1534 void TraceLog::Flush(const TraceLog::OutputCallback& cb) { | 1534 void TraceLog::Flush(const TraceLog::OutputCallback& cb) { |
1535 if (IsEnabled()) { | 1535 if (IsEnabled()) { |
1536 // Can't flush when tracing is enabled because otherwise PostTask would | 1536 // Can't flush when tracing is enabled because otherwise PostTask would |
1537 // - it generates more trace events; | 1537 // - generate more trace events; |
1538 // - it deschedules the calling thread on some platforms causing inaccurate | 1538 // - deschedule the calling thread on some platforms causing inaccurate |
1539 // timing of the trace events. | 1539 // timing of the trace events. |
1540 scoped_refptr<RefCountedString> empty_result = new RefCountedString; | 1540 scoped_refptr<RefCountedString> empty_result = new RefCountedString; |
1541 if (!cb.is_null()) | 1541 if (!cb.is_null()) |
1542 cb.Run(empty_result, false); | 1542 cb.Run(empty_result, false); |
1543 LOG(WARNING) << "Ignored TraceLog::Flush called when tracing is enabled"; | 1543 LOG(WARNING) << "Ignored TraceLog::Flush called when tracing is enabled"; |
1544 return; | 1544 return; |
1545 } | 1545 } |
1546 | 1546 |
1547 int generation = this->generation(); | 1547 int generation = this->generation(); |
1548 { | 1548 { |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1672 thread_message_loops_.begin(); | 1672 thread_message_loops_.begin(); |
1673 it != thread_message_loops_.end(); ++it) { | 1673 it != thread_message_loops_.end(); ++it) { |
1674 LOG(WARNING) << "Thread: " << (*it)->thread_name(); | 1674 LOG(WARNING) << "Thread: " << (*it)->thread_name(); |
1675 } | 1675 } |
1676 } | 1676 } |
1677 FinishFlush(generation); | 1677 FinishFlush(generation); |
1678 } | 1678 } |
1679 | 1679 |
1680 void TraceLog::FlushButLeaveBufferIntact( | 1680 void TraceLog::FlushButLeaveBufferIntact( |
1681 const TraceLog::OutputCallback& flush_output_callback) { | 1681 const TraceLog::OutputCallback& flush_output_callback) { |
1682 if (!sampling_thread_) | |
1683 return; | |
1684 | |
1685 scoped_ptr<TraceBuffer> previous_logged_events; | 1682 scoped_ptr<TraceBuffer> previous_logged_events; |
1686 { | 1683 { |
1687 AutoLock lock(lock_); | 1684 AutoLock lock(lock_); |
1688 AddMetadataEventsWhileLocked(); | 1685 AddMetadataEventsWhileLocked(); |
1689 if (thread_shared_chunk_) { | 1686 if (thread_shared_chunk_) { |
1690 // Return the chunk to the main buffer to flush the sampling data. | 1687 // Return the chunk to the main buffer to flush the sampling data. |
1691 logged_events_->ReturnChunk(thread_shared_chunk_index_, | 1688 logged_events_->ReturnChunk(thread_shared_chunk_index_, |
1692 thread_shared_chunk_.Pass()); | 1689 thread_shared_chunk_.Pass()); |
1693 } | 1690 } |
1694 previous_logged_events = logged_events_->CloneForIteration().Pass(); | 1691 previous_logged_events = logged_events_->CloneForIteration().Pass(); |
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2328 } | 2325 } |
2329 | 2326 |
2330 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() { | 2327 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() { |
2331 if (*category_group_enabled_) { | 2328 if (*category_group_enabled_) { |
2332 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, | 2329 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, |
2333 name_, event_handle_); | 2330 name_, event_handle_); |
2334 } | 2331 } |
2335 } | 2332 } |
2336 | 2333 |
2337 } // namespace trace_event_internal | 2334 } // namespace trace_event_internal |
OLD | NEW |