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/trace_event/trace_event_impl.h" | 5 #include "base/trace_event/trace_event_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 | 9 |
10 #include "base/base_switches.h" | 10 #include "base/base_switches.h" |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 public: | 299 public: |
300 TraceBufferVector(size_t max_chunks) | 300 TraceBufferVector(size_t max_chunks) |
301 : in_flight_chunk_count_(0), | 301 : in_flight_chunk_count_(0), |
302 current_iteration_index_(0), | 302 current_iteration_index_(0), |
303 max_chunks_(max_chunks) { | 303 max_chunks_(max_chunks) { |
304 chunks_.reserve(max_chunks_); | 304 chunks_.reserve(max_chunks_); |
305 } | 305 } |
306 | 306 |
307 scoped_ptr<TraceBufferChunk> GetChunk(size_t* index) override { | 307 scoped_ptr<TraceBufferChunk> GetChunk(size_t* index) override { |
308 // This function may be called when adding normal events or indirectly from | 308 // This function may be called when adding normal events or indirectly from |
309 // AddMetadataEventsWhileLocked(). We can not DECHECK(!IsFull()) because we | 309 // AddMetadataEventsWhileLocked(). We can not DCHECK(!IsFull()) because we |
310 // have to add the metadata events and flush thread-local buffers even if | 310 // have to add the metadata events and flush thread-local buffers even if |
311 // the buffer is full. | 311 // the buffer is full. |
312 *index = chunks_.size(); | 312 *index = chunks_.size(); |
313 chunks_.push_back(NULL); // Put NULL in the slot of a in-flight chunk. | 313 chunks_.push_back(NULL); // Put NULL in the slot of a in-flight chunk. |
314 ++in_flight_chunk_count_; | 314 ++in_flight_chunk_count_; |
315 // + 1 because zero chunk_seq is not allowed. | 315 // + 1 because zero chunk_seq is not allowed. |
316 return scoped_ptr<TraceBufferChunk>( | 316 return scoped_ptr<TraceBufferChunk>( |
317 new TraceBufferChunk(static_cast<uint32>(*index) + 1)); | 317 new TraceBufferChunk(static_cast<uint32>(*index) + 1)); |
318 } | 318 } |
319 | 319 |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
717 *out += arg_names_[i]; | 717 *out += arg_names_[i]; |
718 *out += "\":"; | 718 *out += "\":"; |
719 | 719 |
720 if (arg_types_[i] == TRACE_VALUE_TYPE_CONVERTABLE) | 720 if (arg_types_[i] == TRACE_VALUE_TYPE_CONVERTABLE) |
721 convertable_values_[i]->AppendAsTraceFormat(out); | 721 convertable_values_[i]->AppendAsTraceFormat(out); |
722 else | 722 else |
723 AppendValueAsJSON(arg_types_[i], arg_values_[i], out); | 723 AppendValueAsJSON(arg_types_[i], arg_values_[i], out); |
724 } | 724 } |
725 *out += "}"; | 725 *out += "}"; |
726 | 726 |
727 if (phase_ == TRACE_EVENT_PHASE_COMPLETE) { | 727 if (phase_ == TRACE_EVENT_PHASE_COMPLETE || |
| 728 phase_ == TRACE_EVENT_PHASE_NESTABLE_ASYNC_COMPLETE) { |
728 int64 duration = duration_.ToInternalValue(); | 729 int64 duration = duration_.ToInternalValue(); |
729 if (duration != -1) | 730 if (duration != -1) |
730 StringAppendF(out, ",\"dur\":%" PRId64, duration); | 731 StringAppendF(out, ",\"dur\":%" PRId64, duration); |
731 if (!thread_timestamp_.is_null()) { | 732 if (!thread_timestamp_.is_null()) { |
732 int64 thread_duration = thread_duration_.ToInternalValue(); | 733 int64 thread_duration = thread_duration_.ToInternalValue(); |
733 if (thread_duration != -1) | 734 if (thread_duration != -1) |
734 StringAppendF(out, ",\"tdur\":%" PRId64, thread_duration); | 735 StringAppendF(out, ",\"tdur\":%" PRId64, thread_duration); |
735 } | 736 } |
736 } | 737 } |
737 | 738 |
(...skipping 1332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2070 // May be called when a COMPELETE event ends and the unfinished event has been | 2071 // May be called when a COMPELETE event ends and the unfinished event has been |
2071 // recycled (phase == TRACE_EVENT_PHASE_END and trace_event == NULL). | 2072 // recycled (phase == TRACE_EVENT_PHASE_END and trace_event == NULL). |
2072 std::string TraceLog::EventToConsoleMessage(unsigned char phase, | 2073 std::string TraceLog::EventToConsoleMessage(unsigned char phase, |
2073 const TimeTicks& timestamp, | 2074 const TimeTicks& timestamp, |
2074 TraceEvent* trace_event) { | 2075 TraceEvent* trace_event) { |
2075 AutoLock thread_info_lock(thread_info_lock_); | 2076 AutoLock thread_info_lock(thread_info_lock_); |
2076 | 2077 |
2077 // The caller should translate TRACE_EVENT_PHASE_COMPLETE to | 2078 // The caller should translate TRACE_EVENT_PHASE_COMPLETE to |
2078 // TRACE_EVENT_PHASE_BEGIN or TRACE_EVENT_END. | 2079 // TRACE_EVENT_PHASE_BEGIN or TRACE_EVENT_END. |
2079 DCHECK(phase != TRACE_EVENT_PHASE_COMPLETE); | 2080 DCHECK(phase != TRACE_EVENT_PHASE_COMPLETE); |
| 2081 DCHECK(phase != TRACE_EVENT_PHASE_NESTABLE_ASYNC_COMPLETE); |
2080 | 2082 |
2081 TimeDelta duration; | 2083 TimeDelta duration; |
2082 int thread_id = trace_event ? | 2084 int thread_id = trace_event ? |
2083 trace_event->thread_id() : PlatformThread::CurrentId(); | 2085 trace_event->thread_id() : PlatformThread::CurrentId(); |
2084 if (phase == TRACE_EVENT_PHASE_END) { | 2086 if (phase == TRACE_EVENT_PHASE_END) { |
2085 duration = timestamp - thread_event_start_times_[thread_id].top(); | 2087 duration = timestamp - thread_event_start_times_[thread_id].top(); |
2086 thread_event_start_times_[thread_id].pop(); | 2088 thread_event_start_times_[thread_id].pop(); |
2087 } | 2089 } |
2088 | 2090 |
2089 std::string thread_name = thread_names_[thread_id]; | 2091 std::string thread_name = thread_names_[thread_id]; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2152 | 2154 |
2153 TimeTicks thread_now = ThreadNow(); | 2155 TimeTicks thread_now = ThreadNow(); |
2154 TimeTicks now = OffsetNow(); | 2156 TimeTicks now = OffsetNow(); |
2155 | 2157 |
2156 std::string console_message; | 2158 std::string console_message; |
2157 if (*category_group_enabled & ENABLED_FOR_RECORDING) { | 2159 if (*category_group_enabled & ENABLED_FOR_RECORDING) { |
2158 OptionalAutoLock lock(&lock_); | 2160 OptionalAutoLock lock(&lock_); |
2159 | 2161 |
2160 TraceEvent* trace_event = GetEventByHandleInternal(handle, &lock); | 2162 TraceEvent* trace_event = GetEventByHandleInternal(handle, &lock); |
2161 if (trace_event) { | 2163 if (trace_event) { |
2162 DCHECK(trace_event->phase() == TRACE_EVENT_PHASE_COMPLETE); | 2164 DCHECK(trace_event->phase() == TRACE_EVENT_PHASE_COMPLETE || |
| 2165 trace_event->phase() == TRACE_EVENT_PHASE_NESTABLE_ASYNC_COMPLETE); |
2163 trace_event->UpdateDuration(now, thread_now); | 2166 trace_event->UpdateDuration(now, thread_now); |
2164 #if defined(OS_ANDROID) | 2167 #if defined(OS_ANDROID) |
2165 trace_event->SendToATrace(); | 2168 trace_event->SendToATrace(); |
2166 #endif | 2169 #endif |
2167 } | 2170 } |
2168 | 2171 |
2169 if (trace_options() & kInternalEchoToConsole) { | 2172 if (trace_options() & kInternalEchoToConsole) { |
2170 console_message = EventToConsoleMessage(TRACE_EVENT_PHASE_END, | 2173 console_message = EventToConsoleMessage(TRACE_EVENT_PHASE_END, |
2171 now, trace_event); | 2174 now, trace_event); |
2172 } | 2175 } |
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2634 } | 2637 } |
2635 | 2638 |
2636 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() { | 2639 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() { |
2637 if (*category_group_enabled_) { | 2640 if (*category_group_enabled_) { |
2638 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, | 2641 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, |
2639 name_, event_handle_); | 2642 name_, event_handle_); |
2640 } | 2643 } |
2641 } | 2644 } |
2642 | 2645 |
2643 } // namespace trace_event_internal | 2646 } // namespace trace_event_internal |
OLD | NEW |