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

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

Issue 8355024: Internalize JSON chunk management to trace_event.h API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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') | base/debug/trace_event.cc » ('J')
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 merges trace fragments returned by TraceLog.
519 // Add all the trace event fragments with AddFragment and then call GetJSON to
520 // retrieve the full set of trace events in JSON format.
521 class TraceResultBuffer {
522 public:
523 TraceResultBuffer();
524 ~TraceResultBuffer();
525
526 void AddFragment(const std::string& trace_fragment);
nduca 2011/10/20 00:28:03 Brownie points: typedef TraceFragment so nobody se
jbates 2011/10/20 22:18:49 I wanted to do this as well, but I didn't want to
nduca 2011/10/20 23:20:05 I realize its work, but we both agree its the righ
jbates 2011/10/20 23:55:13 Yup, we agree it's a good design, but low priority
527
528 void GetJSON(std::string* json_trace_output);
529
530 private:
531 std::vector<std::string> fragments_;
532 };
533
534
518 class BASE_EXPORT TraceLog { 535 class BASE_EXPORT TraceLog {
519 public: 536 public:
520 // Flags for passing to AddTraceEvent. 537 // Flags for passing to AddTraceEvent.
521 enum EventFlags { 538 enum EventFlags {
522 EVENT_FLAG_NONE = 0, 539 EVENT_FLAG_NONE = 0,
523 EVENT_FLAG_COPY = 1<<0 540 EVENT_FLAG_COPY = 1<<0
524 }; 541 };
525 542
526 static TraceLog* GetInstance(); 543 static TraceLog* GetInstance();
527 544
(...skipping 14 matching lines...) Expand all
542 // Disable tracing for all categories. 559 // Disable tracing for all categories.
543 void SetDisabled(); 560 void SetDisabled();
544 // Helper method to enable/disable tracing for all categories. 561 // Helper method to enable/disable tracing for all categories.
545 void SetEnabled(bool enabled); 562 void SetEnabled(bool enabled);
546 bool IsEnabled() { return enabled_; } 563 bool IsEnabled() { return enabled_; }
547 564
548 float GetBufferPercentFull() const; 565 float GetBufferPercentFull() const;
549 566
550 // When enough events are collected, they are handed (in bulk) to 567 // When enough events are collected, they are handed (in bulk) to
551 // the output callback. If no callback is set, the output will be 568 // the output callback. If no callback is set, the output will be
552 // silently dropped. The callback must be thread safe. 569 // silently dropped. The callback must be thread safe. The string format is
570 // undefined. Use TraceResultBuffer to convert one or more trace strings to
571 // JSON.
553 typedef RefCountedData<std::string> RefCountedString; 572 typedef RefCountedData<std::string> RefCountedString;
554 typedef base::Callback<void(scoped_refptr<RefCountedString>)> OutputCallback; 573 typedef base::Callback<void(scoped_refptr<RefCountedString>)> OutputCallback;
555 void SetOutputCallback(const OutputCallback& cb); 574 void SetOutputCallback(const OutputCallback& cb);
556 575
557 // The trace buffer does not flush dynamically, so when it fills up, 576 // The trace buffer does not flush dynamically, so when it fills up,
558 // subsequent trace events will be dropped. This callback is generated when 577 // subsequent trace events will be dropped. This callback is generated when
559 // the trace buffer is full. The callback must be thread safe. 578 // the trace buffer is full. The callback must be thread safe.
560 typedef base::Callback<void(void)> BufferFullCallback; 579 typedef base::Callback<void(void)> BufferFullCallback;
561 void SetBufferFullCallback(const BufferFullCallback& cb); 580 void SetBufferFullCallback(const BufferFullCallback& cb);
562 581
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 Data* p_data_; 717 Data* p_data_;
699 Data data_; 718 Data data_;
700 }; 719 };
701 720
702 } // namespace internal 721 } // namespace internal
703 722
704 } // namespace debug 723 } // namespace debug
705 } // namespace base 724 } // namespace base
706 725
707 #endif // BASE_DEBUG_TRACE_EVENT_H_ 726 #endif // BASE_DEBUG_TRACE_EVENT_H_
OLDNEW
« no previous file with comments | « no previous file | base/debug/trace_event.cc » ('j') | base/debug/trace_event.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698