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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 | 148 |
149 virtual void AddEvent(const TraceEvent& event) = 0; | 149 virtual void AddEvent(const TraceEvent& event) = 0; |
150 virtual bool HasMoreEvents() const = 0; | 150 virtual bool HasMoreEvents() const = 0; |
151 virtual const TraceEvent& NextEvent() = 0; | 151 virtual const TraceEvent& NextEvent() = 0; |
152 virtual bool IsFull() const = 0; | 152 virtual bool IsFull() const = 0; |
153 virtual size_t CountEnabledByName(const unsigned char* category, | 153 virtual size_t CountEnabledByName(const unsigned char* category, |
154 const std::string& event_name) const = 0; | 154 const std::string& event_name) const = 0; |
155 virtual size_t Size() const = 0; | 155 virtual size_t Size() const = 0; |
156 virtual size_t Capacity() const = 0; | 156 virtual size_t Capacity() const = 0; |
157 virtual const TraceEvent& GetEventAt(size_t index) const = 0; | 157 virtual const TraceEvent& GetEventAt(size_t index) const = 0; |
| 158 virtual TraceBuffer* Clone() const = 0; |
158 }; | 159 }; |
159 | 160 |
160 // TraceResultBuffer collects and converts trace fragments returned by TraceLog | 161 // TraceResultBuffer collects and converts trace fragments returned by TraceLog |
161 // to JSON output. | 162 // to JSON output. |
162 class BASE_EXPORT TraceResultBuffer { | 163 class BASE_EXPORT TraceResultBuffer { |
163 public: | 164 public: |
164 typedef base::Callback<void(const std::string&)> OutputCallback; | 165 typedef base::Callback<void(const std::string&)> OutputCallback; |
165 | 166 |
166 // If you don't need to stream JSON chunks out efficiently, and just want to | 167 // If you don't need to stream JSON chunks out efficiently, and just want to |
167 // get a complete JSON string after calling Finish, use this struct to collect | 168 // get a complete JSON string after calling Finish, use this struct to collect |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 | 312 |
312 // Retrieves the current CategoryFilter. | 313 // Retrieves the current CategoryFilter. |
313 const CategoryFilter& GetCurrentCategoryFilter(); | 314 const CategoryFilter& GetCurrentCategoryFilter(); |
314 | 315 |
315 Options trace_options() const { return trace_options_; } | 316 Options trace_options() const { return trace_options_; } |
316 | 317 |
317 // Enables tracing. See CategoryFilter comments for details | 318 // Enables tracing. See CategoryFilter comments for details |
318 // on how to control what categories will be traced. | 319 // on how to control what categories will be traced. |
319 void SetEnabled(const CategoryFilter& category_filter, Options options); | 320 void SetEnabled(const CategoryFilter& category_filter, Options options); |
320 | 321 |
321 // Disable tracing for all categories. | 322 // Disables tracing for all categories. |
322 void SetDisabled(); | 323 void SetDisabled(); |
323 bool IsEnabled() { return !!enable_count_; } | 324 bool IsEnabled() { return !!enable_count_; } |
324 | 325 |
| 326 // Enables continuous sampling tracing. |
| 327 void SetContinuousSamplingEnabled(); |
| 328 |
| 329 // Disables continuous sampling tracing. |
| 330 void SetContinuousSamplingDisabled(); |
| 331 |
325 // The number of times we have begun recording traces. If tracing is off, | 332 // The number of times we have begun recording traces. If tracing is off, |
326 // returns -1. If tracing is on, then it returns the number of times we have | 333 // returns -1. If tracing is on, then it returns the number of times we have |
327 // recorded a trace. By watching for this number to increment, you can | 334 // recorded a trace. By watching for this number to increment, you can |
328 // passively discover when a new trace has begun. This is then used to | 335 // passively discover when a new trace has begun. This is then used to |
329 // implement the TRACE_EVENT_IS_NEW_TRACE() primitive. | 336 // implement the TRACE_EVENT_IS_NEW_TRACE() primitive. |
330 int GetNumTracesRecorded(); | 337 int GetNumTracesRecorded(); |
331 | 338 |
332 #if defined(OS_ANDROID) | 339 #if defined(OS_ANDROID) |
333 void StartATrace(); | 340 void StartATrace(); |
334 void StopATrace(); | 341 void StopATrace(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 unsigned char flags); | 384 unsigned char flags); |
378 void SetEventCallback(EventCallback cb); | 385 void SetEventCallback(EventCallback cb); |
379 | 386 |
380 // Flush all collected events to the given output callback. The callback will | 387 // Flush all collected events to the given output callback. The callback will |
381 // be called one or more times with IPC-bite-size chunks. The string format is | 388 // be called one or more times with IPC-bite-size chunks. The string format is |
382 // undefined. Use TraceResultBuffer to convert one or more trace strings to | 389 // undefined. Use TraceResultBuffer to convert one or more trace strings to |
383 // JSON. | 390 // JSON. |
384 typedef base::Callback<void(const scoped_refptr<base::RefCountedString>&)> | 391 typedef base::Callback<void(const scoped_refptr<base::RefCountedString>&)> |
385 OutputCallback; | 392 OutputCallback; |
386 void Flush(const OutputCallback& cb); | 393 void Flush(const OutputCallback& cb); |
| 394 void FlushContinuousSamplingTracing(const OutputCallback& cb); |
387 | 395 |
388 // Called by TRACE_EVENT* macros, don't call this directly. | 396 // Called by TRACE_EVENT* macros, don't call this directly. |
389 // The name parameter is a category group for example: | 397 // The name parameter is a category group for example: |
390 // TRACE_EVENT0("renderer,webkit", "WebViewImpl::HandleInputEvent") | 398 // TRACE_EVENT0("renderer,webkit", "WebViewImpl::HandleInputEvent") |
391 static const unsigned char* GetCategoryGroupEnabled(const char* name); | 399 static const unsigned char* GetCategoryGroupEnabled(const char* name); |
392 static const char* GetCategoryGroupName( | 400 static const char* GetCategoryGroupName( |
393 const unsigned char* category_group_enabled); | 401 const unsigned char* category_group_enabled); |
394 | 402 |
395 // Called by TRACE_EVENT* macros, don't call this directly. | 403 // Called by TRACE_EVENT* macros, don't call this directly. |
396 // If |copy| is set, |name|, |arg_name1| and |arg_name2| will be deep copied | 404 // If |copy| is set, |name|, |arg_name1| and |arg_name2| will be deep copied |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 const std::string& event_name); | 443 const std::string& event_name); |
436 // Cancel the watch event. If tracing is enabled, this may race with the | 444 // Cancel the watch event. If tracing is enabled, this may race with the |
437 // watch event notification firing. | 445 // watch event notification firing. |
438 void CancelWatchEvent(); | 446 void CancelWatchEvent(); |
439 | 447 |
440 int process_id() const { return process_id_; } | 448 int process_id() const { return process_id_; } |
441 | 449 |
442 // Exposed for unittesting: | 450 // Exposed for unittesting: |
443 | 451 |
444 void InstallWaitableEventForSamplingTesting(WaitableEvent* waitable_event); | 452 void InstallWaitableEventForSamplingTesting(WaitableEvent* waitable_event); |
| 453 void InstallWaitableEventForContinuousSamplingTesting( |
| 454 WaitableEvent* waitable_event); |
445 | 455 |
446 // Allows deleting our singleton instance. | 456 // Allows deleting our singleton instance. |
447 static void DeleteForTesting(); | 457 static void DeleteForTesting(); |
448 | 458 |
449 // Allow tests to inspect TraceEvents. | 459 // Allow tests to inspect TraceEvents. |
450 size_t GetEventsSize() const { return logged_events_->Size(); } | 460 size_t GetEventsSize() const { return logged_events_->Size(); } |
451 const TraceEvent& GetEventAt(size_t index) const { | 461 const TraceEvent& GetEventAt(size_t index) const { |
452 return logged_events_->GetEventAt(index); | 462 return logged_events_->GetEventAt(index); |
453 } | 463 } |
454 | 464 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 | 535 |
526 private: | 536 private: |
527 TraceLog* trace_log_; | 537 TraceLog* trace_log_; |
528 NotificationCallback callback_copy_; | 538 NotificationCallback callback_copy_; |
529 int notification_; | 539 int notification_; |
530 }; | 540 }; |
531 | 541 |
532 TraceLog(); | 542 TraceLog(); |
533 ~TraceLog(); | 543 ~TraceLog(); |
534 const unsigned char* GetCategoryGroupEnabledInternal(const char* name); | 544 const unsigned char* GetCategoryGroupEnabledInternal(const char* name); |
535 void AddMetadataEvents(); | 545 void AddMetadataEvents(unsigned char flags); |
536 | 546 |
537 #if defined(OS_ANDROID) | 547 #if defined(OS_ANDROID) |
538 void SendToATrace(char phase, | 548 void SendToATrace(char phase, |
539 const char* category_group, | 549 const char* category_group, |
540 const char* name, | 550 const char* name, |
541 unsigned long long id, | 551 unsigned long long id, |
542 int num_args, | 552 int num_args, |
543 const char** arg_names, | 553 const char** arg_names, |
544 const unsigned char* arg_types, | 554 const unsigned char* arg_types, |
545 const unsigned long long* arg_values, | 555 const unsigned long long* arg_values, |
546 scoped_ptr<ConvertableToTraceFormat> convertable_values[], | 556 scoped_ptr<ConvertableToTraceFormat> convertable_values[], |
547 unsigned char flags); | 557 unsigned char flags); |
548 static void ApplyATraceEnabledFlag(unsigned char* category_group_enabled); | 558 static void ApplyATraceEnabledFlag(unsigned char* category_group_enabled); |
549 #endif | 559 #endif |
550 | 560 |
551 TraceBuffer* GetTraceBuffer(); | 561 TraceBuffer* GetTraceBuffer(); |
552 | 562 |
553 // TODO(nduca): switch to per-thread trace buffers to reduce thread | 563 // TODO(nduca): switch to per-thread trace buffers to reduce thread |
554 // synchronization. | 564 // synchronization. |
555 // This lock protects TraceLog member accesses from arbitrary threads. | 565 // This lock protects TraceLog member accesses from arbitrary threads. |
556 Lock lock_; | 566 Lock lock_; |
557 int enable_count_; | 567 int enable_count_; |
| 568 int continuous_sampling_enable_count_; |
558 int num_traces_recorded_; | 569 int num_traces_recorded_; |
559 NotificationCallback notification_callback_; | 570 NotificationCallback notification_callback_; |
560 scoped_ptr<TraceBuffer> logged_events_; | 571 scoped_ptr<TraceBuffer> logged_events_; |
| 572 scoped_ptr<TraceBuffer> continuous_sampling_logged_events_; |
561 EventCallback event_callback_; | 573 EventCallback event_callback_; |
562 bool dispatching_to_observer_list_; | 574 bool dispatching_to_observer_list_; |
563 std::vector<EnabledStateObserver*> enabled_state_observer_list_; | 575 std::vector<EnabledStateObserver*> enabled_state_observer_list_; |
564 | 576 |
565 std::string process_name_; | 577 std::string process_name_; |
566 base::hash_map<int, std::string> process_labels_; | 578 base::hash_map<int, std::string> process_labels_; |
567 int process_sort_index_; | 579 int process_sort_index_; |
568 base::hash_map<int, int> thread_sort_indices_; | 580 base::hash_map<int, int> thread_sort_indices_; |
569 | 581 |
570 base::hash_map<int, std::string> thread_names_; | 582 base::hash_map<int, std::string> thread_names_; |
(...skipping 10 matching lines...) Expand all Loading... |
581 // Allow tests to wake up when certain events occur. | 593 // Allow tests to wake up when certain events occur. |
582 const unsigned char* watch_category_; | 594 const unsigned char* watch_category_; |
583 std::string watch_event_name_; | 595 std::string watch_event_name_; |
584 | 596 |
585 Options trace_options_; | 597 Options trace_options_; |
586 | 598 |
587 // Sampling thread handles. | 599 // Sampling thread handles. |
588 scoped_ptr<TraceSamplingThread> sampling_thread_; | 600 scoped_ptr<TraceSamplingThread> sampling_thread_; |
589 PlatformThreadHandle sampling_thread_handle_; | 601 PlatformThreadHandle sampling_thread_handle_; |
590 | 602 |
| 603 // Continuous sampling thread handles. |
| 604 // TODO(haraken): Merge this thread with the normal sampling thread. |
| 605 // Currently we launch two sampling threads when we |
| 606 // record normal tracing with enabling continuous sampling. |
| 607 scoped_ptr<TraceSamplingThread> continuous_sampling_thread_; |
| 608 PlatformThreadHandle continuous_sampling_thread_handle_; |
| 609 |
591 CategoryFilter category_filter_; | 610 CategoryFilter category_filter_; |
592 | 611 |
593 DISALLOW_COPY_AND_ASSIGN(TraceLog); | 612 DISALLOW_COPY_AND_ASSIGN(TraceLog); |
594 }; | 613 }; |
595 | 614 |
596 } // namespace debug | 615 } // namespace debug |
597 } // namespace base | 616 } // namespace base |
598 | 617 |
599 #endif // BASE_DEBUG_TRACE_EVENT_IMPL_H_ | 618 #endif // BASE_DEBUG_TRACE_EVENT_IMPL_H_ |
OLD | NEW |