[email protected] | 4dad9ad8 | 2009-11-25 20:47:52 | [diff] [blame] | 1 | // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | cd1adc2 | 2009-01-16 01:29:22 | [diff] [blame] | 5 | #include "chrome/browser/metrics/metrics_log.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 6 | |
[email protected] | 978df34 | 2009-11-24 06:21:53 | [diff] [blame] | 7 | #include "base/base64.h" |
[email protected] | 9165f74 | 2010-03-10 22:55:01 | [diff] [blame] | 8 | #include "base/time.h" |
[email protected] | d1be67b | 2008-11-19 20:28:38 | [diff] [blame] | 9 | #include "base/basictypes.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 10 | #include "base/file_util.h" |
| 11 | #include "base/file_version_info.h" |
| 12 | #include "base/md5.h" |
| 13 | #include "base/scoped_ptr.h" |
| 14 | #include "base/string_util.h" |
[email protected] | fadf97f | 2008-09-18 12:18:14 | [diff] [blame] | 15 | #include "base/sys_info.h" |
[email protected] | 1cb92b8 | 2010-03-08 23:12:15 | [diff] [blame] | 16 | #include "base/utf_string_conversions.h" |
[email protected] | 37f39e4 | 2010-01-06 17:35:17 | [diff] [blame] | 17 | #include "base/third_party/nspr/prtime.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 18 | #include "chrome/browser/autocomplete/autocomplete.h" |
| 19 | #include "chrome/browser/browser_process.h" |
[email protected] | 052313b | 2010-02-19 09:43:08 | [diff] [blame] | 20 | #include "chrome/browser/pref_service.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 21 | #include "chrome/common/logging_chrome.h" |
| 22 | #include "chrome/common/pref_names.h" |
[email protected] | 46072d4 | 2008-07-28 14:49:35 | [diff] [blame] | 23 | #include "googleurl/src/gurl.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 24 | |
| 25 | #define OPEN_ELEMENT_FOR_SCOPE(name) ScopedElement scoped_element(this, name) |
| 26 | |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 27 | using base::Time; |
| 28 | using base::TimeDelta; |
| 29 | |
[email protected] | d1be67b | 2008-11-19 20:28:38 | [diff] [blame] | 30 | // http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx |
| 31 | #if defined(OS_WIN) |
| 32 | extern "C" IMAGE_DOS_HEADER __ImageBase; |
| 33 | #endif |
| 34 | |
[email protected] | 5ed7d457 | 2009-12-23 17:42:41 | [diff] [blame] | 35 | // static |
| 36 | std::string MetricsLog::version_extension_; |
| 37 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 38 | // libxml take xmlChar*, which is unsigned char* |
| 39 | inline const unsigned char* UnsignedChar(const char* input) { |
| 40 | return reinterpret_cast<const unsigned char*>(input); |
| 41 | } |
| 42 | |
| 43 | // static |
| 44 | void MetricsLog::RegisterPrefs(PrefService* local_state) { |
| 45 | local_state->RegisterListPref(prefs::kStabilityPluginStats); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | MetricsLog::MetricsLog(const std::string& client_id, int session_id) |
| 49 | : start_time_(Time::Now()), |
[email protected] | 29d02e5 | 2008-12-16 16:58:27 | [diff] [blame] | 50 | client_id_(client_id), |
| 51 | session_id_(IntToString(session_id)), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 52 | locked_(false), |
| 53 | buffer_(NULL), |
| 54 | writer_(NULL), |
[email protected] | 29d02e5 | 2008-12-16 16:58:27 | [diff] [blame] | 55 | num_events_(0) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 56 | |
| 57 | buffer_ = xmlBufferCreate(); |
| 58 | DCHECK(buffer_); |
| 59 | |
| 60 | writer_ = xmlNewTextWriterMemory(buffer_, 0); |
| 61 | DCHECK(writer_); |
| 62 | |
| 63 | int result = xmlTextWriterSetIndent(writer_, 2); |
| 64 | DCHECK_EQ(0, result); |
| 65 | |
| 66 | StartElement("log"); |
| 67 | WriteAttribute("clientid", client_id_); |
[email protected] | 37f39e4 | 2010-01-06 17:35:17 | [diff] [blame] | 68 | WriteInt64Attribute("buildtime", GetBuildTime()); |
[email protected] | efc607b | 2010-02-19 21:31:57 | [diff] [blame] | 69 | WriteAttribute("appversion", GetVersionString()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 70 | |
| 71 | DCHECK_GE(result, 0); |
| 72 | } |
| 73 | |
| 74 | MetricsLog::~MetricsLog() { |
| 75 | if (writer_) |
| 76 | xmlFreeTextWriter(writer_); |
| 77 | |
| 78 | if (buffer_) |
| 79 | xmlBufferFree(buffer_); |
| 80 | } |
| 81 | |
| 82 | void MetricsLog::CloseLog() { |
| 83 | DCHECK(!locked_); |
| 84 | locked_ = true; |
| 85 | |
| 86 | int result = xmlTextWriterEndDocument(writer_); |
[email protected] | 5ed7d457 | 2009-12-23 17:42:41 | [diff] [blame] | 87 | DCHECK_GE(result, 0); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 88 | |
| 89 | result = xmlTextWriterFlush(writer_); |
[email protected] | 5ed7d457 | 2009-12-23 17:42:41 | [diff] [blame] | 90 | DCHECK_GE(result, 0); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | int MetricsLog::GetEncodedLogSize() { |
| 94 | DCHECK(locked_); |
| 95 | return buffer_->use; |
| 96 | } |
| 97 | |
| 98 | bool MetricsLog::GetEncodedLog(char* buffer, int buffer_size) { |
| 99 | DCHECK(locked_); |
| 100 | if (buffer_size < GetEncodedLogSize()) |
| 101 | return false; |
| 102 | |
| 103 | memcpy(buffer, buffer_->content, GetEncodedLogSize()); |
| 104 | return true; |
| 105 | } |
| 106 | |
| 107 | int MetricsLog::GetElapsedSeconds() { |
| 108 | return static_cast<int>((Time::Now() - start_time_).InSeconds()); |
| 109 | } |
| 110 | |
| 111 | std::string MetricsLog::CreateHash(const std::string& value) { |
| 112 | MD5Context ctx; |
| 113 | MD5Init(&ctx); |
| 114 | MD5Update(&ctx, value.data(), value.length()); |
| 115 | |
| 116 | MD5Digest digest; |
| 117 | MD5Final(&digest, &ctx); |
| 118 | |
[email protected] | be6bf5e | 2009-06-16 13:14:08 | [diff] [blame] | 119 | uint64 reverse_uint64; |
| 120 | // UMA only uses first 8 chars of hash. We use the above uint64 instead |
| 121 | // of a unsigned char[8] so that we don't run into strict aliasing issues |
| 122 | // in the LOG statement below when trying to interpret reverse as a uint64. |
| 123 | unsigned char* reverse = reinterpret_cast<unsigned char *>(&reverse_uint64); |
| 124 | DCHECK(arraysize(digest.a) >= sizeof(reverse_uint64)); |
| 125 | for (size_t i = 0; i < sizeof(reverse_uint64); ++i) |
| 126 | reverse[i] = digest.a[sizeof(reverse_uint64) - i - 1]; |
[email protected] | f88ba61a | 2009-06-12 16:52:10 | [diff] [blame] | 127 | // The following log is VERY helpful when folks add some named histogram into |
| 128 | // the code, but forgot to update the descriptive list of histograms. When |
| 129 | // that happens, all we get to see (server side) is a hash of the histogram |
| 130 | // name. We can then use this logging to find out what histogram name was |
| 131 | // being hashed to a given MD5 value by just running the version of Chromium |
| 132 | // in question with --enable-logging. |
| 133 | LOG(INFO) << "Metrics: Hash numeric [" << value << "]=[" |
[email protected] | be6bf5e | 2009-06-16 13:14:08 | [diff] [blame] | 134 | << reverse_uint64 << "]"; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 135 | return std::string(reinterpret_cast<char*>(digest.a), arraysize(digest.a)); |
| 136 | } |
| 137 | |
| 138 | std::string MetricsLog::CreateBase64Hash(const std::string& string) { |
| 139 | std::string encoded_digest; |
[email protected] | 978df34 | 2009-11-24 06:21:53 | [diff] [blame] | 140 | if (base::Base64Encode(CreateHash(string), &encoded_digest)) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 141 | DLOG(INFO) << "Metrics: Hash [" << encoded_digest << "]=[" << string << "]"; |
| 142 | return encoded_digest; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 143 | } |
[email protected] | a9bb6f69 | 2008-07-30 16:40:10 | [diff] [blame] | 144 | return std::string(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 145 | } |
| 146 | |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 147 | void MetricsLog::RecordUserAction(const char* key) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 148 | DCHECK(!locked_); |
| 149 | |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 150 | std::string command_hash = CreateBase64Hash(key); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 151 | if (command_hash.empty()) { |
| 152 | NOTREACHED() << "Unable generate encoded hash of command: " << key; |
| 153 | return; |
| 154 | } |
| 155 | |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 156 | OPEN_ELEMENT_FOR_SCOPE("uielement"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 157 | WriteAttribute("action", "command"); |
| 158 | WriteAttribute("targetidhash", command_hash); |
| 159 | |
| 160 | // TODO(jhughes): Properly track windows. |
| 161 | WriteIntAttribute("window", 0); |
| 162 | WriteCommonEventAttributes(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 163 | |
| 164 | ++num_events_; |
| 165 | } |
| 166 | |
| 167 | void MetricsLog::RecordLoadEvent(int window_id, |
| 168 | const GURL& url, |
| 169 | PageTransition::Type origin, |
| 170 | int session_index, |
| 171 | TimeDelta load_time) { |
| 172 | DCHECK(!locked_); |
| 173 | |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 174 | OPEN_ELEMENT_FOR_SCOPE("document"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 175 | WriteAttribute("action", "load"); |
| 176 | WriteIntAttribute("docid", session_index); |
| 177 | WriteIntAttribute("window", window_id); |
| 178 | WriteAttribute("loadtime", Int64ToString(load_time.InMilliseconds())); |
| 179 | |
| 180 | std::string origin_string; |
| 181 | |
| 182 | switch (PageTransition::StripQualifier(origin)) { |
| 183 | // TODO(jhughes): Some of these mappings aren't right... we need to add |
| 184 | // some values to the server's enum. |
| 185 | case PageTransition::LINK: |
| 186 | case PageTransition::MANUAL_SUBFRAME: |
| 187 | origin_string = "link"; |
| 188 | break; |
| 189 | |
| 190 | case PageTransition::TYPED: |
| 191 | origin_string = "typed"; |
| 192 | break; |
| 193 | |
| 194 | case PageTransition::AUTO_BOOKMARK: |
| 195 | origin_string = "bookmark"; |
| 196 | break; |
| 197 | |
| 198 | case PageTransition::AUTO_SUBFRAME: |
| 199 | case PageTransition::RELOAD: |
| 200 | origin_string = "refresh"; |
| 201 | break; |
| 202 | |
| 203 | case PageTransition::GENERATED: |
[email protected] | 0bfc29a | 2009-04-27 16:15:44 | [diff] [blame] | 204 | case PageTransition::KEYWORD: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 205 | origin_string = "global-history"; |
| 206 | break; |
| 207 | |
| 208 | case PageTransition::START_PAGE: |
| 209 | origin_string = "start-page"; |
| 210 | break; |
| 211 | |
| 212 | case PageTransition::FORM_SUBMIT: |
| 213 | origin_string = "form-submit"; |
| 214 | break; |
| 215 | |
| 216 | default: |
| 217 | NOTREACHED() << "Received an unknown page transition type: " << |
| 218 | PageTransition::StripQualifier(origin); |
| 219 | } |
| 220 | if (!origin_string.empty()) |
| 221 | WriteAttribute("origin", origin_string); |
| 222 | |
| 223 | WriteCommonEventAttributes(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 224 | |
| 225 | ++num_events_; |
| 226 | } |
| 227 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 228 | void MetricsLog::RecordWindowEvent(WindowEventType type, |
| 229 | int window_id, |
| 230 | int parent_id) { |
| 231 | DCHECK(!locked_); |
| 232 | |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 233 | OPEN_ELEMENT_FOR_SCOPE("window"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 234 | WriteAttribute("action", WindowEventTypeToString(type)); |
| 235 | WriteAttribute("windowid", IntToString(window_id)); |
| 236 | if (parent_id >= 0) |
| 237 | WriteAttribute("parent", IntToString(parent_id)); |
| 238 | WriteCommonEventAttributes(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 239 | |
| 240 | ++num_events_; |
| 241 | } |
| 242 | |
| 243 | std::string MetricsLog::GetCurrentTimeString() { |
| 244 | return Uint64ToString(Time::Now().ToTimeT()); |
| 245 | } |
| 246 | |
| 247 | // These are the attributes that are common to every event. |
| 248 | void MetricsLog::WriteCommonEventAttributes() { |
| 249 | WriteAttribute("session", session_id_); |
| 250 | WriteAttribute("time", GetCurrentTimeString()); |
| 251 | } |
| 252 | |
| 253 | void MetricsLog::WriteAttribute(const std::string& name, |
| 254 | const std::string& value) { |
| 255 | DCHECK(!locked_); |
| 256 | DCHECK(!name.empty()); |
| 257 | |
| 258 | int result = xmlTextWriterWriteAttribute(writer_, |
| 259 | UnsignedChar(name.c_str()), |
| 260 | UnsignedChar(value.c_str())); |
| 261 | DCHECK_GE(result, 0); |
| 262 | } |
| 263 | |
| 264 | void MetricsLog::WriteIntAttribute(const std::string& name, int value) { |
| 265 | WriteAttribute(name, IntToString(value)); |
| 266 | } |
| 267 | |
| 268 | void MetricsLog::WriteInt64Attribute(const std::string& name, int64 value) { |
| 269 | WriteAttribute(name, Int64ToString(value)); |
| 270 | } |
| 271 | |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 272 | // static |
| 273 | const char* MetricsLog::WindowEventTypeToString(WindowEventType type) { |
| 274 | switch (type) { |
| 275 | case WINDOW_CREATE: return "create"; |
| 276 | case WINDOW_OPEN: return "open"; |
| 277 | case WINDOW_CLOSE: return "close"; |
| 278 | case WINDOW_DESTROY: return "destroy"; |
| 279 | |
| 280 | default: |
| 281 | NOTREACHED(); |
| 282 | return "unknown"; // Can't return NULL as this is used in a required |
| 283 | // attribute. |
| 284 | } |
| 285 | } |
| 286 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 287 | void MetricsLog::StartElement(const char* name) { |
| 288 | DCHECK(!locked_); |
| 289 | DCHECK(name); |
| 290 | |
| 291 | int result = xmlTextWriterStartElement(writer_, UnsignedChar(name)); |
| 292 | DCHECK_GE(result, 0); |
| 293 | } |
| 294 | |
| 295 | void MetricsLog::EndElement() { |
| 296 | DCHECK(!locked_); |
| 297 | |
| 298 | int result = xmlTextWriterEndElement(writer_); |
| 299 | DCHECK_GE(result, 0); |
| 300 | } |
| 301 | |
[email protected] | 541f7792 | 2009-02-23 21:14:38 | [diff] [blame] | 302 | // static |
| 303 | std::string MetricsLog::GetVersionString() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 304 | scoped_ptr<FileVersionInfo> version_info( |
| 305 | FileVersionInfo::CreateFileVersionInfoForCurrentModule()); |
| 306 | if (version_info.get()) { |
| 307 | std::string version = WideToUTF8(version_info->product_version()); |
[email protected] | 5ed7d457 | 2009-12-23 17:42:41 | [diff] [blame] | 308 | if (!version_extension_.empty()) |
| 309 | version += version_extension_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 310 | if (!version_info->is_official_build()) |
| 311 | version.append("-devel"); |
| 312 | return version; |
| 313 | } else { |
| 314 | NOTREACHED() << "Unable to retrieve version string."; |
| 315 | } |
| 316 | |
| 317 | return std::string(); |
| 318 | } |
| 319 | |
[email protected] | 225c5084 | 2010-01-19 21:19:13 | [diff] [blame] | 320 | // static |
| 321 | int64 MetricsLog::GetBuildTime() { |
| 322 | static int64 integral_build_time = 0; |
| 323 | if (!integral_build_time) { |
| 324 | Time time; |
| 325 | const char* kDateTime = __DATE__ " " __TIME__ " GMT"; |
| 326 | bool result = Time::FromString(ASCIIToWide(kDateTime).c_str(), &time); |
| 327 | DCHECK(result); |
| 328 | integral_build_time = static_cast<int64>(time.ToTimeT()); |
| 329 | } |
| 330 | return integral_build_time; |
| 331 | } |
| 332 | |
[email protected] | 9165f74 | 2010-03-10 22:55:01 | [diff] [blame] | 333 | // static |
| 334 | int64 MetricsLog::GetIncrementalUptime(PrefService* pref) { |
| 335 | base::TimeTicks now = base::TimeTicks::Now(); |
| 336 | static base::TimeTicks last_updated_time(now); |
| 337 | int64 incremental_time = (now - last_updated_time).InSeconds(); |
| 338 | last_updated_time = now; |
| 339 | |
| 340 | if (incremental_time > 0) { |
| 341 | int64 metrics_uptime = pref->GetInt64(prefs::kUninstallMetricsUptimeSec); |
| 342 | metrics_uptime += incremental_time; |
| 343 | pref->SetInt64(prefs::kUninstallMetricsUptimeSec, metrics_uptime); |
| 344 | } |
| 345 | |
| 346 | return incremental_time; |
| 347 | } |
| 348 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 349 | std::string MetricsLog::GetInstallDate() const { |
| 350 | PrefService* pref = g_browser_process->local_state(); |
| 351 | if (pref) { |
| 352 | return WideToUTF8(pref->GetString(prefs::kMetricsClientIDTimestamp)); |
| 353 | } else { |
| 354 | NOTREACHED(); |
| 355 | return "0"; |
| 356 | } |
| 357 | } |
| 358 | |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 359 | void MetricsLog::RecordIncrementalStabilityElements() { |
| 360 | DCHECK(!locked_); |
| 361 | |
| 362 | PrefService* pref = g_browser_process->local_state(); |
| 363 | DCHECK(pref); |
| 364 | |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 365 | OPEN_ELEMENT_FOR_SCOPE("profile"); |
| 366 | WriteCommonEventAttributes(); |
| 367 | |
| 368 | WriteInstallElement(); // Supply appversion. |
| 369 | |
| 370 | { |
| 371 | OPEN_ELEMENT_FOR_SCOPE("stability"); // Minimal set of stability elements. |
| 372 | WriteRequiredStabilityAttributes(pref); |
| 373 | WriteRealtimeStabilityAttributes(pref); |
| 374 | |
| 375 | WritePluginStabilityElements(pref); |
| 376 | } |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 377 | } |
| 378 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 379 | void MetricsLog::WriteStabilityElement() { |
| 380 | DCHECK(!locked_); |
| 381 | |
| 382 | PrefService* pref = g_browser_process->local_state(); |
| 383 | DCHECK(pref); |
| 384 | |
| 385 | // Get stability attributes out of Local State, zeroing out stored values. |
| 386 | // NOTE: This could lead to some data loss if this report isn't successfully |
| 387 | // sent, but that's true for all the metrics. |
| 388 | |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 389 | OPEN_ELEMENT_FOR_SCOPE("stability"); |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 390 | WriteRequiredStabilityAttributes(pref); |
| 391 | WriteRealtimeStabilityAttributes(pref); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 392 | |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 393 | // TODO(jar): The following are all optional, so we *could* optimize them for |
| 394 | // values of zero (and not include them). |
[email protected] | 8e674e4 | 2008-07-30 16:05:48 | [diff] [blame] | 395 | WriteIntAttribute("incompleteshutdowncount", |
| 396 | pref->GetInteger( |
| 397 | prefs::kStabilityIncompleteSessionEndCount)); |
| 398 | pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 399 | |
| 400 | |
[email protected] | e73c0197 | 2008-08-13 00:18:24 | [diff] [blame] | 401 | WriteIntAttribute("breakpadregistrationok", |
| 402 | pref->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess)); |
| 403 | pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0); |
| 404 | WriteIntAttribute("breakpadregistrationfail", |
| 405 | pref->GetInteger(prefs::kStabilityBreakpadRegistrationFail)); |
| 406 | pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0); |
| 407 | WriteIntAttribute("debuggerpresent", |
| 408 | pref->GetInteger(prefs::kStabilityDebuggerPresent)); |
| 409 | pref->SetInteger(prefs::kStabilityDebuggerPresent, 0); |
| 410 | WriteIntAttribute("debuggernotpresent", |
| 411 | pref->GetInteger(prefs::kStabilityDebuggerNotPresent)); |
| 412 | pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 413 | |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 414 | WritePluginStabilityElements(pref); |
| 415 | } |
| 416 | |
| 417 | void MetricsLog::WritePluginStabilityElements(PrefService* pref) { |
| 418 | // Now log plugin stability info. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 419 | const ListValue* plugin_stats_list = pref->GetList( |
| 420 | prefs::kStabilityPluginStats); |
| 421 | if (plugin_stats_list) { |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 422 | OPEN_ELEMENT_FOR_SCOPE("plugins"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 423 | for (ListValue::const_iterator iter = plugin_stats_list->begin(); |
| 424 | iter != plugin_stats_list->end(); ++iter) { |
| 425 | if (!(*iter)->IsType(Value::TYPE_DICTIONARY)) { |
| 426 | NOTREACHED(); |
| 427 | continue; |
| 428 | } |
| 429 | DictionaryValue* plugin_dict = static_cast<DictionaryValue*>(*iter); |
| 430 | |
[email protected] | 8e50b60 | 2009-03-03 22:59:43 | [diff] [blame] | 431 | std::wstring plugin_name; |
| 432 | plugin_dict->GetString(prefs::kStabilityPluginName, &plugin_name); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 433 | |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 434 | OPEN_ELEMENT_FOR_SCOPE("pluginstability"); |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 435 | // Use "filename" instead of "name", otherwise we need to update the |
| 436 | // UMA servers. |
[email protected] | 8e50b60 | 2009-03-03 22:59:43 | [diff] [blame] | 437 | WriteAttribute("filename", CreateBase64Hash(WideToUTF8(plugin_name))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 438 | |
| 439 | int launches = 0; |
[email protected] | 8e50b60 | 2009-03-03 22:59:43 | [diff] [blame] | 440 | plugin_dict->GetInteger(prefs::kStabilityPluginLaunches, &launches); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 441 | WriteIntAttribute("launchcount", launches); |
| 442 | |
| 443 | int instances = 0; |
[email protected] | 8e50b60 | 2009-03-03 22:59:43 | [diff] [blame] | 444 | plugin_dict->GetInteger(prefs::kStabilityPluginInstances, &instances); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 445 | WriteIntAttribute("instancecount", instances); |
| 446 | |
| 447 | int crashes = 0; |
[email protected] | 8e50b60 | 2009-03-03 22:59:43 | [diff] [blame] | 448 | plugin_dict->GetInteger(prefs::kStabilityPluginCrashes, &crashes); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 449 | WriteIntAttribute("crashcount", crashes); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | pref->ClearPref(prefs::kStabilityPluginStats); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 453 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 454 | } |
| 455 | |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 456 | void MetricsLog::WriteRequiredStabilityAttributes(PrefService* pref) { |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 457 | // The server refuses data that doesn't have certain values. crashcount and |
| 458 | // launchcount are currently "required" in the "stability" group. |
| 459 | WriteIntAttribute("launchcount", |
| 460 | pref->GetInteger(prefs::kStabilityLaunchCount)); |
| 461 | pref->SetInteger(prefs::kStabilityLaunchCount, 0); |
| 462 | WriteIntAttribute("crashcount", |
| 463 | pref->GetInteger(prefs::kStabilityCrashCount)); |
| 464 | pref->SetInteger(prefs::kStabilityCrashCount, 0); |
| 465 | } |
| 466 | |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 467 | void MetricsLog::WriteRealtimeStabilityAttributes(PrefService* pref) { |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 468 | // Update the stats which are critical for real-time stability monitoring. |
| 469 | // Since these are "optional," only list ones that are non-zero, as the counts |
| 470 | // are aggergated (summed) server side. |
| 471 | |
| 472 | int count = pref->GetInteger(prefs::kStabilityPageLoadCount); |
| 473 | if (count) { |
| 474 | WriteIntAttribute("pageloadcount", count); |
| 475 | pref->SetInteger(prefs::kStabilityPageLoadCount, 0); |
| 476 | } |
| 477 | |
| 478 | count = pref->GetInteger(prefs::kStabilityRendererCrashCount); |
| 479 | if (count) { |
| 480 | WriteIntAttribute("renderercrashcount", count); |
| 481 | pref->SetInteger(prefs::kStabilityRendererCrashCount, 0); |
| 482 | } |
| 483 | |
[email protected] | 1f08562 | 2009-12-04 05:33:45 | [diff] [blame] | 484 | count = pref->GetInteger(prefs::kStabilityExtensionRendererCrashCount); |
| 485 | if (count) { |
| 486 | WriteIntAttribute("extensionrenderercrashcount", count); |
| 487 | pref->SetInteger(prefs::kStabilityExtensionRendererCrashCount, 0); |
| 488 | } |
| 489 | |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 490 | count = pref->GetInteger(prefs::kStabilityRendererHangCount); |
| 491 | if (count) { |
| 492 | WriteIntAttribute("rendererhangcount", count); |
| 493 | pref->SetInteger(prefs::kStabilityRendererHangCount, 0); |
| 494 | } |
[email protected] | 1f08562 | 2009-12-04 05:33:45 | [diff] [blame] | 495 | |
| 496 | count = pref->GetInteger(prefs::kStabilityChildProcessCrashCount); |
| 497 | if (count) { |
| 498 | WriteIntAttribute("childprocesscrashcount", count); |
| 499 | pref->SetInteger(prefs::kStabilityChildProcessCrashCount, 0); |
| 500 | } |
[email protected] | 9165f74 | 2010-03-10 22:55:01 | [diff] [blame] | 501 | |
| 502 | int64 recent_duration = GetIncrementalUptime(pref); |
| 503 | if (recent_duration) |
| 504 | WriteInt64Attribute("uptimesec", recent_duration); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 505 | } |
| 506 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 507 | void MetricsLog::WritePluginList( |
| 508 | const std::vector<WebPluginInfo>& plugin_list) { |
| 509 | DCHECK(!locked_); |
| 510 | |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 511 | OPEN_ELEMENT_FOR_SCOPE("plugins"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 512 | |
| 513 | for (std::vector<WebPluginInfo>::const_iterator iter = plugin_list.begin(); |
| 514 | iter != plugin_list.end(); ++iter) { |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 515 | OPEN_ELEMENT_FOR_SCOPE("plugin"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 516 | |
| 517 | // Plugin name and filename are hashed for the privacy of those |
| 518 | // testing unreleased new extensions. |
[email protected] | b734450 | 2009-01-12 19:43:44 | [diff] [blame] | 519 | WriteAttribute("name", CreateBase64Hash(WideToUTF8(iter->name))); |
[email protected] | 046344c | 2009-01-13 00:54:21 | [diff] [blame] | 520 | WriteAttribute("filename", |
| 521 | CreateBase64Hash(WideToUTF8(iter->path.BaseName().ToWStringHack()))); |
[email protected] | b734450 | 2009-01-12 19:43:44 | [diff] [blame] | 522 | WriteAttribute("version", WideToUTF8(iter->version)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 523 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 524 | } |
| 525 | |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 526 | void MetricsLog::WriteInstallElement() { |
| 527 | OPEN_ELEMENT_FOR_SCOPE("install"); |
| 528 | WriteAttribute("installdate", GetInstallDate()); |
| 529 | WriteIntAttribute("buildid", 0); // We're using appversion instead. |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 530 | } |
| 531 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 532 | void MetricsLog::RecordEnvironment( |
| 533 | const std::vector<WebPluginInfo>& plugin_list, |
| 534 | const DictionaryValue* profile_metrics) { |
| 535 | DCHECK(!locked_); |
| 536 | |
| 537 | PrefService* pref = g_browser_process->local_state(); |
| 538 | |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 539 | OPEN_ELEMENT_FOR_SCOPE("profile"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 540 | WriteCommonEventAttributes(); |
| 541 | |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 542 | WriteInstallElement(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 543 | |
| 544 | WritePluginList(plugin_list); |
| 545 | |
| 546 | WriteStabilityElement(); |
| 547 | |
| 548 | { |
| 549 | OPEN_ELEMENT_FOR_SCOPE("cpu"); |
[email protected] | 05f9b68 | 2008-09-29 22:18:01 | [diff] [blame] | 550 | WriteAttribute("arch", base::SysInfo::CPUArchitecture()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 554 | OPEN_ELEMENT_FOR_SCOPE("memory"); |
[email protected] | ed6fc35 | 2008-09-18 12:44:40 | [diff] [blame] | 555 | WriteIntAttribute("mb", base::SysInfo::AmountOfPhysicalMemoryMB()); |
[email protected] | d1be67b | 2008-11-19 20:28:38 | [diff] [blame] | 556 | #if defined(OS_WIN) |
| 557 | WriteIntAttribute("dllbase", reinterpret_cast<int>(&__ImageBase)); |
| 558 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | { |
| 562 | OPEN_ELEMENT_FOR_SCOPE("os"); |
| 563 | WriteAttribute("name", |
[email protected] | 05f9b68 | 2008-09-29 22:18:01 | [diff] [blame] | 564 | base::SysInfo::OperatingSystemName()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 565 | WriteAttribute("version", |
[email protected] | 05f9b68 | 2008-09-29 22:18:01 | [diff] [blame] | 566 | base::SysInfo::OperatingSystemVersion()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | { |
| 570 | OPEN_ELEMENT_FOR_SCOPE("display"); |
| 571 | int width = 0; |
| 572 | int height = 0; |
[email protected] | 05f9b68 | 2008-09-29 22:18:01 | [diff] [blame] | 573 | base::SysInfo::GetPrimaryDisplayDimensions(&width, &height); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 574 | WriteIntAttribute("xsize", width); |
| 575 | WriteIntAttribute("ysize", height); |
[email protected] | 05f9b68 | 2008-09-29 22:18:01 | [diff] [blame] | 576 | WriteIntAttribute("screens", base::SysInfo::DisplayCount()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 577 | } |
| 578 | |
| 579 | { |
| 580 | OPEN_ELEMENT_FOR_SCOPE("bookmarks"); |
| 581 | int num_bookmarks_on_bookmark_bar = |
| 582 | pref->GetInteger(prefs::kNumBookmarksOnBookmarkBar); |
| 583 | int num_folders_on_bookmark_bar = |
| 584 | pref->GetInteger(prefs::kNumFoldersOnBookmarkBar); |
| 585 | int num_bookmarks_in_other_bookmarks_folder = |
| 586 | pref->GetInteger(prefs::kNumBookmarksInOtherBookmarkFolder); |
| 587 | int num_folders_in_other_bookmarks_folder = |
| 588 | pref->GetInteger(prefs::kNumFoldersInOtherBookmarkFolder); |
| 589 | { |
| 590 | OPEN_ELEMENT_FOR_SCOPE("bookmarklocation"); |
| 591 | WriteAttribute("name", "full-tree"); |
| 592 | WriteIntAttribute("foldercount", |
| 593 | num_folders_on_bookmark_bar + num_folders_in_other_bookmarks_folder); |
| 594 | WriteIntAttribute("itemcount", |
| 595 | num_bookmarks_on_bookmark_bar + |
| 596 | num_bookmarks_in_other_bookmarks_folder); |
| 597 | } |
| 598 | { |
| 599 | OPEN_ELEMENT_FOR_SCOPE("bookmarklocation"); |
| 600 | WriteAttribute("name", "toolbar"); |
| 601 | WriteIntAttribute("foldercount", num_folders_on_bookmark_bar); |
| 602 | WriteIntAttribute("itemcount", num_bookmarks_on_bookmark_bar); |
| 603 | } |
| 604 | } |
| 605 | |
| 606 | { |
| 607 | OPEN_ELEMENT_FOR_SCOPE("keywords"); |
| 608 | WriteIntAttribute("count", pref->GetInteger(prefs::kNumKeywords)); |
| 609 | } |
| 610 | |
| 611 | if (profile_metrics) |
| 612 | WriteAllProfilesMetrics(*profile_metrics); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | void MetricsLog::WriteAllProfilesMetrics( |
| 616 | const DictionaryValue& all_profiles_metrics) { |
| 617 | const std::wstring profile_prefix(prefs::kProfilePrefix); |
| 618 | for (DictionaryValue::key_iterator i = all_profiles_metrics.begin_keys(); |
| 619 | i != all_profiles_metrics.end_keys(); ++i) { |
[email protected] | 8e50b60 | 2009-03-03 22:59:43 | [diff] [blame] | 620 | const std::wstring& key_name = *i; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 621 | if (key_name.compare(0, profile_prefix.size(), profile_prefix) == 0) { |
| 622 | DictionaryValue* profile; |
[email protected] | 4dad9ad8 | 2009-11-25 20:47:52 | [diff] [blame] | 623 | if (all_profiles_metrics.GetDictionaryWithoutPathExpansion(key_name, |
| 624 | &profile)) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 625 | WriteProfileMetrics(key_name.substr(profile_prefix.size()), *profile); |
| 626 | } |
| 627 | } |
| 628 | } |
| 629 | |
| 630 | void MetricsLog::WriteProfileMetrics(const std::wstring& profileidhash, |
| 631 | const DictionaryValue& profile_metrics) { |
| 632 | OPEN_ELEMENT_FOR_SCOPE("userprofile"); |
| 633 | WriteAttribute("profileidhash", WideToUTF8(profileidhash)); |
| 634 | for (DictionaryValue::key_iterator i = profile_metrics.begin_keys(); |
| 635 | i != profile_metrics.end_keys(); ++i) { |
| 636 | Value* value; |
[email protected] | 4dad9ad8 | 2009-11-25 20:47:52 | [diff] [blame] | 637 | if (profile_metrics.GetWithoutPathExpansion(*i, &value)) { |
[email protected] | 8e50b60 | 2009-03-03 22:59:43 | [diff] [blame] | 638 | DCHECK(*i != L"id"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 639 | switch (value->GetType()) { |
| 640 | case Value::TYPE_STRING: { |
[email protected] | 5e324b7 | 2008-12-18 00:07:59 | [diff] [blame] | 641 | std::string string_value; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 642 | if (value->GetAsString(&string_value)) { |
| 643 | OPEN_ELEMENT_FOR_SCOPE("profileparam"); |
[email protected] | 8e50b60 | 2009-03-03 22:59:43 | [diff] [blame] | 644 | WriteAttribute("name", WideToUTF8(*i)); |
[email protected] | 5e324b7 | 2008-12-18 00:07:59 | [diff] [blame] | 645 | WriteAttribute("value", string_value); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 646 | } |
| 647 | break; |
| 648 | } |
| 649 | |
| 650 | case Value::TYPE_BOOLEAN: { |
| 651 | bool bool_value; |
| 652 | if (value->GetAsBoolean(&bool_value)) { |
| 653 | OPEN_ELEMENT_FOR_SCOPE("profileparam"); |
[email protected] | 8e50b60 | 2009-03-03 22:59:43 | [diff] [blame] | 654 | WriteAttribute("name", WideToUTF8(*i)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 655 | WriteIntAttribute("value", bool_value ? 1 : 0); |
| 656 | } |
| 657 | break; |
| 658 | } |
| 659 | |
| 660 | case Value::TYPE_INTEGER: { |
| 661 | int int_value; |
| 662 | if (value->GetAsInteger(&int_value)) { |
| 663 | OPEN_ELEMENT_FOR_SCOPE("profileparam"); |
[email protected] | 8e50b60 | 2009-03-03 22:59:43 | [diff] [blame] | 664 | WriteAttribute("name", WideToUTF8(*i)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 665 | WriteIntAttribute("value", int_value); |
| 666 | } |
| 667 | break; |
| 668 | } |
| 669 | |
| 670 | default: |
| 671 | NOTREACHED(); |
| 672 | break; |
| 673 | } |
| 674 | } |
| 675 | } |
| 676 | } |
| 677 | |
| 678 | void MetricsLog::RecordOmniboxOpenedURL(const AutocompleteLog& log) { |
| 679 | DCHECK(!locked_); |
| 680 | |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 681 | OPEN_ELEMENT_FOR_SCOPE("uielement"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 682 | WriteAttribute("action", "autocomplete"); |
| 683 | WriteAttribute("targetidhash", ""); |
| 684 | // TODO(kochi): Properly track windows. |
| 685 | WriteIntAttribute("window", 0); |
| 686 | WriteCommonEventAttributes(); |
| 687 | |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 688 | { |
| 689 | OPEN_ELEMENT_FOR_SCOPE("autocomplete"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 690 | |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 691 | WriteIntAttribute("typedlength", static_cast<int>(log.text.length())); |
| 692 | WriteIntAttribute("selectedindex", static_cast<int>(log.selected_index)); |
| 693 | WriteIntAttribute("completedlength", |
| 694 | static_cast<int>(log.inline_autocompleted_length)); |
[email protected] | 381e299 | 2008-12-16 01:41:00 | [diff] [blame] | 695 | const std::string input_type( |
| 696 | AutocompleteInput::TypeToString(log.input_type)); |
| 697 | if (!input_type.empty()) |
| 698 | WriteAttribute("inputtype", input_type); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 699 | |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 700 | for (AutocompleteResult::const_iterator i(log.result.begin()); |
| 701 | i != log.result.end(); ++i) { |
| 702 | OPEN_ELEMENT_FOR_SCOPE("autocompleteitem"); |
| 703 | if (i->provider) |
| 704 | WriteAttribute("provider", i->provider->name()); |
[email protected] | 381e299 | 2008-12-16 01:41:00 | [diff] [blame] | 705 | const std::string result_type(AutocompleteMatch::TypeToString(i->type)); |
| 706 | if (!result_type.empty()) |
| 707 | WriteAttribute("resulttype", result_type); |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 708 | WriteIntAttribute("relevance", i->relevance); |
| 709 | WriteIntAttribute("isstarred", i->starred ? 1 : 0); |
| 710 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 711 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 712 | |
| 713 | ++num_events_; |
| 714 | } |
| 715 | |
| 716 | // TODO(JAR): A The following should really be part of the histogram class. |
| 717 | // Internal state is being needlessly exposed, and it would be hard to reuse |
| 718 | // this code. If we moved this into the Histogram class, then we could use |
| 719 | // the same infrastructure for logging StatsCounters, RatesCounters, etc. |
| 720 | void MetricsLog::RecordHistogramDelta(const Histogram& histogram, |
| 721 | const Histogram::SampleSet& snapshot) { |
| 722 | DCHECK(!locked_); |
[email protected] | 5ed7d457 | 2009-12-23 17:42:41 | [diff] [blame] | 723 | DCHECK_NE(0, snapshot.TotalCount()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 724 | snapshot.CheckSize(histogram); |
| 725 | |
| 726 | // We will ignore the MAX_INT/infinite value in the last element of range[]. |
| 727 | |
| 728 | OPEN_ELEMENT_FOR_SCOPE("histogram"); |
| 729 | |
| 730 | WriteAttribute("name", CreateBase64Hash(histogram.histogram_name())); |
| 731 | |
| 732 | WriteInt64Attribute("sum", snapshot.sum()); |
| 733 | WriteInt64Attribute("sumsquares", snapshot.square_sum()); |
| 734 | |
| 735 | for (size_t i = 0; i < histogram.bucket_count(); i++) { |
| 736 | if (snapshot.counts(i)) { |
| 737 | OPEN_ELEMENT_FOR_SCOPE("histogrambucket"); |
| 738 | WriteIntAttribute("min", histogram.ranges(i)); |
| 739 | WriteIntAttribute("max", histogram.ranges(i + 1)); |
| 740 | WriteIntAttribute("count", snapshot.counts(i)); |
| 741 | } |
| 742 | } |
| 743 | } |