Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_log.h" | 5 #include "base/trace_event/trace_log.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 486 return true; | 486 return true; |
| 487 } | 487 } |
| 488 | 488 |
| 489 const unsigned char* TraceLog::GetCategoryGroupEnabled( | 489 const unsigned char* TraceLog::GetCategoryGroupEnabled( |
| 490 const char* category_group) { | 490 const char* category_group) { |
| 491 TraceLog* tracelog = GetInstance(); | 491 TraceLog* tracelog = GetInstance(); |
| 492 if (!tracelog) { | 492 if (!tracelog) { |
| 493 DCHECK(!CategoryRegistry::kCategoryAlreadyShutdown->is_enabled()); | 493 DCHECK(!CategoryRegistry::kCategoryAlreadyShutdown->is_enabled()); |
| 494 return CategoryRegistry::kCategoryAlreadyShutdown->state_ptr(); | 494 return CategoryRegistry::kCategoryAlreadyShutdown->state_ptr(); |
| 495 } | 495 } |
| 496 TraceCategory* category = nullptr; | 496 TraceCategory* category = CategoryRegistry::GetCategoryByName(category_group); |
| 497 bool is_new_category = | 497 if (!category) { |
| 498 CategoryRegistry::GetOrCreateCategoryByName(category_group, &category); | 498 // Slow path: in the case of a new category we have to repeat the check |
|
Primiano Tucci (use gerrit)
2016/11/16 16:46:54
Essentially this was the core of the problem.
The
| |
| 499 if (is_new_category) | 499 // holding the lock, as multiple threads might have reached this point |
| 500 tracelog->UpdateCategoryState(category); | 500 // at the same time. |
| 501 auto category_initializer = [](TraceCategory* category) { | |
| 502 TraceLog::GetInstance()->UpdateCategoryState(category); | |
| 503 }; | |
| 504 AutoLock lock(tracelog->lock_); | |
| 505 CategoryRegistry::GetOrCreateCategoryLocked( | |
| 506 category_group, category_initializer, &category); | |
| 507 } | |
| 501 DCHECK(category->state_ptr()); | 508 DCHECK(category->state_ptr()); |
| 502 return category->state_ptr(); | 509 return category->state_ptr(); |
| 503 } | 510 } |
| 504 | 511 |
| 505 const char* TraceLog::GetCategoryGroupName( | 512 const char* TraceLog::GetCategoryGroupName( |
| 506 const unsigned char* category_group_enabled) { | 513 const unsigned char* category_group_enabled) { |
| 507 return CategoryRegistry::GetCategoryByStatePtr(category_group_enabled) | 514 return CategoryRegistry::GetCategoryByStatePtr(category_group_enabled) |
| 508 ->name(); | 515 ->name(); |
| 509 } | 516 } |
| 510 | 517 |
| (...skipping 1279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1790 } | 1797 } |
| 1791 | 1798 |
| 1792 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() { | 1799 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() { |
| 1793 if (*category_group_enabled_) { | 1800 if (*category_group_enabled_) { |
| 1794 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, name_, | 1801 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, name_, |
| 1795 event_handle_); | 1802 event_handle_); |
| 1796 } | 1803 } |
| 1797 } | 1804 } |
| 1798 | 1805 |
| 1799 } // namespace trace_event_internal | 1806 } // namespace trace_event_internal |
| OLD | NEW |