summaryrefslogtreecommitdiffstats
path: root/content/browser/trace_subscriber_stdio.cc
diff options
context:
space:
mode:
authormpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-22 00:15:14 +0000
committermpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-22 00:15:14 +0000
commita4ecc3d225e129390b8a80ddbee445e31fde2a94 (patch)
tree27271c2842597520c794b4e36943793aafd676dc /content/browser/trace_subscriber_stdio.cc
parent35d849dc495e21eaceb75badc6541c1d30bffb79 (diff)
downloadchromium_src-a4ecc3d225e129390b8a80ddbee445e31fde2a94.zip
chromium_src-a4ecc3d225e129390b8a80ddbee445e31fde2a94.tar.gz
chromium_src-a4ecc3d225e129390b8a80ddbee445e31fde2a94.tar.bz2
Revert: Internalize JSON chunk merging to trace_event.h API.
BUG=100291 TEST=base_unittests, content_unittests Review URL: http://codereview.chromium.org/8355024 Review URL: http://codereview.chromium.org/8369021 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@106812 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/trace_subscriber_stdio.cc')
-rw-r--r--content/browser/trace_subscriber_stdio.cc36
1 files changed, 21 insertions, 15 deletions
diff --git a/content/browser/trace_subscriber_stdio.cc b/content/browser/trace_subscriber_stdio.cc
index 901aea0..bf6a8fc 100644
--- a/content/browser/trace_subscriber_stdio.cc
+++ b/content/browser/trace_subscriber_stdio.cc
@@ -4,7 +4,6 @@
#include "content/browser/trace_subscriber_stdio.h"
-#include "base/bind.h"
#include "base/logging.h"
TraceSubscriberStdio::TraceSubscriberStdio() : file_(0) {
@@ -23,9 +22,8 @@ bool TraceSubscriberStdio::OpenFile(const FilePath& path) {
CloseFile();
file_ = file_util::OpenFile(path, "w+");
if (IsValid()) {
- trace_buffer_.SetOutputCallback(base::Bind(&TraceSubscriberStdio::Write,
- base::Unretained(this)));
- trace_buffer_.Start();
+ // FIXME: the file format expects it to start with "[".
+ fputc('[', file_);
return true;
} else {
LOG(ERROR) << "Failed to open performance trace file: " << path.value();
@@ -35,6 +33,8 @@ 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,21 +45,27 @@ bool TraceSubscriberStdio::IsValid() {
}
void TraceSubscriberStdio::OnEndTracingComplete() {
- trace_buffer_.Finish();
CloseFile();
}
void TraceSubscriberStdio::OnTraceDataCollected(
- const std::string& trace_fragment) {
- trace_buffer_.AddFragment(trace_fragment);
-}
+ const std::string& json_events) {
+ if (!IsValid()) {
+ return;
+ }
-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();
- }
+ // 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;
+
+ 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_);
}
}