Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(117)

Side by Side Diff: base/trace_event/trace_log.cc

Issue 2440443002: tracing: remove WatchEvent feature (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/trace_event/trace_log.h ('k') | chrome/test/base/tracing.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 return Singleton<TraceLog, LeakySingletonTraits<TraceLog>>::get(); 461 return Singleton<TraceLog, LeakySingletonTraits<TraceLog>>::get();
462 } 462 }
463 463
464 TraceLog::TraceLog() 464 TraceLog::TraceLog()
465 : enabled_modes_(0), 465 : enabled_modes_(0),
466 num_traces_recorded_(0), 466 num_traces_recorded_(0),
467 dispatching_to_observer_list_(false), 467 dispatching_to_observer_list_(false),
468 process_sort_index_(0), 468 process_sort_index_(0),
469 process_id_hash_(0), 469 process_id_hash_(0),
470 process_id_(0), 470 process_id_(0),
471 watch_category_(0),
472 trace_options_(kInternalRecordUntilFull), 471 trace_options_(kInternalRecordUntilFull),
473 trace_config_(TraceConfig()), 472 trace_config_(TraceConfig()),
474 thread_shared_chunk_index_(0), 473 thread_shared_chunk_index_(0),
475 generation_(0), 474 generation_(0),
476 use_worker_thread_(false) { 475 use_worker_thread_(false) {
477 // Trace is enabled or disabled on one thread while other threads are 476 // Trace is enabled or disabled on one thread while other threads are
478 // accessing the enabled flag. We don't care whether edge-case events are 477 // accessing the enabled flag. We don't care whether edge-case events are
479 // traced or not, so we allow races on the enabled flag to keep the trace 478 // traced or not, so we allow races on the enabled flag to keep the trace
480 // macros fast. 479 // macros fast.
481 // TODO(jbates): ANNOTATE_BENIGN_RACE_SIZED crashes windows TSAN bots: 480 // TODO(jbates): ANNOTATE_BENIGN_RACE_SIZED crashes windows TSAN bots:
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
877 876
878 bool is_recording_mode_disabled = 877 bool is_recording_mode_disabled =
879 (enabled_modes_ & RECORDING_MODE) && (modes_to_disable & RECORDING_MODE); 878 (enabled_modes_ & RECORDING_MODE) && (modes_to_disable & RECORDING_MODE);
880 enabled_modes_ &= ~modes_to_disable; 879 enabled_modes_ &= ~modes_to_disable;
881 880
882 if (modes_to_disable & FILTERING_MODE) 881 if (modes_to_disable & FILTERING_MODE)
883 enabled_event_filters_.clear(); 882 enabled_event_filters_.clear();
884 883
885 if (modes_to_disable & RECORDING_MODE) { 884 if (modes_to_disable & RECORDING_MODE) {
886 trace_config_.Clear(); 885 trace_config_.Clear();
887
888 subtle::NoBarrier_Store(&watch_category_, 0);
889 watch_event_name_.clear();
890 } 886 }
891 887
892 UpdateCategoryGroupEnabledFlags(); 888 UpdateCategoryGroupEnabledFlags();
893 889
894 // Add metadata events and notify observers only if recording mode was 890 // Add metadata events and notify observers only if recording mode was
895 // disabled now. 891 // disabled now.
896 if (!is_recording_mode_disabled) 892 if (!is_recording_mode_disabled)
897 return; 893 return;
898 894
899 AddMetadataEventsWhileLocked(); 895 AddMetadataEventsWhileLocked();
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after
1474 if (trace_options() & kInternalEchoToConsole) { 1470 if (trace_options() & kInternalEchoToConsole) {
1475 console_message = EventToConsoleMessage( 1471 console_message = EventToConsoleMessage(
1476 phase == TRACE_EVENT_PHASE_COMPLETE ? TRACE_EVENT_PHASE_BEGIN : phase, 1472 phase == TRACE_EVENT_PHASE_COMPLETE ? TRACE_EVENT_PHASE_BEGIN : phase,
1477 timestamp, trace_event); 1473 timestamp, trace_event);
1478 } 1474 }
1479 } 1475 }
1480 1476
1481 if (!console_message.empty()) 1477 if (!console_message.empty())
1482 LOG(ERROR) << console_message; 1478 LOG(ERROR) << console_message;
1483 1479
1484 if (reinterpret_cast<const unsigned char*>(
1485 subtle::NoBarrier_Load(&watch_category_)) == category_group_enabled) {
1486 bool event_name_matches;
1487 WatchEventCallback watch_event_callback_copy;
1488 {
1489 AutoLock lock(lock_);
1490 event_name_matches = watch_event_name_ == name;
1491 watch_event_callback_copy = watch_event_callback_;
1492 }
1493 if (event_name_matches) {
1494 if (!watch_event_callback_copy.is_null())
1495 watch_event_callback_copy.Run();
1496 }
1497 }
1498
1499 return handle; 1480 return handle;
1500 } 1481 }
1501 1482
1502 void TraceLog::AddMetadataEvent( 1483 void TraceLog::AddMetadataEvent(
1503 const unsigned char* category_group_enabled, 1484 const unsigned char* category_group_enabled,
1504 const char* name, 1485 const char* name,
1505 int num_args, 1486 int num_args,
1506 const char** arg_names, 1487 const char** arg_names,
1507 const unsigned char* arg_types, 1488 const unsigned char* arg_types,
1508 const unsigned long long* arg_values, 1489 const unsigned long long* arg_values,
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1640 } 1621 }
1641 } 1622 }
1642 1623
1643 if (!console_message.empty()) 1624 if (!console_message.empty())
1644 LOG(ERROR) << console_message; 1625 LOG(ERROR) << console_message;
1645 1626
1646 if (category_group_enabled_local & ENABLED_FOR_FILTERING) 1627 if (category_group_enabled_local & ENABLED_FOR_FILTERING)
1647 EndFilteredEvent(category_group_enabled, name, handle); 1628 EndFilteredEvent(category_group_enabled, name, handle);
1648 } 1629 }
1649 1630
1650 void TraceLog::SetWatchEvent(const std::string& category_name,
1651 const std::string& event_name,
1652 const WatchEventCallback& callback) {
1653 const unsigned char* category =
1654 GetCategoryGroupEnabled(category_name.c_str());
1655 AutoLock lock(lock_);
1656 subtle::NoBarrier_Store(&watch_category_,
1657 reinterpret_cast<subtle::AtomicWord>(category));
1658 watch_event_name_ = event_name;
1659 watch_event_callback_ = callback;
1660 }
1661
1662 void TraceLog::CancelWatchEvent() {
1663 AutoLock lock(lock_);
1664 subtle::NoBarrier_Store(&watch_category_, 0);
1665 watch_event_name_.clear();
1666 watch_event_callback_.Reset();
1667 }
1668
1669 uint64_t TraceLog::MangleEventId(uint64_t id) { 1631 uint64_t TraceLog::MangleEventId(uint64_t id) {
1670 return id ^ process_id_hash_; 1632 return id ^ process_id_hash_;
1671 } 1633 }
1672 1634
1673 void TraceLog::AddMetadataEventsWhileLocked() { 1635 void TraceLog::AddMetadataEventsWhileLocked() {
1674 lock_.AssertAcquired(); 1636 lock_.AssertAcquired();
1675 1637
1676 // Move metadata added by |AddMetadataEvent| into the trace log. 1638 // Move metadata added by |AddMetadataEvent| into the trace log.
1677 while (!metadata_events_.empty()) { 1639 while (!metadata_events_.empty()) {
1678 TraceEvent* event = AddEventToThreadSharedChunkWhileLocked(nullptr, false); 1640 TraceEvent* event = AddEventToThreadSharedChunkWhileLocked(nullptr, false);
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
1928 } 1890 }
1929 1891
1930 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() { 1892 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() {
1931 if (*category_group_enabled_) { 1893 if (*category_group_enabled_) {
1932 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, name_, 1894 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, name_,
1933 event_handle_); 1895 event_handle_);
1934 } 1896 }
1935 } 1897 }
1936 1898
1937 } // namespace trace_event_internal 1899 } // namespace trace_event_internal
OLDNEW
« no previous file with comments | « base/trace_event/trace_log.h ('k') | chrome/test/base/tracing.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698