summaryrefslogtreecommitdiffstats
path: root/base/debug/trace_event.h
diff options
context:
space:
mode:
authorjbates@chromium.org <jbates@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-24 16:34:08 +0000
committerjbates@chromium.org <jbates@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-24 16:34:08 +0000
commit91ea6343d74a2cd7457d2a8b1521e3fd4724d7f5 (patch)
treec28b5e27b1d369c35405b53f603e7a9796089ac8 /base/debug/trace_event.h
parent7d1208ce239e0298f016e6839f25551975de2269 (diff)
downloadchromium_src-91ea6343d74a2cd7457d2a8b1521e3fd4724d7f5.zip
chromium_src-91ea6343d74a2cd7457d2a8b1521e3fd4724d7f5.tar.gz
chromium_src-91ea6343d74a2cd7457d2a8b1521e3fd4724d7f5.tar.bz2
Internalize JSON chunk merging to trace_event.h API (retry).
Original review: http://codereview.chromium.org/8355024/ BUG=100291 TEST=base_unittests, content_unittests Review URL: http://codereview.chromium.org/8373018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@106924 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/debug/trace_event.h')
-rw-r--r--base/debug/trace_event.h48
1 files changed, 47 insertions, 1 deletions
diff --git a/base/debug/trace_event.h b/base/debug/trace_event.h
index d5aa256..b4f7d28 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 BASE_EXPORT TraceResultBuffer {
+ 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 BASE_EXPORT 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);