blob: a563ed5341b9b08724ee8668291767fffc9a7c36 [file] [log] [blame]
initial.commit09911bf2008-07-26 23:55:291// Copyright 2008, Google Inc.
2// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are
6// met:
7//
8// * Redistributions of source code must retain the above copyright
9// notice, this list of conditions and the following disclaimer.
10// * Redistributions in binary form must reproduce the above
11// copyright notice, this list of conditions and the following disclaimer
12// in the documentation and/or other materials provided with the
13// distribution.
14// * Neither the name of Google Inc. nor the names of its
15// contributors may be used to endorse or promote products derived from
16// this software without specific prior written permission.
17//
18// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30#include "chrome/browser/metrics_log.h"
31
32#include "base/file_util.h"
33#include "base/file_version_info.h"
34#include "base/md5.h"
35#include "base/scoped_ptr.h"
36#include "base/string_util.h"
37#include "chrome/browser/autocomplete/autocomplete.h"
38#include "chrome/browser/browser_process.h"
39#include "chrome/common/env_util.h"
40#include "chrome/common/logging_chrome.h"
41#include "chrome/common/pref_names.h"
42#include "chrome/common/pref_service.h"
[email protected]46072d42008-07-28 14:49:3543#include "googleurl/src/gurl.h"
initial.commit09911bf2008-07-26 23:55:2944#include "net/base/base64.h"
45
46#define OPEN_ELEMENT_FOR_SCOPE(name) ScopedElement scoped_element(this, name)
47
48// libxml take xmlChar*, which is unsigned char*
49inline const unsigned char* UnsignedChar(const char* input) {
50 return reinterpret_cast<const unsigned char*>(input);
51}
52
53// static
54void MetricsLog::RegisterPrefs(PrefService* local_state) {
55 local_state->RegisterListPref(prefs::kStabilityPluginStats);
56 local_state->RegisterBooleanPref(prefs::kMetricsIsRecording, true);
57}
58
59MetricsLog::MetricsLog(const std::string& client_id, int session_id)
60 : start_time_(Time::Now()),
61 num_events_(0),
62 locked_(false),
63 buffer_(NULL),
64 writer_(NULL),
65 client_id_(client_id),
66 session_id_(IntToString(session_id)) {
67
68 buffer_ = xmlBufferCreate();
69 DCHECK(buffer_);
70
71 writer_ = xmlNewTextWriterMemory(buffer_, 0);
72 DCHECK(writer_);
73
74 int result = xmlTextWriterSetIndent(writer_, 2);
75 DCHECK_EQ(0, result);
76
77 StartElement("log");
78 WriteAttribute("clientid", client_id_);
79
80 DCHECK_GE(result, 0);
81}
82
83MetricsLog::~MetricsLog() {
84 if (writer_)
85 xmlFreeTextWriter(writer_);
86
87 if (buffer_)
88 xmlBufferFree(buffer_);
89}
90
91void MetricsLog::CloseLog() {
92 DCHECK(!locked_);
93 locked_ = true;
94
95 int result = xmlTextWriterEndDocument(writer_);
96 DCHECK(result >= 0);
97
98 result = xmlTextWriterFlush(writer_);
99 DCHECK(result >= 0);
100}
101
102int MetricsLog::GetEncodedLogSize() {
103 DCHECK(locked_);
104 return buffer_->use;
105}
106
107bool MetricsLog::GetEncodedLog(char* buffer, int buffer_size) {
108 DCHECK(locked_);
109 if (buffer_size < GetEncodedLogSize())
110 return false;
111
112 memcpy(buffer, buffer_->content, GetEncodedLogSize());
113 return true;
114}
115
116int MetricsLog::GetElapsedSeconds() {
117 return static_cast<int>((Time::Now() - start_time_).InSeconds());
118}
119
120std::string MetricsLog::CreateHash(const std::string& value) {
121 MD5Context ctx;
122 MD5Init(&ctx);
123 MD5Update(&ctx, value.data(), value.length());
124
125 MD5Digest digest;
126 MD5Final(&digest, &ctx);
127
128 unsigned char reverse[8]; // UMA only uses first 8 chars of hash.
129 DCHECK(arraysize(digest.a) >= arraysize(reverse));
130 for (int i = 0; i < arraysize(reverse); ++i)
131 reverse[i] = digest.a[arraysize(reverse) - i - 1];
132 LOG(INFO) << "Metrics: Hash numeric [" << value << "]=["
133 << *reinterpret_cast<const uint64*>(&reverse[0]) << "]";
134 return std::string(reinterpret_cast<char*>(digest.a), arraysize(digest.a));
135}
136
137std::string MetricsLog::CreateBase64Hash(const std::string& string) {
138 std::string encoded_digest;
[email protected]a9bb6f692008-07-30 16:40:10139 if (net::Base64Encode(CreateHash(string), &encoded_digest)) {
initial.commit09911bf2008-07-26 23:55:29140 DLOG(INFO) << "Metrics: Hash [" << encoded_digest << "]=[" << string << "]";
141 return encoded_digest;
initial.commit09911bf2008-07-26 23:55:29142 }
[email protected]a9bb6f692008-07-30 16:40:10143 return std::string();
initial.commit09911bf2008-07-26 23:55:29144}
145
146void MetricsLog::RecordUserAction(const wchar_t* key) {
147 DCHECK(!locked_);
148
149 std::string command_hash = CreateBase64Hash(WideToUTF8(key));
150 if (command_hash.empty()) {
151 NOTREACHED() << "Unable generate encoded hash of command: " << key;
152 return;
153 }
154
155 StartElement("uielement");
156 WriteAttribute("action", "command");
157 WriteAttribute("targetidhash", command_hash);
158
159 // TODO(jhughes): Properly track windows.
160 WriteIntAttribute("window", 0);
161 WriteCommonEventAttributes();
162 EndElement();
163
164 ++num_events_;
165}
166
167void 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
174 StartElement("document");
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:
204 origin_string = "global-history";
205 break;
206
207 case PageTransition::START_PAGE:
208 origin_string = "start-page";
209 break;
210
211 case PageTransition::FORM_SUBMIT:
212 origin_string = "form-submit";
213 break;
214
215 default:
216 NOTREACHED() << "Received an unknown page transition type: " <<
217 PageTransition::StripQualifier(origin);
218 }
219 if (!origin_string.empty())
220 WriteAttribute("origin", origin_string);
221
222 WriteCommonEventAttributes();
223 EndElement();
224
225 ++num_events_;
226}
227
228// static
229const char* MetricsLog::WindowEventTypeToString(WindowEventType type) {
230 switch (type) {
231 case WINDOW_CREATE:
232 return "create";
233
234 case WINDOW_OPEN:
235 return "open";
236
237 case WINDOW_CLOSE:
238 return "close";
239
240 case WINDOW_DESTROY:
241 return "destroy";
242
243 default:
244 NOTREACHED();
245 return "unknown";
246 }
247}
248
249void MetricsLog::RecordWindowEvent(WindowEventType type,
250 int window_id,
251 int parent_id) {
252 DCHECK(!locked_);
253
254 StartElement("window");
255 WriteAttribute("action", WindowEventTypeToString(type));
256 WriteAttribute("windowid", IntToString(window_id));
257 if (parent_id >= 0)
258 WriteAttribute("parent", IntToString(parent_id));
259 WriteCommonEventAttributes();
260 EndElement();
261
262 ++num_events_;
263}
264
265std::string MetricsLog::GetCurrentTimeString() {
266 return Uint64ToString(Time::Now().ToTimeT());
267}
268
269// These are the attributes that are common to every event.
270void MetricsLog::WriteCommonEventAttributes() {
271 WriteAttribute("session", session_id_);
272 WriteAttribute("time", GetCurrentTimeString());
273}
274
275void MetricsLog::WriteAttribute(const std::string& name,
276 const std::string& value) {
277 DCHECK(!locked_);
278 DCHECK(!name.empty());
279
280 int result = xmlTextWriterWriteAttribute(writer_,
281 UnsignedChar(name.c_str()),
282 UnsignedChar(value.c_str()));
283 DCHECK_GE(result, 0);
284}
285
286void MetricsLog::WriteIntAttribute(const std::string& name, int value) {
287 WriteAttribute(name, IntToString(value));
288}
289
290void MetricsLog::WriteInt64Attribute(const std::string& name, int64 value) {
291 WriteAttribute(name, Int64ToString(value));
292}
293
294void MetricsLog::StartElement(const char* name) {
295 DCHECK(!locked_);
296 DCHECK(name);
297
298 int result = xmlTextWriterStartElement(writer_, UnsignedChar(name));
299 DCHECK_GE(result, 0);
300}
301
302void MetricsLog::EndElement() {
303 DCHECK(!locked_);
304
305 int result = xmlTextWriterEndElement(writer_);
306 DCHECK_GE(result, 0);
307}
308
309std::string MetricsLog::GetVersionString() const {
310 scoped_ptr<FileVersionInfo> version_info(
311 FileVersionInfo::CreateFileVersionInfoForCurrentModule());
312 if (version_info.get()) {
313 std::string version = WideToUTF8(version_info->product_version());
314 if (!version_info->is_official_build())
315 version.append("-devel");
316 return version;
317 } else {
318 NOTREACHED() << "Unable to retrieve version string.";
319 }
320
321 return std::string();
322}
323
324std::string MetricsLog::GetInstallDate() const {
325 PrefService* pref = g_browser_process->local_state();
326 if (pref) {
327 return WideToUTF8(pref->GetString(prefs::kMetricsClientIDTimestamp));
328 } else {
329 NOTREACHED();
330 return "0";
331 }
332}
333
334void MetricsLog::WriteStabilityElement() {
335 DCHECK(!locked_);
336
337 PrefService* pref = g_browser_process->local_state();
338 DCHECK(pref);
339
340 // Get stability attributes out of Local State, zeroing out stored values.
341 // NOTE: This could lead to some data loss if this report isn't successfully
342 // sent, but that's true for all the metrics.
343
344 StartElement("stability");
345
346 WriteIntAttribute("launchcount",
347 pref->GetInteger(prefs::kStabilityLaunchCount));
348 pref->SetInteger(prefs::kStabilityLaunchCount, 0);
349 WriteIntAttribute("crashcount",
350 pref->GetInteger(prefs::kStabilityCrashCount));
351 pref->SetInteger(prefs::kStabilityCrashCount, 0);
[email protected]8e674e42008-07-30 16:05:48352 WriteIntAttribute("incompleteshutdowncount",
353 pref->GetInteger(
354 prefs::kStabilityIncompleteSessionEndCount));
355 pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0);
initial.commit09911bf2008-07-26 23:55:29356 WriteIntAttribute("pageloadcount",
357 pref->GetInteger(prefs::kStabilityPageLoadCount));
358 pref->SetInteger(prefs::kStabilityPageLoadCount, 0);
359 WriteIntAttribute("renderercrashcount",
360 pref->GetInteger(prefs::kStabilityRendererCrashCount));
361 pref->SetInteger(prefs::kStabilityRendererCrashCount, 0);
362 WriteIntAttribute("rendererhangcount",
363 pref->GetInteger(prefs::kStabilityRendererHangCount));
364 pref->SetInteger(prefs::kStabilityRendererHangCount, 0);
365
366 // Uptime is stored as a string, since there's no int64 in Value/JSON.
367 WriteAttribute("uptimesec",
368 WideToUTF8(pref->GetString(prefs::kStabilityUptimeSec)));
369 pref->SetString(prefs::kStabilityUptimeSec, L"0");
370
371 // Now log plugin stability info
372 const ListValue* plugin_stats_list = pref->GetList(
373 prefs::kStabilityPluginStats);
374 if (plugin_stats_list) {
375 StartElement("plugins");
376 for (ListValue::const_iterator iter = plugin_stats_list->begin();
377 iter != plugin_stats_list->end(); ++iter) {
378 if (!(*iter)->IsType(Value::TYPE_DICTIONARY)) {
379 NOTREACHED();
380 continue;
381 }
382 DictionaryValue* plugin_dict = static_cast<DictionaryValue*>(*iter);
383
384 std::wstring plugin_path;
385 plugin_dict->GetString(prefs::kStabilityPluginPath, &plugin_path);
386 plugin_path = file_util::GetFilenameFromPath(plugin_path);
387 if (plugin_path.empty()) {
388 NOTREACHED();
389 continue;
390 }
391
392 StartElement("pluginstability");
393 WriteAttribute("filename", CreateBase64Hash(WideToUTF8(plugin_path)));
394
395 int launches = 0;
396 plugin_dict->GetInteger(prefs::kStabilityPluginLaunches, &launches);
397 WriteIntAttribute("launchcount", launches);
398
399 int instances = 0;
400 plugin_dict->GetInteger(prefs::kStabilityPluginInstances, &instances);
401 WriteIntAttribute("instancecount", instances);
402
403 int crashes = 0;
404 plugin_dict->GetInteger(prefs::kStabilityPluginCrashes, &crashes);
405 WriteIntAttribute("crashcount", crashes);
406 EndElement();
407 }
408
409 pref->ClearPref(prefs::kStabilityPluginStats);
410 EndElement();
411 }
412
413 EndElement();
414}
415
416void MetricsLog::WritePluginList(
417 const std::vector<WebPluginInfo>& plugin_list) {
418 DCHECK(!locked_);
419
420 StartElement("plugins");
421
422 for (std::vector<WebPluginInfo>::const_iterator iter = plugin_list.begin();
423 iter != plugin_list.end(); ++iter) {
424 StartElement("plugin");
425
426 // Plugin name and filename are hashed for the privacy of those
427 // testing unreleased new extensions.
428 WriteAttribute("name", CreateBase64Hash(WideToUTF8((*iter).name)));
429 std::wstring filename = file_util::GetFilenameFromPath((*iter).file);
430 WriteAttribute("filename", CreateBase64Hash(WideToUTF8(filename)));
431
432 WriteAttribute("version", WideToUTF8((*iter).version));
433
434 EndElement();
435 }
436
437 EndElement();
438}
439
440void MetricsLog::RecordEnvironment(
441 const std::vector<WebPluginInfo>& plugin_list,
442 const DictionaryValue* profile_metrics) {
443 DCHECK(!locked_);
444
445 PrefService* pref = g_browser_process->local_state();
446
447 StartElement("profile");
448 WriteCommonEventAttributes();
449
450 StartElement("install");
451 WriteAttribute("installdate", GetInstallDate());
452 WriteIntAttribute("buildid", 0); // means that we're using appversion instead
453 WriteAttribute("appversion", GetVersionString());
454 EndElement();
455
456 WritePluginList(plugin_list);
457
458 WriteStabilityElement();
459
460 {
461 OPEN_ELEMENT_FOR_SCOPE("cpu");
462 WriteAttribute("arch", env_util::GetCPUArchitecture());
463 }
464
465 {
466 OPEN_ELEMENT_FOR_SCOPE("security");
467 WriteIntAttribute("rendereronsboxdesktop",
468 pref->GetInteger(prefs::kSecurityRendererOnSboxDesktop));
469 pref->SetInteger(prefs::kSecurityRendererOnSboxDesktop, 0);
470
471 WriteIntAttribute("rendererondefaultdesktop",
472 pref->GetInteger(prefs::kSecurityRendererOnDefaultDesktop));
473 pref->SetInteger(prefs::kSecurityRendererOnDefaultDesktop, 0);
474 }
475
476 {
477 OPEN_ELEMENT_FOR_SCOPE("memory");
478 WriteIntAttribute("mb", env_util::GetPhysicalMemoryMB());
479 }
480
481 {
482 OPEN_ELEMENT_FOR_SCOPE("os");
483 WriteAttribute("name",
484 env_util::GetOperatingSystemName());
485 WriteAttribute("version",
486 env_util::GetOperatingSystemVersion());
487 }
488
489 {
490 OPEN_ELEMENT_FOR_SCOPE("display");
491 int width = 0;
492 int height = 0;
493 env_util::GetPrimaryDisplayDimensions(&width, &height);
494 WriteIntAttribute("xsize", width);
495 WriteIntAttribute("ysize", height);
496 WriteIntAttribute("screens", env_util::GetDisplayCount());
497 }
498
499 {
500 OPEN_ELEMENT_FOR_SCOPE("bookmarks");
501 int num_bookmarks_on_bookmark_bar =
502 pref->GetInteger(prefs::kNumBookmarksOnBookmarkBar);
503 int num_folders_on_bookmark_bar =
504 pref->GetInteger(prefs::kNumFoldersOnBookmarkBar);
505 int num_bookmarks_in_other_bookmarks_folder =
506 pref->GetInteger(prefs::kNumBookmarksInOtherBookmarkFolder);
507 int num_folders_in_other_bookmarks_folder =
508 pref->GetInteger(prefs::kNumFoldersInOtherBookmarkFolder);
509 {
510 OPEN_ELEMENT_FOR_SCOPE("bookmarklocation");
511 WriteAttribute("name", "full-tree");
512 WriteIntAttribute("foldercount",
513 num_folders_on_bookmark_bar + num_folders_in_other_bookmarks_folder);
514 WriteIntAttribute("itemcount",
515 num_bookmarks_on_bookmark_bar +
516 num_bookmarks_in_other_bookmarks_folder);
517 }
518 {
519 OPEN_ELEMENT_FOR_SCOPE("bookmarklocation");
520 WriteAttribute("name", "toolbar");
521 WriteIntAttribute("foldercount", num_folders_on_bookmark_bar);
522 WriteIntAttribute("itemcount", num_bookmarks_on_bookmark_bar);
523 }
524 }
525
526 {
527 OPEN_ELEMENT_FOR_SCOPE("keywords");
528 WriteIntAttribute("count", pref->GetInteger(prefs::kNumKeywords));
529 }
530
531 if (profile_metrics)
532 WriteAllProfilesMetrics(*profile_metrics);
533
534 EndElement(); // profile
535}
536
537void MetricsLog::WriteAllProfilesMetrics(
538 const DictionaryValue& all_profiles_metrics) {
539 const std::wstring profile_prefix(prefs::kProfilePrefix);
540 for (DictionaryValue::key_iterator i = all_profiles_metrics.begin_keys();
541 i != all_profiles_metrics.end_keys(); ++i) {
542 const std::wstring& key_name = *i;
543 if (key_name.compare(0, profile_prefix.size(), profile_prefix) == 0) {
544 DictionaryValue* profile;
545 if (all_profiles_metrics.GetDictionary(key_name, &profile))
546 WriteProfileMetrics(key_name.substr(profile_prefix.size()), *profile);
547 }
548 }
549}
550
551void MetricsLog::WriteProfileMetrics(const std::wstring& profileidhash,
552 const DictionaryValue& profile_metrics) {
553 OPEN_ELEMENT_FOR_SCOPE("userprofile");
554 WriteAttribute("profileidhash", WideToUTF8(profileidhash));
555 for (DictionaryValue::key_iterator i = profile_metrics.begin_keys();
556 i != profile_metrics.end_keys(); ++i) {
557 Value* value;
558 if (profile_metrics.Get(*i, &value)) {
559 DCHECK(*i != L"id");
560 switch (value->GetType()) {
561 case Value::TYPE_STRING: {
562 std::wstring string_value;
563 if (value->GetAsString(&string_value)) {
564 OPEN_ELEMENT_FOR_SCOPE("profileparam");
565 WriteAttribute("name", WideToUTF8(*i));
566 WriteAttribute("value", WideToUTF8(string_value));
567 }
568 break;
569 }
570
571 case Value::TYPE_BOOLEAN: {
572 bool bool_value;
573 if (value->GetAsBoolean(&bool_value)) {
574 OPEN_ELEMENT_FOR_SCOPE("profileparam");
575 WriteAttribute("name", WideToUTF8(*i));
576 WriteIntAttribute("value", bool_value ? 1 : 0);
577 }
578 break;
579 }
580
581 case Value::TYPE_INTEGER: {
582 int int_value;
583 if (value->GetAsInteger(&int_value)) {
584 OPEN_ELEMENT_FOR_SCOPE("profileparam");
585 WriteAttribute("name", WideToUTF8(*i));
586 WriteIntAttribute("value", int_value);
587 }
588 break;
589 }
590
591 default:
592 NOTREACHED();
593 break;
594 }
595 }
596 }
597}
598
599void MetricsLog::RecordOmniboxOpenedURL(const AutocompleteLog& log) {
600 DCHECK(!locked_);
601
602 StartElement("uielement");
603 WriteAttribute("action", "autocomplete");
604 WriteAttribute("targetidhash", "");
605 // TODO(kochi): Properly track windows.
606 WriteIntAttribute("window", 0);
607 WriteCommonEventAttributes();
608
609 StartElement("autocomplete");
610
611 WriteIntAttribute("typedlength", static_cast<int>(log.text.length()));
612 WriteIntAttribute("completedlength",
613 static_cast<int>(log.inline_autocompleted_length));
614 WriteIntAttribute("selectedindex", static_cast<int>(log.selected_index));
615
616 for (AutocompleteResult::const_iterator i(log.result.begin());
617 i != log.result.end(); ++i) {
618 StartElement("autocompleteitem");
619 if (i->provider)
620 WriteAttribute("provider", i->provider->name());
621 WriteIntAttribute("relevance", i->relevance);
622 WriteIntAttribute("isstarred", i->starred ? 1 : 0);
623 EndElement(); // autocompleteitem
624 }
625 EndElement(); // autocomplete
626 EndElement(); // uielement
627
628 ++num_events_;
629}
630
631// TODO(JAR): A The following should really be part of the histogram class.
632// Internal state is being needlessly exposed, and it would be hard to reuse
633// this code. If we moved this into the Histogram class, then we could use
634// the same infrastructure for logging StatsCounters, RatesCounters, etc.
635void MetricsLog::RecordHistogramDelta(const Histogram& histogram,
636 const Histogram::SampleSet& snapshot) {
637 DCHECK(!locked_);
638 DCHECK(0 != snapshot.TotalCount());
639 snapshot.CheckSize(histogram);
640
641 // We will ignore the MAX_INT/infinite value in the last element of range[].
642
643 OPEN_ELEMENT_FOR_SCOPE("histogram");
644
645 WriteAttribute("name", CreateBase64Hash(histogram.histogram_name()));
646
647 WriteInt64Attribute("sum", snapshot.sum());
648 WriteInt64Attribute("sumsquares", snapshot.square_sum());
649
650 for (size_t i = 0; i < histogram.bucket_count(); i++) {
651 if (snapshot.counts(i)) {
652 OPEN_ELEMENT_FOR_SCOPE("histogrambucket");
653 WriteIntAttribute("min", histogram.ranges(i));
654 WriteIntAttribute("max", histogram.ranges(i + 1));
655 WriteIntAttribute("count", snapshot.counts(i));
656 }
657 }
658}