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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/debug/trace_event.cc » ('j') | base/debug/trace_event_unittest.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/debug/trace_event.h
diff --git a/base/debug/trace_event.h b/base/debug/trace_event.h
index d5aa256dc15cb769c2de0a312eb5c2084f7f56ba..ec1884414c5cfce71de49a370a9cc11fe93dc1a3 100644
--- a/base/debug/trace_event.h
+++ b/base/debug/trace_event.h
@@ -515,6 +515,50 @@ class TraceEvent {
};
+// TraceResultBuffer collects and converts trace fragments returned by TraceLog
+// to JSON output.
+class TraceResultBuffer {
joth 2011/10/24 08:09:29 BASE_EXPORT ?
+ public:
+ typedef base::Callback<void(const std::string&)> OutputCallback;
+
+ // If you don't need to stream JSON chunks out efficiently, and just want to
+ // get a complete JSON string after calling Finish, use this struct to collect
+ // JSON trace output.
+ struct SimpleOutput {
+ OutputCallback GetCallback();
+ void Append(const std::string& json_string);
+
+ // Do what you want with the json_output_ string after calling
+ // TraceResultBuffer::Finish.
+ std::string json_output;
+ };
+
+ TraceResultBuffer();
+ ~TraceResultBuffer();
+
+ // Set callback. The callback will be called during Start with the initial
+ // JSON output and during AddFragment and Finish with following JSON output
+ // chunks. The callback target must live past the last calls to
+ // TraceResultBuffer::Start/AddFragment/Finish.
+ void SetOutputCallback(OutputCallback json_chunk_callback);
+
+ // Start JSON output. This resets all internal state, so you can reuse
+ // the TraceResultBuffer by calling Start.
+ void Start();
+
+ // Call AddFragment 0 or more times to add trace fragments from TraceLog.
+ void AddFragment(const std::string& trace_fragment);
+
+ // When all fragments have been added, call Finish to complete the JSON
+ // formatted output.
+ void Finish();
+
+ private:
+ OutputCallback output_callback_;
+ bool append_comma_;
+};
+
+
class BASE_EXPORT TraceLog {
public:
// Flags for passing to AddTraceEvent.
@@ -549,7 +593,9 @@ class BASE_EXPORT TraceLog {
// When enough events are collected, they are handed (in bulk) to
// the output callback. If no callback is set, the output will be
- // silently dropped. The callback must be thread safe.
+ // silently dropped. The callback must be thread safe. The string format is
+ // undefined. Use TraceResultBuffer to convert one or more trace strings to
+ // JSON.
typedef RefCountedData<std::string> RefCountedString;
typedef base::Callback<void(scoped_refptr<RefCountedString>)> OutputCallback;
void SetOutputCallback(const OutputCallback& cb);
« no previous file with comments | « no previous file | base/debug/trace_event.cc » ('j') | base/debug/trace_event_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698