| 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 | 5 |
| 6 #ifndef BASE_DEBUG_TRACE_EVENT_IMPL_H_ | 6 #ifndef BASE_DEBUG_TRACE_EVENT_IMPL_H_ |
| 7 #define BASE_DEBUG_TRACE_EVENT_IMPL_H_ | 7 #define BASE_DEBUG_TRACE_EVENT_IMPL_H_ |
| 8 | 8 |
| 9 #include <stack> | 9 #include <stack> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 int GetNumTracesRecorded(); | 325 int GetNumTracesRecorded(); |
| 326 | 326 |
| 327 #if defined(OS_ANDROID) | 327 #if defined(OS_ANDROID) |
| 328 void StartATrace(); | 328 void StartATrace(); |
| 329 void StopATrace(); | 329 void StopATrace(); |
| 330 #endif | 330 #endif |
| 331 | 331 |
| 332 // Enabled state listeners give a callback when tracing is enabled or | 332 // Enabled state listeners give a callback when tracing is enabled or |
| 333 // disabled. This can be used to tie into other library's tracing systems | 333 // disabled. This can be used to tie into other library's tracing systems |
| 334 // on-demand. | 334 // on-demand. |
| 335 class EnabledStateChangedObserver { | 335 class EnabledStateObserver { |
| 336 public: | 336 public: |
| 337 // Called just before the tracing system becomes | 337 // Called just after the tracing system becomes enabled, outside of the |
| 338 // enabled. TraceLog::IsEnabled will return false at this point and trace | 338 // |lock_|. TraceLog::IsEnabled() is true at this point. |
| 339 // macros and methods called within the observer will deadlock. | 339 virtual void OnTraceLogEnabled() = 0; |
| 340 virtual void OnTraceLogWillEnable() { } | |
| 341 | 340 |
| 342 // Called just before the tracing system disables. TraceLog::IsEnabled is | 341 // Called just after the tracing system disables, outside of the |lock_|. |
| 343 // still false at this point TRACE macros will still be capturing | 342 // TraceLog::IsEnabled() is false at this point. |
| 344 // data. However, trace macros and methods called within the observer will | 343 virtual void OnTraceLogDisabled() = 0; |
| 345 // deadlock. | |
| 346 virtual void OnTraceLogWillDisable() { } | |
| 347 }; | 344 }; |
| 348 void AddEnabledStateObserver(EnabledStateChangedObserver* listener); | 345 void AddEnabledStateObserver(EnabledStateObserver* listener); |
| 349 void RemoveEnabledStateObserver(EnabledStateChangedObserver* listener); | 346 void RemoveEnabledStateObserver(EnabledStateObserver* listener); |
| 350 | 347 |
| 351 float GetBufferPercentFull() const; | 348 float GetBufferPercentFull() const; |
| 352 | 349 |
| 353 // Set the thread-safe notification callback. The callback can occur at any | 350 // Set the thread-safe notification callback. The callback can occur at any |
| 354 // time and from any thread. WARNING: It is possible for the previously set | 351 // time and from any thread. WARNING: It is possible for the previously set |
| 355 // callback to be called during OR AFTER a call to SetNotificationCallback. | 352 // callback to be called during OR AFTER a call to SetNotificationCallback. |
| 356 // Therefore, the target of the callback must either be a global function, | 353 // Therefore, the target of the callback must either be a global function, |
| 357 // ref-counted object or a LazyInstance with Leaky traits (or equivalent). | 354 // ref-counted object or a LazyInstance with Leaky traits (or equivalent). |
| 358 typedef base::Callback<void(int)> NotificationCallback; | 355 typedef base::Callback<void(int)> NotificationCallback; |
| 359 void SetNotificationCallback(const NotificationCallback& cb); | 356 void SetNotificationCallback(const NotificationCallback& cb); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 const TraceEvent& GetEventAt(size_t index) const { | 448 const TraceEvent& GetEventAt(size_t index) const { |
| 452 return logged_events_->GetEventAt(index); | 449 return logged_events_->GetEventAt(index); |
| 453 } | 450 } |
| 454 | 451 |
| 455 void SetProcessID(int process_id); | 452 void SetProcessID(int process_id); |
| 456 | 453 |
| 457 // Allow setting an offset between the current TimeTicks time and the time | 454 // Allow setting an offset between the current TimeTicks time and the time |
| 458 // that should be reported. | 455 // that should be reported. |
| 459 void SetTimeOffset(TimeDelta offset); | 456 void SetTimeOffset(TimeDelta offset); |
| 460 | 457 |
| 458 size_t GetObserverCountForTest() const; |
| 459 |
| 461 private: | 460 private: |
| 462 // This allows constructor and destructor to be private and usable only | 461 // This allows constructor and destructor to be private and usable only |
| 463 // by the Singleton class. | 462 // by the Singleton class. |
| 464 friend struct StaticMemorySingletonTraits<TraceLog>; | 463 friend struct StaticMemorySingletonTraits<TraceLog>; |
| 465 | 464 |
| 466 // Enable/disable each category group based on the current category_filter_. | 465 // Enable/disable each category group based on the current category_filter_. |
| 467 // If the category group contains a category that matches an included category | 466 // If the category group contains a category that matches an included category |
| 468 // pattern, that category group will be enabled. | 467 // pattern, that category group will be enabled. |
| 469 void EnableIncludedCategoryGroups(); | 468 void EnableIncludedCategoryGroups(); |
| 470 void EnableIncludedCategoryGroup(int category_index); | 469 void EnableIncludedCategoryGroup(int category_index); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 // TODO(nduca): switch to per-thread trace buffers to reduce thread | 530 // TODO(nduca): switch to per-thread trace buffers to reduce thread |
| 532 // synchronization. | 531 // synchronization. |
| 533 // This lock protects TraceLog member accesses from arbitrary threads. | 532 // This lock protects TraceLog member accesses from arbitrary threads. |
| 534 Lock lock_; | 533 Lock lock_; |
| 535 int enable_count_; | 534 int enable_count_; |
| 536 int num_traces_recorded_; | 535 int num_traces_recorded_; |
| 537 NotificationCallback notification_callback_; | 536 NotificationCallback notification_callback_; |
| 538 scoped_ptr<TraceBuffer> logged_events_; | 537 scoped_ptr<TraceBuffer> logged_events_; |
| 539 EventCallback event_callback_; | 538 EventCallback event_callback_; |
| 540 bool dispatching_to_observer_list_; | 539 bool dispatching_to_observer_list_; |
| 541 ObserverList<EnabledStateChangedObserver> enabled_state_observer_list_; | 540 std::vector<EnabledStateObserver*> enabled_state_observer_list_; |
| 542 | 541 |
| 543 base::hash_map<int, std::string> thread_names_; | 542 base::hash_map<int, std::string> thread_names_; |
| 544 base::hash_map<int, std::stack<TimeTicks> > thread_event_start_times_; | 543 base::hash_map<int, std::stack<TimeTicks> > thread_event_start_times_; |
| 545 base::hash_map<std::string, int> thread_colors_; | 544 base::hash_map<std::string, int> thread_colors_; |
| 546 | 545 |
| 547 // XORed with TraceID to make it unlikely to collide with other processes. | 546 // XORed with TraceID to make it unlikely to collide with other processes. |
| 548 unsigned long long process_id_hash_; | 547 unsigned long long process_id_hash_; |
| 549 | 548 |
| 550 int process_id_; | 549 int process_id_; |
| 551 | 550 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 563 | 562 |
| 564 CategoryFilter category_filter_; | 563 CategoryFilter category_filter_; |
| 565 | 564 |
| 566 DISALLOW_COPY_AND_ASSIGN(TraceLog); | 565 DISALLOW_COPY_AND_ASSIGN(TraceLog); |
| 567 }; | 566 }; |
| 568 | 567 |
| 569 } // namespace debug | 568 } // namespace debug |
| 570 } // namespace base | 569 } // namespace base |
| 571 | 570 |
| 572 #endif // BASE_DEBUG_TRACE_EVENT_IMPL_H_ | 571 #endif // BASE_DEBUG_TRACE_EVENT_IMPL_H_ |
| OLD | NEW |