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

Unified Diff: content/browser/trace_subscriber_stdio.cc

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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/trace_subscriber_stdio.h ('k') | content/browser/trace_subscriber_stdio_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/trace_subscriber_stdio.cc
diff --git a/content/browser/trace_subscriber_stdio.cc b/content/browser/trace_subscriber_stdio.cc
index bf6a8fccd2adc84ad88e86535eaf5a7495d81ce7..901aea09b100ccc361084be445a501d672ada280 100644
--- a/content/browser/trace_subscriber_stdio.cc
+++ b/content/browser/trace_subscriber_stdio.cc
@@ -4,6 +4,7 @@
#include "content/browser/trace_subscriber_stdio.h"
+#include "base/bind.h"
#include "base/logging.h"
TraceSubscriberStdio::TraceSubscriberStdio() : file_(0) {
@@ -22,8 +23,9 @@ bool TraceSubscriberStdio::OpenFile(const FilePath& path) {
CloseFile();
file_ = file_util::OpenFile(path, "w+");
if (IsValid()) {
- // FIXME: the file format expects it to start with "[".
- fputc('[', file_);
+ trace_buffer_.SetOutputCallback(base::Bind(&TraceSubscriberStdio::Write,
+ base::Unretained(this)));
+ trace_buffer_.Start();
return true;
} else {
LOG(ERROR) << "Failed to open performance trace file: " << path.value();
@@ -33,8 +35,6 @@ bool TraceSubscriberStdio::OpenFile(const FilePath& path) {
void TraceSubscriberStdio::CloseFile() {
if (file_) {
- // FIXME: the file format expects it to end with "]".
- fputc(']', file_);
fclose(file_);
file_ = 0;
}
@@ -45,27 +45,21 @@ bool TraceSubscriberStdio::IsValid() {
}
void TraceSubscriberStdio::OnEndTracingComplete() {
+ trace_buffer_.Finish();
CloseFile();
}
void TraceSubscriberStdio::OnTraceDataCollected(
- const std::string& json_events) {
- if (!IsValid()) {
- return;
- }
-
- // FIXME: "json_events" currently comes with "[" and "]". But the file doesn't
- // expect them. So remove them when writing to the file.
- CHECK_GE(json_events.size(), 2u);
- const char* data = json_events.data() + 1;
- size_t size = json_events.size() - 2;
+ const std::string& trace_fragment) {
+ trace_buffer_.AddFragment(trace_fragment);
+}
- size_t written = fwrite(data, 1, size, file_);
- if (written != size) {
- LOG(ERROR) << "Error " << ferror(file_) << " when writing to trace file";
- fclose(file_);
- file_ = 0;
- } else {
- fputc(',', file_);
+void TraceSubscriberStdio::Write(const std::string& output_str) {
+ if (IsValid()) {
+ size_t written = fwrite(output_str.c_str(), 1, output_str.size(), file_);
+ if (written != output_str.size()) {
+ LOG(ERROR) << "Error " << ferror(file_) << " when writing to trace file";
+ CloseFile();
+ }
}
}
« no previous file with comments | « content/browser/trace_subscriber_stdio.h ('k') | content/browser/trace_subscriber_stdio_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698