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

Side by Side Diff: base/debug/trace_event.h

Issue 8373018: Internalize JSON chunk merging to trace_event.h API (retry). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more BASE_EXPORT Created 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | base/debug/trace_event.cc » ('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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // Trace events are for tracking application performance. 5 // Trace events are for tracking application performance.
6 // 6 //
7 // Events are issued against categories. Whereas LOG's 7 // Events are issued against categories. Whereas LOG's
8 // categories are statically defined, TRACE categories are created 8 // categories are statically defined, TRACE categories are created
9 // implicitly with a string. For example: 9 // implicitly with a string. For example:
10 // TRACE_EVENT_INSTANT0("MY_SUBSYSTEM", "SomeImportantEvent") 10 // TRACE_EVENT_INSTANT0("MY_SUBSYSTEM", "SomeImportantEvent")
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 TimeTicks timestamp_; 508 TimeTicks timestamp_;
509 TraceEventPhase phase_; 509 TraceEventPhase phase_;
510 const TraceCategory* category_; 510 const TraceCategory* category_;
511 const char* name_; 511 const char* name_;
512 const char* arg_names_[kTraceMaxNumArgs]; 512 const char* arg_names_[kTraceMaxNumArgs];
513 TraceValue arg_values_[kTraceMaxNumArgs]; 513 TraceValue arg_values_[kTraceMaxNumArgs];
514 scoped_refptr<base::RefCountedString> parameter_copy_storage_; 514 scoped_refptr<base::RefCountedString> parameter_copy_storage_;
515 }; 515 };
516 516
517 517
518 // TraceResultBuffer collects and converts trace fragments returned by TraceLog
519 // to JSON output.
520 class BASE_EXPORT TraceResultBuffer {
521 public:
522 typedef base::Callback<void(const std::string&)> OutputCallback;
523
524 // If you don't need to stream JSON chunks out efficiently, and just want to
525 // get a complete JSON string after calling Finish, use this struct to collect
526 // JSON trace output.
527 struct BASE_EXPORT SimpleOutput {
528 OutputCallback GetCallback();
529 void Append(const std::string& json_string);
530
531 // Do what you want with the json_output_ string after calling
532 // TraceResultBuffer::Finish.
533 std::string json_output;
534 };
535
536 TraceResultBuffer();
537 ~TraceResultBuffer();
538
539 // Set callback. The callback will be called during Start with the initial
540 // JSON output and during AddFragment and Finish with following JSON output
541 // chunks. The callback target must live past the last calls to
542 // TraceResultBuffer::Start/AddFragment/Finish.
543 void SetOutputCallback(OutputCallback json_chunk_callback);
544
545 // Start JSON output. This resets all internal state, so you can reuse
546 // the TraceResultBuffer by calling Start.
547 void Start();
548
549 // Call AddFragment 0 or more times to add trace fragments from TraceLog.
550 void AddFragment(const std::string& trace_fragment);
551
552 // When all fragments have been added, call Finish to complete the JSON
553 // formatted output.
554 void Finish();
555
556 private:
557 OutputCallback output_callback_;
558 bool append_comma_;
559 };
560
561
518 class BASE_EXPORT TraceLog { 562 class BASE_EXPORT TraceLog {
519 public: 563 public:
520 // Flags for passing to AddTraceEvent. 564 // Flags for passing to AddTraceEvent.
521 enum EventFlags { 565 enum EventFlags {
522 EVENT_FLAG_NONE = 0, 566 EVENT_FLAG_NONE = 0,
523 EVENT_FLAG_COPY = 1<<0 567 EVENT_FLAG_COPY = 1<<0
524 }; 568 };
525 569
526 static TraceLog* GetInstance(); 570 static TraceLog* GetInstance();
527 571
(...skipping 14 matching lines...) Expand all
542 // Disable tracing for all categories. 586 // Disable tracing for all categories.
543 void SetDisabled(); 587 void SetDisabled();
544 // Helper method to enable/disable tracing for all categories. 588 // Helper method to enable/disable tracing for all categories.
545 void SetEnabled(bool enabled); 589 void SetEnabled(bool enabled);
546 bool IsEnabled() { return enabled_; } 590 bool IsEnabled() { return enabled_; }
547 591
548 float GetBufferPercentFull() const; 592 float GetBufferPercentFull() const;
549 593
550 // When enough events are collected, they are handed (in bulk) to 594 // When enough events are collected, they are handed (in bulk) to
551 // the output callback. If no callback is set, the output will be 595 // the output callback. If no callback is set, the output will be
552 // silently dropped. The callback must be thread safe. 596 // silently dropped. The callback must be thread safe. The string format is
597 // undefined. Use TraceResultBuffer to convert one or more trace strings to
598 // JSON.
553 typedef RefCountedData<std::string> RefCountedString; 599 typedef RefCountedData<std::string> RefCountedString;
554 typedef base::Callback<void(scoped_refptr<RefCountedString>)> OutputCallback; 600 typedef base::Callback<void(scoped_refptr<RefCountedString>)> OutputCallback;
555 void SetOutputCallback(const OutputCallback& cb); 601 void SetOutputCallback(const OutputCallback& cb);
556 602
557 // The trace buffer does not flush dynamically, so when it fills up, 603 // The trace buffer does not flush dynamically, so when it fills up,
558 // subsequent trace events will be dropped. This callback is generated when 604 // subsequent trace events will be dropped. This callback is generated when
559 // the trace buffer is full. The callback must be thread safe. 605 // the trace buffer is full. The callback must be thread safe.
560 typedef base::Callback<void(void)> BufferFullCallback; 606 typedef base::Callback<void(void)> BufferFullCallback;
561 void SetBufferFullCallback(const BufferFullCallback& cb); 607 void SetBufferFullCallback(const BufferFullCallback& cb);
562 608
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 Data* p_data_; 744 Data* p_data_;
699 Data data_; 745 Data data_;
700 }; 746 };
701 747
702 } // namespace internal 748 } // namespace internal
703 749
704 } // namespace debug 750 } // namespace debug
705 } // namespace base 751 } // namespace base
706 752
707 #endif // BASE_DEBUG_TRACE_EVENT_H_ 753 #endif // BASE_DEBUG_TRACE_EVENT_H_
OLDNEW
« no previous file with comments | « no previous file | base/debug/trace_event.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698