Index: chrome/common/metrics_helpers.cc |
=================================================================== |
--- chrome/common/metrics_helpers.cc (revision 49384) |
+++ chrome/common/metrics_helpers.cc (working copy) |
@@ -15,6 +15,7 @@ |
#include "base/basictypes.h" |
#include "base/file_util.h" |
#include "base/md5.h" |
+#include "base/perftimer.h" |
#include "base/scoped_ptr.h" |
#include "base/string_util.h" |
#include "base/sys_info.h" |
@@ -47,6 +48,7 @@ |
client_id_(client_id), |
session_id_(IntToString(session_id)), |
locked_(false), |
+ doc_(NULL), |
buffer_(NULL), |
writer_(NULL), |
num_events_(0) { |
@@ -54,7 +56,11 @@ |
buffer_ = xmlBufferCreate(); |
DCHECK(buffer_); |
- writer_ = xmlNewTextWriterMemory(buffer_, 0); |
+ #if defined(OS_CHROMEOS) |
+ writer_ = xmlNewTextWriterDoc(&doc_, /* compression */ 0); |
+ #else |
+ writer_ = xmlNewTextWriterMemory(buffer_, /* compression */ 0); |
+ #endif // OS_CHROMEOS |
DCHECK(writer_); |
int result = xmlTextWriterSetIndent(writer_, 2); |
@@ -69,11 +75,15 @@ |
} |
MetricsLogBase::~MetricsLogBase() { |
+ FreeDocWriter(); |
+ |
if (writer_) |
xmlFreeTextWriter(writer_); |
- if (buffer_) |
+ if (buffer_) { |
xmlBufferFree(buffer_); |
+ buffer_ = NULL; |
+ } |
} |
void MetricsLogBase::CloseLog() { |
@@ -85,6 +95,27 @@ |
result = xmlTextWriterFlush(writer_); |
DCHECK_GE(result, 0); |
+ |
+#if defined(OS_CHROMEOS) |
+ xmlNodePtr root = xmlDocGetRootElement(doc_); |
+ if (!hardware_class_.empty()) { |
+ // The hardware class is determined after the first ongoing log is |
+ // constructed, so this adds the root element's "hardwareclass" |
+ // attribute when the log is closed instead. |
+ xmlNewProp(root, UnsignedChar("hardwareclass"), |
+ UnsignedChar(hardware_class_.c_str())); |
+ } |
+ |
+ // Flattens the XML tree into a character buffer. |
+ PerfTimer dump_timer; |
+ result = xmlNodeDump(buffer_, doc_, root, /* level */ 0, /* format */ 1); |
+ DCHECK_GE(result, 0); |
+ UMA_HISTOGRAM_TIMES("UMA.XMLNodeDumpTime", dump_timer.Elapsed()); |
+ |
+ PerfTimer free_timer; |
+ FreeDocWriter(); |
+ UMA_HISTOGRAM_TIMES("UMA.XMLWriterDestructionTime", free_timer.Elapsed()); |
+#endif // OS_CHROMEOS |
} |
int MetricsLogBase::GetEncodedLogSize() { |
@@ -286,6 +317,18 @@ |
} |
} |
+void MetricsLogBase::FreeDocWriter() { |
+ if (writer_) { |
+ xmlFreeTextWriter(writer_); |
+ writer_ = NULL; |
+ } |
+ |
+ if (doc_) { |
+ xmlFreeDoc(doc_); |
+ doc_ = NULL; |
+ } |
+} |
+ |
void MetricsLogBase::StartElement(const char* name) { |
DCHECK(!locked_); |
DCHECK(name); |