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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
617 // Only reset fields that won't be initialized in Initialize(), or that may | 614 // Only reset fields that won't be initialized in Initialize(), or that may |
618 // hold references to other objects. | 615 // hold references to other objects. |
619 duration_ = TimeDelta::FromInternalValue(-1); | 616 duration_ = TimeDelta::FromInternalValue(-1); |
620 parameter_copy_storage_ = NULL; | 617 parameter_copy_storage_ = NULL; |
621 for (int i = 0; i < kTraceMaxNumArgs; ++i) | 618 for (int i = 0; i < kTraceMaxNumArgs; ++i) |
622 convertable_values_[i] = NULL; | 619 convertable_values_[i] = NULL; |
623 } | 620 } |
624 | 621 |
625 void TraceEvent::UpdateDuration(const TimeTicks& now, | 622 void TraceEvent::UpdateDuration(const TimeTicks& now, |
626 const TimeTicks& thread_now) { | 623 const TimeTicks& thread_now) { |
627 DCHECK(duration_.ToInternalValue() == -1); | 624 DCHECK_EQ(duration_.ToInternalValue(), -1); |
628 duration_ = now - timestamp_; | 625 duration_ = now - timestamp_; |
629 thread_duration_ = thread_now - thread_timestamp_; | 626 thread_duration_ = thread_now - thread_timestamp_; |
630 } | 627 } |
631 | 628 |
632 // static | 629 // static |
633 void TraceEvent::AppendValueAsJSON(unsigned char type, | 630 void TraceEvent::AppendValueAsJSON(unsigned char type, |
634 TraceEvent::TraceValue value, | 631 TraceEvent::TraceValue value, |
635 std::string* out) { | 632 std::string* out) { |
636 switch (type) { | 633 switch (type) { |
637 case TRACE_VALUE_TYPE_BOOL: | 634 case TRACE_VALUE_TYPE_BOOL: |
(...skipping 1332 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 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2483 if (IsCategoryEnabled(category_group_token.c_str())) { | 2480 if (IsCategoryEnabled(category_group_token.c_str())) { |
2484 return true; | 2481 return true; |
2485 } | 2482 } |
2486 if (!MatchPattern(category_group_token.c_str(), | 2483 if (!MatchPattern(category_group_token.c_str(), |
2487 TRACE_DISABLED_BY_DEFAULT("*"))) | 2484 TRACE_DISABLED_BY_DEFAULT("*"))) |
2488 had_enabled_by_default = true; | 2485 had_enabled_by_default = true; |
2489 } | 2486 } |
2490 // Do a second pass to check for explicitly disabled categories | 2487 // Do a second pass to check for explicitly disabled categories |
2491 // (those explicitly enabled have priority due to first pass). | 2488 // (those explicitly enabled have priority due to first pass). |
2492 category_group_tokens.Reset(); | 2489 category_group_tokens.Reset(); |
| 2490 bool category_group_disabled = false; |
2493 while (category_group_tokens.GetNext()) { | 2491 while (category_group_tokens.GetNext()) { |
2494 std::string category_group_token = category_group_tokens.token(); | 2492 std::string category_group_token = category_group_tokens.token(); |
2495 for (StringList::const_iterator ci = excluded_.begin(); | 2493 for (StringList::const_iterator ci = excluded_.begin(); |
2496 ci != excluded_.end(); ++ci) { | 2494 ci != excluded_.end(); ++ci) { |
2497 if (MatchPattern(category_group_token.c_str(), ci->c_str())) | 2495 if (MatchPattern(category_group_token.c_str(), ci->c_str())) { |
2498 return false; | 2496 // Current token of category_group_name is present in excluded_list. |
| 2497 // Flag the exclusion and proceed further to check if any of the |
| 2498 // remaining categories of category_group_name is not present in the |
| 2499 // excluded_ list. |
| 2500 category_group_disabled = true; |
| 2501 break; |
| 2502 } |
| 2503 // One of the category of category_group_name is not present in |
| 2504 // excluded_ list. So, it has to be included_ list. Enable the |
| 2505 // category_group_name for recording. |
| 2506 category_group_disabled = false; |
2499 } | 2507 } |
| 2508 // One of the categories present in category_group_name is not present in |
| 2509 // excluded_ list. Implies this category_group_name group can be enabled |
| 2510 // for recording, since one of its groups is enabled for recording. |
| 2511 if (!category_group_disabled) |
| 2512 break; |
2500 } | 2513 } |
2501 // If the category group is not excluded, and there are no included patterns | 2514 // If the category group is not excluded, and there are no included patterns |
2502 // we consider this category group enabled, as long as it had categories | 2515 // we consider this category group enabled, as long as it had categories |
2503 // other than disabled-by-default. | 2516 // other than disabled-by-default. |
2504 return included_.empty() && had_enabled_by_default; | 2517 return !category_group_disabled && |
| 2518 included_.empty() && had_enabled_by_default; |
2505 } | 2519 } |
2506 | 2520 |
2507 bool CategoryFilter::IsCategoryEnabled(const char* category_name) const { | 2521 bool CategoryFilter::IsCategoryEnabled(const char* category_name) const { |
2508 StringList::const_iterator ci; | 2522 StringList::const_iterator ci; |
2509 | 2523 |
2510 // Check the disabled- filters and the disabled-* wildcard first so that a | 2524 // Check the disabled- filters and the disabled-* wildcard first so that a |
2511 // "*" filter does not include the disabled. | 2525 // "*" filter does not include the disabled. |
2512 for (ci = disabled_.begin(); ci != disabled_.end(); ++ci) { | 2526 for (ci = disabled_.begin(); ci != disabled_.end(); ++ci) { |
2513 if (MatchPattern(category_name, ci->c_str())) | 2527 if (MatchPattern(category_name, ci->c_str())) |
2514 return true; | 2528 return true; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2564 } | 2578 } |
2565 | 2579 |
2566 } // namespace trace_event | 2580 } // namespace trace_event |
2567 } // namespace base | 2581 } // namespace base |
2568 | 2582 |
2569 namespace trace_event_internal { | 2583 namespace trace_event_internal { |
2570 | 2584 |
2571 ScopedTraceBinaryEfficient::ScopedTraceBinaryEfficient( | 2585 ScopedTraceBinaryEfficient::ScopedTraceBinaryEfficient( |
2572 const char* category_group, const char* name) { | 2586 const char* category_group, const char* name) { |
2573 // The single atom works because for now the category_group can only be "gpu". | 2587 // The single atom works because for now the category_group can only be "gpu". |
2574 DCHECK(strcmp(category_group, "gpu") == 0); | 2588 DCHECK_EQ(strcmp(category_group, "gpu"), 0); |
2575 static TRACE_EVENT_API_ATOMIC_WORD atomic = 0; | 2589 static TRACE_EVENT_API_ATOMIC_WORD atomic = 0; |
2576 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO_CUSTOM_VARIABLES( | 2590 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO_CUSTOM_VARIABLES( |
2577 category_group, atomic, category_group_enabled_); | 2591 category_group, atomic, category_group_enabled_); |
2578 name_ = name; | 2592 name_ = name; |
2579 if (*category_group_enabled_) { | 2593 if (*category_group_enabled_) { |
2580 event_handle_ = | 2594 event_handle_ = |
2581 TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP( | 2595 TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP( |
2582 TRACE_EVENT_PHASE_COMPLETE, category_group_enabled_, name, | 2596 TRACE_EVENT_PHASE_COMPLETE, category_group_enabled_, name, |
2583 trace_event_internal::kNoEventId, | 2597 trace_event_internal::kNoEventId, |
2584 static_cast<int>(base::PlatformThread::CurrentId()), | 2598 static_cast<int>(base::PlatformThread::CurrentId()), |
2585 base::TimeTicks::NowFromSystemTraceTime(), | 2599 base::TimeTicks::NowFromSystemTraceTime(), |
2586 0, NULL, NULL, NULL, NULL, TRACE_EVENT_FLAG_NONE); | 2600 0, NULL, NULL, NULL, NULL, TRACE_EVENT_FLAG_NONE); |
2587 } | 2601 } |
2588 } | 2602 } |
2589 | 2603 |
2590 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() { | 2604 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() { |
2591 if (*category_group_enabled_) { | 2605 if (*category_group_enabled_) { |
2592 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, | 2606 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, |
2593 name_, event_handle_); | 2607 name_, event_handle_); |
2594 } | 2608 } |
2595 } | 2609 } |
2596 | 2610 |
2597 } // namespace trace_event_internal | 2611 } // namespace trace_event_internal |
OLD | NEW |