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