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 | 8 |
9 #include "base/base_switches.h" | 9 #include "base/base_switches.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 cloned_chunk->next_free_ = next_free_; | 423 cloned_chunk->next_free_ = next_free_; |
424 for (size_t i = 0; i < next_free_; ++i) | 424 for (size_t i = 0; i < next_free_; ++i) |
425 cloned_chunk->chunk_[i].CopyFrom(chunk_[i]); | 425 cloned_chunk->chunk_[i].CopyFrom(chunk_[i]); |
426 return cloned_chunk.Pass(); | 426 return cloned_chunk.Pass(); |
427 } | 427 } |
428 | 428 |
429 // A helper class that allows the lock to be acquired in the middle of the scope | 429 // A helper class that allows the lock to be acquired in the middle of the scope |
430 // and unlocks at the end of scope if locked. | 430 // and unlocks at the end of scope if locked. |
431 class TraceLog::OptionalAutoLock { | 431 class TraceLog::OptionalAutoLock { |
432 public: | 432 public: |
433 explicit OptionalAutoLock(Lock& lock) | 433 explicit OptionalAutoLock(Lock* lock) : lock_(lock), locked_(false) {} |
434 : lock_(lock), | |
435 locked_(false) { | |
436 } | |
437 | 434 |
438 ~OptionalAutoLock() { | 435 ~OptionalAutoLock() { |
439 if (locked_) | 436 if (locked_) |
440 lock_.Release(); | 437 lock_->Release(); |
441 } | 438 } |
442 | 439 |
443 void EnsureAcquired() { | 440 void EnsureAcquired() { |
444 if (!locked_) { | 441 if (!locked_) { |
445 lock_.Acquire(); | 442 lock_->Acquire(); |
446 locked_ = true; | 443 locked_ = true; |
447 } | 444 } |
448 } | 445 } |
449 | 446 |
450 private: | 447 private: |
451 Lock& lock_; | 448 Lock* lock_; |
452 bool locked_; | 449 bool locked_; |
453 DISALLOW_COPY_AND_ASSIGN(OptionalAutoLock); | 450 DISALLOW_COPY_AND_ASSIGN(OptionalAutoLock); |
454 }; | 451 }; |
455 | 452 |
456 // Use this function instead of TraceEventHandle constructor to keep the | 453 // Use this function instead of TraceEventHandle constructor to keep the |
457 // overhead of ScopedTracer (trace_event.h) constructor minimum. | 454 // overhead of ScopedTracer (trace_event.h) constructor minimum. |
458 void MakeHandle(uint32 chunk_seq, size_t chunk_index, size_t event_index, | 455 void MakeHandle(uint32 chunk_seq, size_t chunk_index, size_t event_index, |
459 TraceEventHandle* handle) { | 456 TraceEventHandle* handle) { |
460 DCHECK(chunk_seq); | 457 DCHECK(chunk_seq); |
461 DCHECK(chunk_index < (1u << 16)); | 458 DCHECK(chunk_index < (1u << 16)); |
(...skipping 1508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1970 existing_name->second.push_back(','); | 1967 existing_name->second.push_back(','); |
1971 existing_name->second.append(new_name); | 1968 existing_name->second.append(new_name); |
1972 } | 1969 } |
1973 } | 1970 } |
1974 } | 1971 } |
1975 } | 1972 } |
1976 | 1973 |
1977 std::string console_message; | 1974 std::string console_message; |
1978 if (*category_group_enabled & | 1975 if (*category_group_enabled & |
1979 (ENABLED_FOR_RECORDING | ENABLED_FOR_MONITORING)) { | 1976 (ENABLED_FOR_RECORDING | ENABLED_FOR_MONITORING)) { |
1980 OptionalAutoLock lock(lock_); | 1977 OptionalAutoLock lock(&lock_); |
1981 | 1978 |
1982 TraceEvent* trace_event = NULL; | 1979 TraceEvent* trace_event = NULL; |
1983 if (thread_local_event_buffer) { | 1980 if (thread_local_event_buffer) { |
1984 trace_event = thread_local_event_buffer->AddTraceEvent(&handle); | 1981 trace_event = thread_local_event_buffer->AddTraceEvent(&handle); |
1985 } else { | 1982 } else { |
1986 lock.EnsureAcquired(); | 1983 lock.EnsureAcquired(); |
1987 trace_event = AddEventToThreadSharedChunkWhileLocked(&handle, true); | 1984 trace_event = AddEventToThreadSharedChunkWhileLocked(&handle, true); |
1988 } | 1985 } |
1989 | 1986 |
1990 if (trace_event) { | 1987 if (trace_event) { |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2123 if (thread_is_in_trace_event_.Get()) | 2120 if (thread_is_in_trace_event_.Get()) |
2124 return; | 2121 return; |
2125 | 2122 |
2126 AutoThreadLocalBoolean thread_is_in_trace_event(&thread_is_in_trace_event_); | 2123 AutoThreadLocalBoolean thread_is_in_trace_event(&thread_is_in_trace_event_); |
2127 | 2124 |
2128 TimeTicks thread_now = ThreadNow(); | 2125 TimeTicks thread_now = ThreadNow(); |
2129 TimeTicks now = OffsetNow(); | 2126 TimeTicks now = OffsetNow(); |
2130 | 2127 |
2131 std::string console_message; | 2128 std::string console_message; |
2132 if (*category_group_enabled & ENABLED_FOR_RECORDING) { | 2129 if (*category_group_enabled & ENABLED_FOR_RECORDING) { |
2133 OptionalAutoLock lock(lock_); | 2130 OptionalAutoLock lock(&lock_); |
2134 | 2131 |
2135 TraceEvent* trace_event = GetEventByHandleInternal(handle, &lock); | 2132 TraceEvent* trace_event = GetEventByHandleInternal(handle, &lock); |
2136 if (trace_event) { | 2133 if (trace_event) { |
2137 DCHECK(trace_event->phase() == TRACE_EVENT_PHASE_COMPLETE); | 2134 DCHECK(trace_event->phase() == TRACE_EVENT_PHASE_COMPLETE); |
2138 trace_event->UpdateDuration(now, thread_now); | 2135 trace_event->UpdateDuration(now, thread_now); |
2139 #if defined(OS_ANDROID) | 2136 #if defined(OS_ANDROID) |
2140 trace_event->SendToATrace(); | 2137 trace_event->SendToATrace(); |
2141 #endif | 2138 #endif |
2142 } | 2139 } |
2143 | 2140 |
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2605 } | 2602 } |
2606 | 2603 |
2607 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() { | 2604 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() { |
2608 if (*category_group_enabled_) { | 2605 if (*category_group_enabled_) { |
2609 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, | 2606 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, |
2610 name_, event_handle_); | 2607 name_, event_handle_); |
2611 } | 2608 } |
2612 } | 2609 } |
2613 | 2610 |
2614 } // namespace trace_event_internal | 2611 } // namespace trace_event_internal |
OLD | NEW |