blob: 908db3ea1ab44c2824e93f56b573869b2274df52 [file] [log] [blame]
license.botbf09a502008-08-24 00:55:551// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
5#include "chrome/browser/metrics_log.h"
6
7#include "base/file_util.h"
8#include "base/file_version_info.h"
9#include "base/md5.h"
10#include "base/scoped_ptr.h"
11#include "base/string_util.h"
[email protected]fadf97f2008-09-18 12:18:1412#include "base/sys_info.h"
initial.commit09911bf2008-07-26 23:55:2913#include "chrome/browser/autocomplete/autocomplete.h"
14#include "chrome/browser/browser_process.h"
initial.commit09911bf2008-07-26 23:55:2915#include "chrome/common/logging_chrome.h"
16#include "chrome/common/pref_names.h"
17#include "chrome/common/pref_service.h"
[email protected]46072d42008-07-28 14:49:3518#include "googleurl/src/gurl.h"
initial.commit09911bf2008-07-26 23:55:2919#include "net/base/base64.h"
20
21#define OPEN_ELEMENT_FOR_SCOPE(name) ScopedElement scoped_element(this, name)
22
[email protected]e1acf6f2008-10-27 20:43:3323using base::Time;
24using base::TimeDelta;
25
initial.commit09911bf2008-07-26 23:55:2926// libxml take xmlChar*, which is unsigned char*
27inline const unsigned char* UnsignedChar(const char* input) {
28 return reinterpret_cast<const unsigned char*>(input);
29}
30
31// static
32void MetricsLog::RegisterPrefs(PrefService* local_state) {
33 local_state->RegisterListPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:2934}
35
36MetricsLog::MetricsLog(const std::string& client_id, int session_id)
37 : start_time_(Time::Now()),
38 num_events_(0),
39 locked_(false),
40 buffer_(NULL),
41 writer_(NULL),
42 client_id_(client_id),
43 session_id_(IntToString(session_id)) {
44
45 buffer_ = xmlBufferCreate();
46 DCHECK(buffer_);
47
48 writer_ = xmlNewTextWriterMemory(buffer_, 0);
49 DCHECK(writer_);
50
51 int result = xmlTextWriterSetIndent(writer_, 2);
52 DCHECK_EQ(0, result);
53
54 StartElement("log");
55 WriteAttribute("clientid", client_id_);
56
57 DCHECK_GE(result, 0);
58}
59
60MetricsLog::~MetricsLog() {
61 if (writer_)
62 xmlFreeTextWriter(writer_);
63
64 if (buffer_)
65 xmlBufferFree(buffer_);
66}
67
68void MetricsLog::CloseLog() {
69 DCHECK(!locked_);
70 locked_ = true;
71
72 int result = xmlTextWriterEndDocument(writer_);
73 DCHECK(result >= 0);
74
75 result = xmlTextWriterFlush(writer_);
76 DCHECK(result >= 0);
77}
78
79int MetricsLog::GetEncodedLogSize() {
80 DCHECK(locked_);
81 return buffer_->use;
82}
83
84bool MetricsLog::GetEncodedLog(char* buffer, int buffer_size) {
85 DCHECK(locked_);
86 if (buffer_size < GetEncodedLogSize())
87 return false;
88
89 memcpy(buffer, buffer_->content, GetEncodedLogSize());
90 return true;
91}
92
93int MetricsLog::GetElapsedSeconds() {
94 return static_cast<int>((Time::Now() - start_time_).InSeconds());
95}
96
97std::string MetricsLog::CreateHash(const std::string& value) {
98 MD5Context ctx;
99 MD5Init(&ctx);
100 MD5Update(&ctx, value.data(), value.length());
101
102 MD5Digest digest;
103 MD5Final(&digest, &ctx);
104
105 unsigned char reverse[8]; // UMA only uses first 8 chars of hash.
106 DCHECK(arraysize(digest.a) >= arraysize(reverse));
107 for (int i = 0; i < arraysize(reverse); ++i)
108 reverse[i] = digest.a[arraysize(reverse) - i - 1];
109 LOG(INFO) << "Metrics: Hash numeric [" << value << "]=["
110 << *reinterpret_cast<const uint64*>(&reverse[0]) << "]";
111 return std::string(reinterpret_cast<char*>(digest.a), arraysize(digest.a));
112}
113
114std::string MetricsLog::CreateBase64Hash(const std::string& string) {
115 std::string encoded_digest;
[email protected]a9bb6f692008-07-30 16:40:10116 if (net::Base64Encode(CreateHash(string), &encoded_digest)) {
initial.commit09911bf2008-07-26 23:55:29117 DLOG(INFO) << "Metrics: Hash [" << encoded_digest << "]=[" << string << "]";
118 return encoded_digest;
initial.commit09911bf2008-07-26 23:55:29119 }
[email protected]a9bb6f692008-07-30 16:40:10120 return std::string();
initial.commit09911bf2008-07-26 23:55:29121}
122
123void MetricsLog::RecordUserAction(const wchar_t* key) {
124 DCHECK(!locked_);
125
126 std::string command_hash = CreateBase64Hash(WideToUTF8(key));
127 if (command_hash.empty()) {
128 NOTREACHED() << "Unable generate encoded hash of command: " << key;
129 return;
130 }
131
132 StartElement("uielement");
133 WriteAttribute("action", "command");
134 WriteAttribute("targetidhash", command_hash);
135
136 // TODO(jhughes): Properly track windows.
137 WriteIntAttribute("window", 0);
138 WriteCommonEventAttributes();
139 EndElement();
140
141 ++num_events_;
142}
143
144void MetricsLog::RecordLoadEvent(int window_id,
145 const GURL& url,
146 PageTransition::Type origin,
147 int session_index,
148 TimeDelta load_time) {
149 DCHECK(!locked_);
150
151 StartElement("document");
152 WriteAttribute("action", "load");
153 WriteIntAttribute("docid", session_index);
154 WriteIntAttribute("window", window_id);
155 WriteAttribute("loadtime", Int64ToString(load_time.InMilliseconds()));
156
157 std::string origin_string;
158
159 switch (PageTransition::StripQualifier(origin)) {
160 // TODO(jhughes): Some of these mappings aren't right... we need to add
161 // some values to the server's enum.
162 case PageTransition::LINK:
163 case PageTransition::MANUAL_SUBFRAME:
164 origin_string = "link";
165 break;
166
167 case PageTransition::TYPED:
168 origin_string = "typed";
169 break;
170
171 case PageTransition::AUTO_BOOKMARK:
172 origin_string = "bookmark";
173 break;
174
175 case PageTransition::AUTO_SUBFRAME:
176 case PageTransition::RELOAD:
177 origin_string = "refresh";
178 break;
179
180 case PageTransition::GENERATED:
181 origin_string = "global-history";
182 break;
183
184 case PageTransition::START_PAGE:
185 origin_string = "start-page";
186 break;
187
188 case PageTransition::FORM_SUBMIT:
189 origin_string = "form-submit";
190 break;
191
192 default:
193 NOTREACHED() << "Received an unknown page transition type: " <<
194 PageTransition::StripQualifier(origin);
195 }
196 if (!origin_string.empty())
197 WriteAttribute("origin", origin_string);
198
199 WriteCommonEventAttributes();
200 EndElement();
201
202 ++num_events_;
203}
204
205// static
206const char* MetricsLog::WindowEventTypeToString(WindowEventType type) {
207 switch (type) {
208 case WINDOW_CREATE:
209 return "create";
210
211 case WINDOW_OPEN:
212 return "open";
213
214 case WINDOW_CLOSE:
215 return "close";
216
217 case WINDOW_DESTROY:
218 return "destroy";
219
220 default:
221 NOTREACHED();
222 return "unknown";
223 }
224}
225
226void MetricsLog::RecordWindowEvent(WindowEventType type,
227 int window_id,
228 int parent_id) {
229 DCHECK(!locked_);
230
231 StartElement("window");
232 WriteAttribute("action", WindowEventTypeToString(type));
233 WriteAttribute("windowid", IntToString(window_id));
234 if (parent_id >= 0)
235 WriteAttribute("parent", IntToString(parent_id));
236 WriteCommonEventAttributes();
237 EndElement();
238
239 ++num_events_;
240}
241
242std::string MetricsLog::GetCurrentTimeString() {
243 return Uint64ToString(Time::Now().ToTimeT());
244}
245
246// These are the attributes that are common to every event.
247void MetricsLog::WriteCommonEventAttributes() {
248 WriteAttribute("session", session_id_);
249 WriteAttribute("time", GetCurrentTimeString());
250}
251
252void MetricsLog::WriteAttribute(const std::string& name,
253 const std::string& value) {
254 DCHECK(!locked_);
255 DCHECK(!name.empty());
256
257 int result = xmlTextWriterWriteAttribute(writer_,
258 UnsignedChar(name.c_str()),
259 UnsignedChar(value.c_str()));
260 DCHECK_GE(result, 0);
261}
262
263void MetricsLog::WriteIntAttribute(const std::string& name, int value) {
264 WriteAttribute(name, IntToString(value));
265}
266
267void MetricsLog::WriteInt64Attribute(const std::string& name, int64 value) {
268 WriteAttribute(name, Int64ToString(value));
269}
270
271void MetricsLog::StartElement(const char* name) {
272 DCHECK(!locked_);
273 DCHECK(name);
274
275 int result = xmlTextWriterStartElement(writer_, UnsignedChar(name));
276 DCHECK_GE(result, 0);
277}
278
279void MetricsLog::EndElement() {
280 DCHECK(!locked_);
281
282 int result = xmlTextWriterEndElement(writer_);
283 DCHECK_GE(result, 0);
284}
285
286std::string MetricsLog::GetVersionString() const {
287 scoped_ptr<FileVersionInfo> version_info(
288 FileVersionInfo::CreateFileVersionInfoForCurrentModule());
289 if (version_info.get()) {
290 std::string version = WideToUTF8(version_info->product_version());
291 if (!version_info->is_official_build())
292 version.append("-devel");
293 return version;
294 } else {
295 NOTREACHED() << "Unable to retrieve version string.";
296 }
297
298 return std::string();
299}
300
301std::string MetricsLog::GetInstallDate() const {
302 PrefService* pref = g_browser_process->local_state();
303 if (pref) {
304 return WideToUTF8(pref->GetString(prefs::kMetricsClientIDTimestamp));
305 } else {
306 NOTREACHED();
307 return "0";
308 }
309}
310
311void MetricsLog::WriteStabilityElement() {
312 DCHECK(!locked_);
313
314 PrefService* pref = g_browser_process->local_state();
315 DCHECK(pref);
316
317 // Get stability attributes out of Local State, zeroing out stored values.
318 // NOTE: This could lead to some data loss if this report isn't successfully
319 // sent, but that's true for all the metrics.
320
321 StartElement("stability");
322
323 WriteIntAttribute("launchcount",
324 pref->GetInteger(prefs::kStabilityLaunchCount));
325 pref->SetInteger(prefs::kStabilityLaunchCount, 0);
326 WriteIntAttribute("crashcount",
327 pref->GetInteger(prefs::kStabilityCrashCount));
328 pref->SetInteger(prefs::kStabilityCrashCount, 0);
[email protected]8e674e42008-07-30 16:05:48329 WriteIntAttribute("incompleteshutdowncount",
330 pref->GetInteger(
331 prefs::kStabilityIncompleteSessionEndCount));
332 pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0);
initial.commit09911bf2008-07-26 23:55:29333 WriteIntAttribute("pageloadcount",
334 pref->GetInteger(prefs::kStabilityPageLoadCount));
335 pref->SetInteger(prefs::kStabilityPageLoadCount, 0);
336 WriteIntAttribute("renderercrashcount",
337 pref->GetInteger(prefs::kStabilityRendererCrashCount));
338 pref->SetInteger(prefs::kStabilityRendererCrashCount, 0);
339 WriteIntAttribute("rendererhangcount",
340 pref->GetInteger(prefs::kStabilityRendererHangCount));
341 pref->SetInteger(prefs::kStabilityRendererHangCount, 0);
[email protected]e73c01972008-08-13 00:18:24342 WriteIntAttribute("breakpadregistrationok",
343 pref->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess));
344 pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0);
345 WriteIntAttribute("breakpadregistrationfail",
346 pref->GetInteger(prefs::kStabilityBreakpadRegistrationFail));
347 pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0);
348 WriteIntAttribute("debuggerpresent",
349 pref->GetInteger(prefs::kStabilityDebuggerPresent));
350 pref->SetInteger(prefs::kStabilityDebuggerPresent, 0);
351 WriteIntAttribute("debuggernotpresent",
352 pref->GetInteger(prefs::kStabilityDebuggerNotPresent));
353 pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0);
initial.commit09911bf2008-07-26 23:55:29354
355 // Uptime is stored as a string, since there's no int64 in Value/JSON.
356 WriteAttribute("uptimesec",
357 WideToUTF8(pref->GetString(prefs::kStabilityUptimeSec)));
358 pref->SetString(prefs::kStabilityUptimeSec, L"0");
359
360 // Now log plugin stability info
361 const ListValue* plugin_stats_list = pref->GetList(
362 prefs::kStabilityPluginStats);
363 if (plugin_stats_list) {
364 StartElement("plugins");
365 for (ListValue::const_iterator iter = plugin_stats_list->begin();
366 iter != plugin_stats_list->end(); ++iter) {
367 if (!(*iter)->IsType(Value::TYPE_DICTIONARY)) {
368 NOTREACHED();
369 continue;
370 }
371 DictionaryValue* plugin_dict = static_cast<DictionaryValue*>(*iter);
372
373 std::wstring plugin_path;
374 plugin_dict->GetString(prefs::kStabilityPluginPath, &plugin_path);
375 plugin_path = file_util::GetFilenameFromPath(plugin_path);
376 if (plugin_path.empty()) {
377 NOTREACHED();
378 continue;
379 }
380
381 StartElement("pluginstability");
382 WriteAttribute("filename", CreateBase64Hash(WideToUTF8(plugin_path)));
383
384 int launches = 0;
385 plugin_dict->GetInteger(prefs::kStabilityPluginLaunches, &launches);
386 WriteIntAttribute("launchcount", launches);
387
388 int instances = 0;
389 plugin_dict->GetInteger(prefs::kStabilityPluginInstances, &instances);
390 WriteIntAttribute("instancecount", instances);
391
392 int crashes = 0;
393 plugin_dict->GetInteger(prefs::kStabilityPluginCrashes, &crashes);
394 WriteIntAttribute("crashcount", crashes);
395 EndElement();
396 }
397
398 pref->ClearPref(prefs::kStabilityPluginStats);
399 EndElement();
400 }
401
402 EndElement();
403}
404
405void MetricsLog::WritePluginList(
406 const std::vector<WebPluginInfo>& plugin_list) {
407 DCHECK(!locked_);
408
409 StartElement("plugins");
410
411 for (std::vector<WebPluginInfo>::const_iterator iter = plugin_list.begin();
412 iter != plugin_list.end(); ++iter) {
413 StartElement("plugin");
414
415 // Plugin name and filename are hashed for the privacy of those
416 // testing unreleased new extensions.
417 WriteAttribute("name", CreateBase64Hash(WideToUTF8((*iter).name)));
418 std::wstring filename = file_util::GetFilenameFromPath((*iter).file);
419 WriteAttribute("filename", CreateBase64Hash(WideToUTF8(filename)));
420
421 WriteAttribute("version", WideToUTF8((*iter).version));
422
423 EndElement();
424 }
425
426 EndElement();
427}
428
429void MetricsLog::RecordEnvironment(
430 const std::vector<WebPluginInfo>& plugin_list,
431 const DictionaryValue* profile_metrics) {
432 DCHECK(!locked_);
433
434 PrefService* pref = g_browser_process->local_state();
435
436 StartElement("profile");
437 WriteCommonEventAttributes();
438
439 StartElement("install");
440 WriteAttribute("installdate", GetInstallDate());
441 WriteIntAttribute("buildid", 0); // means that we're using appversion instead
442 WriteAttribute("appversion", GetVersionString());
443 EndElement();
444
445 WritePluginList(plugin_list);
446
447 WriteStabilityElement();
448
449 {
450 OPEN_ELEMENT_FOR_SCOPE("cpu");
[email protected]05f9b682008-09-29 22:18:01451 WriteAttribute("arch", base::SysInfo::CPUArchitecture());
initial.commit09911bf2008-07-26 23:55:29452 }
453
454 {
455 OPEN_ELEMENT_FOR_SCOPE("security");
456 WriteIntAttribute("rendereronsboxdesktop",
457 pref->GetInteger(prefs::kSecurityRendererOnSboxDesktop));
458 pref->SetInteger(prefs::kSecurityRendererOnSboxDesktop, 0);
459
460 WriteIntAttribute("rendererondefaultdesktop",
461 pref->GetInteger(prefs::kSecurityRendererOnDefaultDesktop));
462 pref->SetInteger(prefs::kSecurityRendererOnDefaultDesktop, 0);
463 }
464
465 {
466 OPEN_ELEMENT_FOR_SCOPE("memory");
[email protected]ed6fc352008-09-18 12:44:40467 WriteIntAttribute("mb", base::SysInfo::AmountOfPhysicalMemoryMB());
initial.commit09911bf2008-07-26 23:55:29468 }
469
470 {
471 OPEN_ELEMENT_FOR_SCOPE("os");
472 WriteAttribute("name",
[email protected]05f9b682008-09-29 22:18:01473 base::SysInfo::OperatingSystemName());
initial.commit09911bf2008-07-26 23:55:29474 WriteAttribute("version",
[email protected]05f9b682008-09-29 22:18:01475 base::SysInfo::OperatingSystemVersion());
initial.commit09911bf2008-07-26 23:55:29476 }
477
478 {
479 OPEN_ELEMENT_FOR_SCOPE("display");
480 int width = 0;
481 int height = 0;
[email protected]05f9b682008-09-29 22:18:01482 base::SysInfo::GetPrimaryDisplayDimensions(&width, &height);
initial.commit09911bf2008-07-26 23:55:29483 WriteIntAttribute("xsize", width);
484 WriteIntAttribute("ysize", height);
[email protected]05f9b682008-09-29 22:18:01485 WriteIntAttribute("screens", base::SysInfo::DisplayCount());
initial.commit09911bf2008-07-26 23:55:29486 }
487
488 {
489 OPEN_ELEMENT_FOR_SCOPE("bookmarks");
490 int num_bookmarks_on_bookmark_bar =
491 pref->GetInteger(prefs::kNumBookmarksOnBookmarkBar);
492 int num_folders_on_bookmark_bar =
493 pref->GetInteger(prefs::kNumFoldersOnBookmarkBar);
494 int num_bookmarks_in_other_bookmarks_folder =
495 pref->GetInteger(prefs::kNumBookmarksInOtherBookmarkFolder);
496 int num_folders_in_other_bookmarks_folder =
497 pref->GetInteger(prefs::kNumFoldersInOtherBookmarkFolder);
498 {
499 OPEN_ELEMENT_FOR_SCOPE("bookmarklocation");
500 WriteAttribute("name", "full-tree");
501 WriteIntAttribute("foldercount",
502 num_folders_on_bookmark_bar + num_folders_in_other_bookmarks_folder);
503 WriteIntAttribute("itemcount",
504 num_bookmarks_on_bookmark_bar +
505 num_bookmarks_in_other_bookmarks_folder);
506 }
507 {
508 OPEN_ELEMENT_FOR_SCOPE("bookmarklocation");
509 WriteAttribute("name", "toolbar");
510 WriteIntAttribute("foldercount", num_folders_on_bookmark_bar);
511 WriteIntAttribute("itemcount", num_bookmarks_on_bookmark_bar);
512 }
513 }
514
515 {
516 OPEN_ELEMENT_FOR_SCOPE("keywords");
517 WriteIntAttribute("count", pref->GetInteger(prefs::kNumKeywords));
518 }
519
520 if (profile_metrics)
521 WriteAllProfilesMetrics(*profile_metrics);
522
523 EndElement(); // profile
524}
525
526void MetricsLog::WriteAllProfilesMetrics(
527 const DictionaryValue& all_profiles_metrics) {
528 const std::wstring profile_prefix(prefs::kProfilePrefix);
529 for (DictionaryValue::key_iterator i = all_profiles_metrics.begin_keys();
530 i != all_profiles_metrics.end_keys(); ++i) {
531 const std::wstring& key_name = *i;
532 if (key_name.compare(0, profile_prefix.size(), profile_prefix) == 0) {
533 DictionaryValue* profile;
534 if (all_profiles_metrics.GetDictionary(key_name, &profile))
535 WriteProfileMetrics(key_name.substr(profile_prefix.size()), *profile);
536 }
537 }
538}
539
540void MetricsLog::WriteProfileMetrics(const std::wstring& profileidhash,
541 const DictionaryValue& profile_metrics) {
542 OPEN_ELEMENT_FOR_SCOPE("userprofile");
543 WriteAttribute("profileidhash", WideToUTF8(profileidhash));
544 for (DictionaryValue::key_iterator i = profile_metrics.begin_keys();
545 i != profile_metrics.end_keys(); ++i) {
546 Value* value;
547 if (profile_metrics.Get(*i, &value)) {
548 DCHECK(*i != L"id");
549 switch (value->GetType()) {
550 case Value::TYPE_STRING: {
551 std::wstring string_value;
552 if (value->GetAsString(&string_value)) {
553 OPEN_ELEMENT_FOR_SCOPE("profileparam");
554 WriteAttribute("name", WideToUTF8(*i));
555 WriteAttribute("value", WideToUTF8(string_value));
556 }
557 break;
558 }
559
560 case Value::TYPE_BOOLEAN: {
561 bool bool_value;
562 if (value->GetAsBoolean(&bool_value)) {
563 OPEN_ELEMENT_FOR_SCOPE("profileparam");
564 WriteAttribute("name", WideToUTF8(*i));
565 WriteIntAttribute("value", bool_value ? 1 : 0);
566 }
567 break;
568 }
569
570 case Value::TYPE_INTEGER: {
571 int int_value;
572 if (value->GetAsInteger(&int_value)) {
573 OPEN_ELEMENT_FOR_SCOPE("profileparam");
574 WriteAttribute("name", WideToUTF8(*i));
575 WriteIntAttribute("value", int_value);
576 }
577 break;
578 }
579
580 default:
581 NOTREACHED();
582 break;
583 }
584 }
585 }
586}
587
588void MetricsLog::RecordOmniboxOpenedURL(const AutocompleteLog& log) {
589 DCHECK(!locked_);
590
591 StartElement("uielement");
592 WriteAttribute("action", "autocomplete");
593 WriteAttribute("targetidhash", "");
594 // TODO(kochi): Properly track windows.
595 WriteIntAttribute("window", 0);
596 WriteCommonEventAttributes();
597
598 StartElement("autocomplete");
599
600 WriteIntAttribute("typedlength", static_cast<int>(log.text.length()));
601 WriteIntAttribute("completedlength",
602 static_cast<int>(log.inline_autocompleted_length));
603 WriteIntAttribute("selectedindex", static_cast<int>(log.selected_index));
604
605 for (AutocompleteResult::const_iterator i(log.result.begin());
606 i != log.result.end(); ++i) {
607 StartElement("autocompleteitem");
608 if (i->provider)
609 WriteAttribute("provider", i->provider->name());
610 WriteIntAttribute("relevance", i->relevance);
611 WriteIntAttribute("isstarred", i->starred ? 1 : 0);
612 EndElement(); // autocompleteitem
613 }
614 EndElement(); // autocomplete
615 EndElement(); // uielement
616
617 ++num_events_;
618}
619
620// TODO(JAR): A The following should really be part of the histogram class.
621// Internal state is being needlessly exposed, and it would be hard to reuse
622// this code. If we moved this into the Histogram class, then we could use
623// the same infrastructure for logging StatsCounters, RatesCounters, etc.
624void MetricsLog::RecordHistogramDelta(const Histogram& histogram,
625 const Histogram::SampleSet& snapshot) {
626 DCHECK(!locked_);
627 DCHECK(0 != snapshot.TotalCount());
628 snapshot.CheckSize(histogram);
629
630 // We will ignore the MAX_INT/infinite value in the last element of range[].
631
632 OPEN_ELEMENT_FOR_SCOPE("histogram");
633
634 WriteAttribute("name", CreateBase64Hash(histogram.histogram_name()));
635
636 WriteInt64Attribute("sum", snapshot.sum());
637 WriteInt64Attribute("sumsquares", snapshot.square_sum());
638
639 for (size_t i = 0; i < histogram.bucket_count(); i++) {
640 if (snapshot.counts(i)) {
641 OPEN_ELEMENT_FOR_SCOPE("histogrambucket");
642 WriteIntAttribute("min", histogram.ranges(i));
643 WriteIntAttribute("max", histogram.ranges(i + 1));
644 WriteIntAttribute("count", snapshot.counts(i));
645 }
646 }
647}