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 1679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1690 // - deschedule the calling thread on some platforms causing inaccurate | 1690 // - deschedule the calling thread on some platforms causing inaccurate |
1691 // timing of the trace events. | 1691 // timing of the trace events. |
1692 scoped_refptr<RefCountedString> empty_result = new RefCountedString; | 1692 scoped_refptr<RefCountedString> empty_result = new RefCountedString; |
1693 if (!cb.is_null()) | 1693 if (!cb.is_null()) |
1694 cb.Run(empty_result, false); | 1694 cb.Run(empty_result, false); |
1695 LOG(WARNING) << "Ignored TraceLog::Flush called when tracing is enabled"; | 1695 LOG(WARNING) << "Ignored TraceLog::Flush called when tracing is enabled"; |
1696 return; | 1696 return; |
1697 } | 1697 } |
1698 | 1698 |
1699 int generation = this->generation(); | 1699 int generation = this->generation(); |
| 1700 // Copy of thread_message_loops_ to be used without locking. |
| 1701 std::vector<scoped_refptr<SingleThreadTaskRunner> > |
| 1702 thread_message_loop_task_runners; |
1700 { | 1703 { |
1701 AutoLock lock(lock_); | 1704 AutoLock lock(lock_); |
1702 DCHECK(!flush_message_loop_proxy_.get()); | 1705 DCHECK(!flush_message_loop_proxy_.get()); |
1703 flush_message_loop_proxy_ = MessageLoopProxy::current(); | 1706 flush_message_loop_proxy_ = MessageLoopProxy::current(); |
1704 DCHECK(!thread_message_loops_.size() || flush_message_loop_proxy_.get()); | 1707 DCHECK(!thread_message_loops_.size() || flush_message_loop_proxy_.get()); |
1705 flush_output_callback_ = cb; | 1708 flush_output_callback_ = cb; |
1706 | 1709 |
1707 if (thread_shared_chunk_) { | 1710 if (thread_shared_chunk_) { |
1708 logged_events_->ReturnChunk(thread_shared_chunk_index_, | 1711 logged_events_->ReturnChunk(thread_shared_chunk_index_, |
1709 thread_shared_chunk_.Pass()); | 1712 thread_shared_chunk_.Pass()); |
1710 } | 1713 } |
1711 | 1714 |
1712 if (thread_message_loops_.size()) { | 1715 if (thread_message_loops_.size()) { |
1713 for (hash_set<MessageLoop*>::const_iterator it = | 1716 for (hash_set<MessageLoop*>::const_iterator it = |
1714 thread_message_loops_.begin(); | 1717 thread_message_loops_.begin(); |
1715 it != thread_message_loops_.end(); ++it) { | 1718 it != thread_message_loops_.end(); ++it) { |
1716 (*it)->PostTask( | 1719 thread_message_loop_task_runners.push_back((*it)->task_runner()); |
1717 FROM_HERE, | |
1718 Bind(&TraceLog::FlushCurrentThread, Unretained(this), generation)); | |
1719 } | 1720 } |
1720 flush_message_loop_proxy_->PostDelayedTask( | |
1721 FROM_HERE, | |
1722 Bind(&TraceLog::OnFlushTimeout, Unretained(this), generation), | |
1723 TimeDelta::FromMilliseconds(kThreadFlushTimeoutMs)); | |
1724 return; | |
1725 } | 1721 } |
1726 } | 1722 } |
1727 | 1723 |
| 1724 if (thread_message_loop_task_runners.size()) { |
| 1725 for (size_t i = 0; i < thread_message_loop_task_runners.size(); ++i) { |
| 1726 thread_message_loop_task_runners[i]->PostTask( |
| 1727 FROM_HERE, |
| 1728 Bind(&TraceLog::FlushCurrentThread, Unretained(this), generation)); |
| 1729 } |
| 1730 flush_message_loop_proxy_->PostDelayedTask( |
| 1731 FROM_HERE, |
| 1732 Bind(&TraceLog::OnFlushTimeout, Unretained(this), generation), |
| 1733 TimeDelta::FromMilliseconds(kThreadFlushTimeoutMs)); |
| 1734 return; |
| 1735 } |
| 1736 |
1728 FinishFlush(generation); | 1737 FinishFlush(generation); |
1729 } | 1738 } |
1730 | 1739 |
1731 void TraceLog::ConvertTraceEventsToTraceFormat( | 1740 void TraceLog::ConvertTraceEventsToTraceFormat( |
1732 scoped_ptr<TraceBuffer> logged_events, | 1741 scoped_ptr<TraceBuffer> logged_events, |
1733 const TraceLog::OutputCallback& flush_output_callback) { | 1742 const TraceLog::OutputCallback& flush_output_callback) { |
1734 | 1743 |
1735 if (flush_output_callback.is_null()) | 1744 if (flush_output_callback.is_null()) |
1736 return; | 1745 return; |
1737 | 1746 |
(...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2562 } | 2571 } |
2563 | 2572 |
2564 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() { | 2573 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() { |
2565 if (*category_group_enabled_) { | 2574 if (*category_group_enabled_) { |
2566 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, | 2575 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, |
2567 name_, event_handle_); | 2576 name_, event_handle_); |
2568 } | 2577 } |
2569 } | 2578 } |
2570 | 2579 |
2571 } // namespace trace_event_internal | 2580 } // namespace trace_event_internal |
OLD | NEW |