diff options
author | laforge@chromium.org <laforge@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-20 02:19:56 +0000 |
---|---|---|
committer | laforge@chromium.org <laforge@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-20 02:19:56 +0000 |
commit | 4d43b0aec563d1b3e0d22db320f9f4ef6a459af0 (patch) | |
tree | 1e47c252f41ec23deb4003d40a83bb9e0522370c | |
parent | 84f460a53c787956e9ef47e3a34966e190beb532 (diff) | |
download | chromium_src-4d43b0aec563d1b3e0d22db320f9f4ef6a459af0.zip chromium_src-4d43b0aec563d1b3e0d22db320f9f4ef6a459af0.tar.gz chromium_src-4d43b0aec563d1b3e0d22db320f9f4ef6a459af0.tar.bz2 |
Merge 35629 - Add buildtime to UMA upload data
r=tigerf
Review URL: http://codereview.chromium.org/519017
TBR=jar@chromium.org
Review URL: http://codereview.chromium.org/546084
git-svn-id: svn://svn.chromium.org/chrome/branches/249/src@36600 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/metrics/metrics_log.cc | 12 | ||||
-rw-r--r-- | chrome/browser/metrics/metrics_log_unittest.cc | 56 |
2 files changed, 54 insertions, 14 deletions
diff --git a/chrome/browser/metrics/metrics_log.cc b/chrome/browser/metrics/metrics_log.cc index 18441d4..14b5649 100644 --- a/chrome/browser/metrics/metrics_log.cc +++ b/chrome/browser/metrics/metrics_log.cc @@ -11,6 +11,7 @@ #include "base/scoped_ptr.h" #include "base/string_util.h" #include "base/sys_info.h" +#include "base/third_party/nspr/prtime.h" #include "chrome/browser/autocomplete/autocomplete.h" #include "chrome/browser/browser_process.h" #include "chrome/common/logging_chrome.h" @@ -34,6 +35,8 @@ inline const unsigned char* UnsignedChar(const char* input) { return reinterpret_cast<const unsigned char*>(input); } +static int64 GetBuildTime(); + // static void MetricsLog::RegisterPrefs(PrefService* local_state) { local_state->RegisterListPref(prefs::kStabilityPluginStats); @@ -59,6 +62,7 @@ MetricsLog::MetricsLog(const std::string& client_id, int session_id) StartElement("log"); WriteAttribute("clientid", client_id_); + WriteInt64Attribute("buildtime", GetBuildTime()); DCHECK_GE(result, 0); } @@ -703,3 +707,11 @@ void MetricsLog::RecordHistogramDelta(const Histogram& histogram, } } } + +static int64 GetBuildTime() { + Time parsed_time; + const char* kDateTime = __DATE__ " " __TIME__; + bool result = Time::FromString(ASCIIToWide(kDateTime).c_str(), &parsed_time); + DCHECK(result); + return static_cast<int64>(parsed_time.ToTimeT()); +} diff --git a/chrome/browser/metrics/metrics_log_unittest.cc b/chrome/browser/metrics/metrics_log_unittest.cc index d3324e3..85d7aaf 100644 --- a/chrome/browser/metrics/metrics_log_unittest.cc +++ b/chrome/browser/metrics/metrics_log_unittest.cc @@ -17,8 +17,30 @@ namespace { }; }; + +// Since buildtime is highly variable, this function will scan an output log and +// replace it with a consistent number. +static void NormalizeBuildtime(std::string* xml_encoded) { + std::string prefix = "buildtime=\""; + const char postfix = '\"'; + size_t offset = xml_encoded->find(prefix); + ASSERT_GT(offset, 0u); + offset += prefix.size(); + size_t postfix_position = xml_encoded->find(postfix, offset); + ASSERT_GT(postfix_position, offset); + for (size_t i = offset; i < postfix_position; ++i) { + char digit = xml_encoded->at(i); + ASSERT_GE(digit, '0'); + ASSERT_LE(digit, '9'); + } + + // Insert a single fake buildtime. + xml_encoded->replace(offset, postfix_position - offset, "123246"); +} + TEST(MetricsLogTest, EmptyRecord) { - std::string expected_output = "<log clientid=\"bogus client ID\"/>"; + std::string expected_output = + "<log clientid=\"bogus client ID\" buildtime=\"123456789\"/>"; MetricsLog log("bogus client ID", 0); log.CloseLog(); @@ -28,6 +50,8 @@ TEST(MetricsLogTest, EmptyRecord) { std::string encoded; ASSERT_TRUE(log.GetEncodedLog(WriteInto(&encoded, size), size)); + NormalizeBuildtime(&encoded); + NormalizeBuildtime(&expected_output); ASSERT_EQ(expected_output, encoded); } @@ -50,14 +74,14 @@ class NoTimeMetricsLog : public MetricsLog { TEST(MetricsLogTest, WindowEvent) { std::string expected_output = - "<log clientid=\"bogus client ID\">\n" - " <window action=\"create\" windowid=\"0\" session=\"0\" time=\"\"/>\n" - " <window action=\"open\" windowid=\"1\" parent=\"0\" " - "session=\"0\" time=\"\"/>\n" - " <window action=\"close\" windowid=\"1\" parent=\"0\" " - "session=\"0\" time=\"\"/>\n" - " <window action=\"destroy\" windowid=\"0\" session=\"0\" time=\"\"/>\n" - "</log>"; + "<log clientid=\"bogus client ID\" buildtime=\"123456789\">\n" + " <window action=\"create\" windowid=\"0\" session=\"0\" time=\"\"/>\n" + " <window action=\"open\" windowid=\"1\" parent=\"0\" " + "session=\"0\" time=\"\"/>\n" + " <window action=\"close\" windowid=\"1\" parent=\"0\" " + "session=\"0\" time=\"\"/>\n" + " <window action=\"destroy\" windowid=\"0\" session=\"0\" time=\"\"/>\n" + "</log>"; NoTimeMetricsLog log("bogus client ID", 0); log.RecordWindowEvent(MetricsLog::WINDOW_CREATE, 0, -1); @@ -73,17 +97,19 @@ TEST(MetricsLogTest, WindowEvent) { std::string encoded; ASSERT_TRUE(log.GetEncodedLog(WriteInto(&encoded, size), size)); + NormalizeBuildtime(&encoded); + NormalizeBuildtime(&expected_output); ASSERT_EQ(expected_output, encoded); } TEST(MetricsLogTest, LoadEvent) { std::string expected_output = - "<log clientid=\"bogus client ID\">\n" - " <document action=\"load\" docid=\"1\" window=\"3\" loadtime=\"7219\" " - "origin=\"link\" " - "session=\"0\" time=\"\"/>\n" - "</log>"; + "<log clientid=\"bogus client ID\" buildtime=\"123456789\">\n" + " <document action=\"load\" docid=\"1\" window=\"3\" loadtime=\"7219\" " + "origin=\"link\" " + "session=\"0\" time=\"\"/>\n" + "</log>"; NoTimeMetricsLog log("bogus client ID", 0); log.RecordLoadEvent(3, GURL("http://google.com"), PageTransition::LINK, @@ -98,6 +124,8 @@ TEST(MetricsLogTest, LoadEvent) { std::string encoded; ASSERT_TRUE(log.GetEncodedLog(WriteInto(&encoded, size), size)); + NormalizeBuildtime(&encoded); + NormalizeBuildtime(&expected_output); ASSERT_EQ(expected_output, encoded); } |