Bug 535564 part 2: only open the PID for short periods while we're writing to it, r=jgriffin
authorBenjamin Smedberg <benjamin@smedbergs.us>
Wed, 27 Jan 2010 11:17:22 -0500
changeset 37547 869030a735da35b28a9597cfe81bab3373e3e145
parent 37546 19b64e822f0472145266b4f9d68b2749bc56f0e6
child 37548 d46a66a8c9176f4beb17def7ae95fffafc916b1b
push id11371
push userbsmedberg@mozilla.com
push dateWed, 27 Jan 2010 16:56:23 +0000
treeherdermozilla-central@ae8c17be0129 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjgriffin
bugs535564
milestone1.9.3a1pre
Bug 535564 part 2: only open the PID for short periods while we're writing to it, r=jgriffin
ipc/chromium/src/base/debug_util.cc
ipc/chromium/src/base/debug_util.h
--- a/ipc/chromium/src/base/debug_util.cc
+++ b/ipc/chromium/src/base/debug_util.cc
@@ -37,40 +37,40 @@ const void *const *StackTrace::Addresses
   if (trace_.size())
     return &trace_[0];
   return NULL;
 }
 
 namespace mozilla {
 
 EnvironmentLog::EnvironmentLog(const char* varname)
-  : fd_(NULL)
 {
-  const char *e = getenv(varname);
-  if (e && *e) {
-    if (!strcmp(e, "-")) {
-      fd_ = fdopen(dup(STDOUT_FILENO), "a");
-    }
-    else {
-      fd_ = fopen(e, "a");
-    }
-  }
+  if (e && *e)
+    fname_ = e;
 }
 
 EnvironmentLog::~EnvironmentLog()
 {
-  if (fd_)
-    fclose(fd_);
 }
 
 void
 EnvironmentLog::print(const char* format, ...)
 {
+  if (!fname_.size())
+    return;
+
+  FILE* f;
+  if (fname_.compare("-") == 0)
+    f = fdopen(dup(STDOUT_FILENO), "a");
+  else
+    f = fopen(fname_.c_str(), "a");
+
+  if (!f)
+    return;
+
   va_list a;
   va_start(a, format);
-  if (fd_) {
-    vfprintf(fd_, format, a);
-    fflush(fd_);
-  }
+  vfprintf(f, format, a);
   va_end(a);
+  fclose(f);
 }
 
 } // namespace mozilla
--- a/ipc/chromium/src/base/debug_util.h
+++ b/ipc/chromium/src/base/debug_util.h
@@ -73,16 +73,16 @@ class EnvironmentLog
 {
 public:
   EnvironmentLog(const char* varname);
   ~EnvironmentLog();
 
   void print(const char* format, ...);
 
 private:
-  FILE* fd_;
+  std::string fname_;
 
   DISALLOW_EVIL_CONSTRUCTORS(EnvironmentLog);
 };
 
 } // namespace mozilla
 
 #endif  // BASE_DEBUG_UTIL_H_