summaryrefslogtreecommitdiffstats
path: root/base/debug/trace_event.cc
diff options
context:
space:
mode:
authorjbates@chromium.org <jbates@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-21 23:31:51 +0000
committerjbates@chromium.org <jbates@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-21 23:31:51 +0000
commit027fc03bee0791e0895a80cd528cd19b16d3d415 (patch)
tree20be477b007b3ce104d1c4aac56029d7e107e60e /base/debug/trace_event.cc
parent66699597a5420264d0ec7c8c61f8a2f1ff35ed22 (diff)
downloadchromium_src-027fc03bee0791e0895a80cd528cd19b16d3d415.zip
chromium_src-027fc03bee0791e0895a80cd528cd19b16d3d415.tar.gz
chromium_src-027fc03bee0791e0895a80cd528cd19b16d3d415.tar.bz2
Internalize JSON chunk merging to trace_event.h API.
BUG=100291 TEST=base_unittests, content_unittests Review URL: http://codereview.chromium.org/8355024 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@106808 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/debug/trace_event.cc')
-rw-r--r--base/debug/trace_event.cc45
1 files changed, 43 insertions, 2 deletions
diff --git a/base/debug/trace_event.cc b/base/debug/trace_event.cc
index 347644f..3e03d4a 100644
--- a/base/debug/trace_event.cc
+++ b/base/debug/trace_event.cc
@@ -9,6 +9,7 @@
#if defined(OS_WIN)
#include "base/debug/trace_event_win.h"
#endif
+#include "base/bind.h"
#include "base/format_macros.h"
#include "base/memory/ref_counted_memory.h"
#include "base/process_util.h"
@@ -224,13 +225,11 @@ void TraceEvent::AppendEventsAsJSON(const std::vector<TraceEvent>& events,
size_t start,
size_t count,
std::string* out) {
- *out += "[";
for (size_t i = 0; i < count && start + i < events.size(); ++i) {
if (i > 0)
*out += ",";
events[i + start].AppendAsJSON(out);
}
- *out += "]";
}
void TraceEvent::AppendAsJSON(std::string* out) const {
@@ -262,6 +261,48 @@ void TraceEvent::AppendAsJSON(std::string* out) const {
////////////////////////////////////////////////////////////////////////////////
//
+// TraceResultBuffer
+//
+////////////////////////////////////////////////////////////////////////////////
+
+TraceResultBuffer::OutputCallback
+ TraceResultBuffer::SimpleOutput::GetCallback() {
+ return base::Bind(&SimpleOutput::Append, base::Unretained(this));
+}
+
+void TraceResultBuffer::SimpleOutput::Append(
+ const std::string& json_trace_output) {
+ json_output += json_trace_output;
+}
+
+TraceResultBuffer::TraceResultBuffer() : append_comma_(false) {
+}
+
+TraceResultBuffer::~TraceResultBuffer() {
+}
+
+void TraceResultBuffer::SetOutputCallback(OutputCallback json_chunk_callback) {
+ output_callback_ = json_chunk_callback;
+}
+
+void TraceResultBuffer::Start() {
+ append_comma_ = false;
+ output_callback_.Run("[");
+}
+
+void TraceResultBuffer::AddFragment(const std::string& trace_fragment) {
+ if (append_comma_)
+ output_callback_.Run(",");
+ append_comma_ = true;
+ output_callback_.Run(trace_fragment);
+}
+
+void TraceResultBuffer::Finish() {
+ output_callback_.Run("]");
+}
+
+////////////////////////////////////////////////////////////////////////////////
+//
// TraceLog
//
////////////////////////////////////////////////////////////////////////////////