summaryrefslogtreecommitdiffstats
path: root/content/browser/trace_subscriber_stdio.cc
diff options
context:
space:
mode:
authorjbates@chromium.org <jbates@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-13 17:06:24 +0000
committerjbates@chromium.org <jbates@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-13 17:06:24 +0000
commitdb09c194c77cb6e1a504986e3d24888fdda9b006 (patch)
tree1f1d164c2c7e6c8dd3ae6b63f4496d3687933376 /content/browser/trace_subscriber_stdio.cc
parent8c985d12487448768a56a28cae9ea918a0043513 (diff)
downloadchromium_src-db09c194c77cb6e1a504986e3d24888fdda9b006.zip
chromium_src-db09c194c77cb6e1a504986e3d24888fdda9b006.tar.gz
chromium_src-db09c194c77cb6e1a504986e3d24888fdda9b006.tar.bz2
Make TraceSubscriberStdio reusable (currently can only run trace once)
Review URL: http://codereview.chromium.org/7863022 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@100929 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/trace_subscriber_stdio.cc')
-rw-r--r--content/browser/trace_subscriber_stdio.cc32
1 files changed, 23 insertions, 9 deletions
diff --git a/content/browser/trace_subscriber_stdio.cc b/content/browser/trace_subscriber_stdio.cc
index b1b5daa..bf6a8fc 100644
--- a/content/browser/trace_subscriber_stdio.cc
+++ b/content/browser/trace_subscriber_stdio.cc
@@ -6,19 +6,38 @@
#include "base/logging.h"
-TraceSubscriberStdio::TraceSubscriberStdio(const FilePath& path) {
+TraceSubscriberStdio::TraceSubscriberStdio() : file_(0) {
+}
+
+TraceSubscriberStdio::TraceSubscriberStdio(const FilePath& path) : file_(0) {
+ OpenFile(path);
+}
+
+TraceSubscriberStdio::~TraceSubscriberStdio() {
+ CloseFile();
+}
+
+bool TraceSubscriberStdio::OpenFile(const FilePath& path) {
LOG(INFO) << "Logging performance trace to file: " << path.value();
+ CloseFile();
file_ = file_util::OpenFile(path, "w+");
if (IsValid()) {
// FIXME: the file format expects it to start with "[".
fputc('[', file_);
+ return true;
} else {
LOG(ERROR) << "Failed to open performance trace file: " << path.value();
+ return false;
}
}
-TraceSubscriberStdio::~TraceSubscriberStdio() {
- OnEndTracingComplete();
+void TraceSubscriberStdio::CloseFile() {
+ if (file_) {
+ // FIXME: the file format expects it to end with "]".
+ fputc(']', file_);
+ fclose(file_);
+ file_ = 0;
+ }
}
bool TraceSubscriberStdio::IsValid() {
@@ -26,12 +45,7 @@ bool TraceSubscriberStdio::IsValid() {
}
void TraceSubscriberStdio::OnEndTracingComplete() {
- if (file_) {
- // FIXME: the file format expects it to end with "]".
- fputc(']', file_);
- fclose(file_);
- file_ = 0;
- }
+ CloseFile();
}
void TraceSubscriberStdio::OnTraceDataCollected(