blob: 06daa76dd6eb1b7aca0d700d56b1c039c4897fd2 [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;
139 if (Base64Encode(CreateHash(string), &encoded_digest)) {
140 DLOG(INFO) << "Metrics: Hash [" << encoded_digest << "]=[" << string << "]";
141 return encoded_digest;
142 } else {
143 return std::string();
144 }
145}
146
147void MetricsLog::RecordUserAction(const wchar_t* key) {
148 DCHECK(!locked_);
149
150 std::string command_hash = CreateBase64Hash(WideToUTF8(key));
151 if (command_hash.empty()) {
152 NOTREACHED() << "Unable generate encoded hash of command: " << key;
153 return;
154 }
155
156 StartElement("uielement");
157 WriteAttribute("action", "command");
158 WriteAttribute("targetidhash", command_hash);
159
160 // TODO(jhughes): Properly track windows.
161 WriteIntAttribute("window", 0);
162 WriteCommonEventAttributes();
163 EndElement();
164
165 ++num_events_;
166}
167
168void 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
175 StartElement("document");
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:
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();
224 EndElement();
225
226 ++num_events_;
227}
228
229// static
230const char* MetricsLog::WindowEventTypeToString(WindowEventType type) {
231 switch (type) {
232 case WINDOW_CREATE:
233 return "create";
234
235 case WINDOW_OPEN:
236 return "open";
237
238 case WINDOW_CLOSE:
239 return "close";
240
241 case WINDOW_DESTROY:
242 return "destroy";
243
244 default:
245 NOTREACHED();
246 return "unknown";
247 }
248}
249
250void MetricsLog::RecordWindowEvent(WindowEventType type,
251 int window_id,
252 int parent_id) {
253 DCHECK(!locked_);
254
255 StartElement("window");
256 WriteAttribute("action", WindowEventTypeToString(type));
257 WriteAttribute("windowid", IntToString(window_id));
258 if (parent_id >= 0)
259 WriteAttribute("parent", IntToString(parent_id));
260 WriteCommonEventAttributes();
261 EndElement();
262
263 ++num_events_;
264}
265
266std::string MetricsLog::GetCurrentTimeString() {
267 return Uint64ToString(Time::Now().ToTimeT());
268}
269
270// These are the attributes that are common to every event.
271void MetricsLog::WriteCommonEventAttributes() {
272 WriteAttribute("session", session_id_);
273 WriteAttribute("time", GetCurrentTimeString());
274}
275
276void MetricsLog::WriteAttribute(const std::string& name,
277 const std::string& value) {
278 DCHECK(!locked_);
279 DCHECK(!name.empty());
280
281 int result = xmlTextWriterWriteAttribute(writer_,
282 UnsignedChar(name.c_str()),
283 UnsignedChar(value.c_str()));
284 DCHECK_GE(result, 0);
285}
286
287void MetricsLog::WriteIntAttribute(const std::string& name, int value) {
288 WriteAttribute(name, IntToString(value));
289}
290
291void MetricsLog::WriteInt64Attribute(const std::string& name, int64 value) {
292 WriteAttribute(name, Int64ToString(value));
293}
294
295void MetricsLog::StartElement(const char* name) {
296 DCHECK(!locked_);
297 DCHECK(name);
298
299 int result = xmlTextWriterStartElement(writer_, UnsignedChar(name));
300 DCHECK_GE(result, 0);
301}
302
303void MetricsLog::EndElement() {
304 DCHECK(!locked_);
305
306 int result = xmlTextWriterEndElement(writer_);
307 DCHECK_GE(result, 0);
308}
309
310std::string MetricsLog::GetVersionString() const {
311 scoped_ptr<FileVersionInfo> version_info(
312 FileVersionInfo::CreateFileVersionInfoForCurrentModule());
313 if (version_info.get()) {
314 std::string version = WideToUTF8(version_info->product_version());
315 if (!version_info->is_official_build())
316 version.append("-devel");
317 return version;
318 } else {
319 NOTREACHED() << "Unable to retrieve version string.";
320 }
321
322 return std::string();
323}
324
325std::string MetricsLog::GetInstallDate() const {
326 PrefService* pref = g_browser_process->local_state();
327 if (pref) {
328 return WideToUTF8(pref->GetString(prefs::kMetricsClientIDTimestamp));
329 } else {
330 NOTREACHED();
331 return "0";
332 }
333}
334
335void MetricsLog::WriteStabilityElement() {
336 DCHECK(!locked_);
337
338 PrefService* pref = g_browser_process->local_state();
339 DCHECK(pref);
340
341 // Get stability attributes out of Local State, zeroing out stored values.
342 // NOTE: This could lead to some data loss if this report isn't successfully
343 // sent, but that's true for all the metrics.
344
345 StartElement("stability");
346
347 WriteIntAttribute("launchcount",
348 pref->GetInteger(prefs::kStabilityLaunchCount));
349 pref->SetInteger(prefs::kStabilityLaunchCount, 0);
350 WriteIntAttribute("crashcount",
351 pref->GetInteger(prefs::kStabilityCrashCount));
352 pref->SetInteger(prefs::kStabilityCrashCount, 0);
[email protected]8e674e42008-07-30 16:05:48353 WriteIntAttribute("incompleteshutdowncount",
354 pref->GetInteger(
355 prefs::kStabilityIncompleteSessionEndCount));
356 pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0);
initial.commit09911bf2008-07-26 23:55:29357 WriteIntAttribute("pageloadcount",
358 pref->GetInteger(prefs::kStabilityPageLoadCount));
359 pref->SetInteger(prefs::kStabilityPageLoadCount, 0);
360 WriteIntAttribute("renderercrashcount",
361 pref->GetInteger(prefs::kStabilityRendererCrashCount));
362 pref->SetInteger(prefs::kStabilityRendererCrashCount, 0);
363 WriteIntAttribute("rendererhangcount",
364 pref->GetInteger(prefs::kStabilityRendererHangCount));
365 pref->SetInteger(prefs::kStabilityRendererHangCount, 0);
366
367 // Uptime is stored as a string, since there's no int64 in Value/JSON.
368 WriteAttribute("uptimesec",
369 WideToUTF8(pref->GetString(prefs::kStabilityUptimeSec)));
370 pref->SetString(prefs::kStabilityUptimeSec, L"0");
371
372 // Now log plugin stability info
373 const ListValue* plugin_stats_list = pref->GetList(
374 prefs::kStabilityPluginStats);
375 if (plugin_stats_list) {
376 StartElement("plugins");
377 for (ListValue::const_iterator iter = plugin_stats_list->begin();
378 iter != plugin_stats_list->end(); ++iter) {
379 if (!(*iter)->IsType(Value::TYPE_DICTIONARY)) {
380 NOTREACHED();
381 continue;
382 }
383 DictionaryValue* plugin_dict = static_cast<DictionaryValue*>(*iter);
384
385 std::wstring plugin_path;
386 plugin_dict->GetString(prefs::kStabilityPluginPath, &plugin_path);
387 plugin_path = file_util::GetFilenameFromPath(plugin_path);
388 if (plugin_path.empty()) {
389 NOTREACHED();
390 continue;
391 }
392
393 StartElement("pluginstability");
394 WriteAttribute("filename", CreateBase64Hash(WideToUTF8(plugin_path)));
395
396 int launches = 0;
397 plugin_dict->GetInteger(prefs::kStabilityPluginLaunches, &launches);
398 WriteIntAttribute("launchcount", launches);
399
400 int instances = 0;
401 plugin_dict->GetInteger(prefs::kStabilityPluginInstances, &instances);
402 WriteIntAttribute("instancecount", instances);
403
404 int crashes = 0;
405 plugin_dict->GetInteger(prefs::kStabilityPluginCrashes, &crashes);
406 WriteIntAttribute("crashcount", crashes);
407 EndElement();
408 }
409
410 pref->ClearPref(prefs::kStabilityPluginStats);
411 EndElement();
412 }
413
414 EndElement();
415}
416
417void MetricsLog::WritePluginList(
418 const std::vector<WebPluginInfo>& plugin_list) {
419 DCHECK(!locked_);
420
421 StartElement("plugins");
422
423 for (std::vector<WebPluginInfo>::const_iterator iter = plugin_list.begin();
424 iter != plugin_list.end(); ++iter) {
425 StartElement("plugin");
426
427 // Plugin name and filename are hashed for the privacy of those
428 // testing unreleased new extensions.
429 WriteAttribute("name", CreateBase64Hash(WideToUTF8((*iter).name)));
430 std::wstring filename = file_util::GetFilenameFromPath((*iter).file);
431 WriteAttribute("filename", CreateBase64Hash(WideToUTF8(filename)));
432
433 WriteAttribute("version", WideToUTF8((*iter).version));
434
435 EndElement();
436 }
437
438 EndElement();
439}
440
441void MetricsLog::RecordEnvironment(
442 const std::vector<WebPluginInfo>& plugin_list,
443 const DictionaryValue* profile_metrics) {
444 DCHECK(!locked_);
445
446 PrefService* pref = g_browser_process->local_state();
447
448 StartElement("profile");
449 WriteCommonEventAttributes();
450
451 StartElement("install");
452 WriteAttribute("installdate", GetInstallDate());
453 WriteIntAttribute("buildid", 0); // means that we're using appversion instead
454 WriteAttribute("appversion", GetVersionString());
455 EndElement();
456
457 WritePluginList(plugin_list);
458
459 WriteStabilityElement();
460
461 {
462 OPEN_ELEMENT_FOR_SCOPE("cpu");
463 WriteAttribute("arch", env_util::GetCPUArchitecture());
464 }
465
466 {
467 OPEN_ELEMENT_FOR_SCOPE("security");
468 WriteIntAttribute("rendereronsboxdesktop",
469 pref->GetInteger(prefs::kSecurityRendererOnSboxDesktop));
470 pref->SetInteger(prefs::kSecurityRendererOnSboxDesktop, 0);
471
472 WriteIntAttribute("rendererondefaultdesktop",
473 pref->GetInteger(prefs::kSecurityRendererOnDefaultDesktop));
474 pref->SetInteger(prefs::kSecurityRendererOnDefaultDesktop, 0);
475 }
476
477 {
478 OPEN_ELEMENT_FOR_SCOPE("memory");
479 WriteIntAttribute("mb", env_util::GetPhysicalMemoryMB());
480 }
481
482 {
483 OPEN_ELEMENT_FOR_SCOPE("os");
484 WriteAttribute("name",
485 env_util::GetOperatingSystemName());
486 WriteAttribute("version",
487 env_util::GetOperatingSystemVersion());
488 }
489
490 {
491 OPEN_ELEMENT_FOR_SCOPE("display");
492 int width = 0;
493 int height = 0;
494 env_util::GetPrimaryDisplayDimensions(&width, &height);
495 WriteIntAttribute("xsize", width);
496 WriteIntAttribute("ysize", height);
497 WriteIntAttribute("screens", env_util::GetDisplayCount());
498 }
499
500 {
501 OPEN_ELEMENT_FOR_SCOPE("bookmarks");
502 int num_bookmarks_on_bookmark_bar =
503 pref->GetInteger(prefs::kNumBookmarksOnBookmarkBar);
504 int num_folders_on_bookmark_bar =
505 pref->GetInteger(prefs::kNumFoldersOnBookmarkBar);
506 int num_bookmarks_in_other_bookmarks_folder =
507 pref->GetInteger(prefs::kNumBookmarksInOtherBookmarkFolder);
508 int num_folders_in_other_bookmarks_folder =
509 pref->GetInteger(prefs::kNumFoldersInOtherBookmarkFolder);
510 {
511 OPEN_ELEMENT_FOR_SCOPE("bookmarklocation");
512 WriteAttribute("name", "full-tree");
513 WriteIntAttribute("foldercount",
514 num_folders_on_bookmark_bar + num_folders_in_other_bookmarks_folder);
515 WriteIntAttribute("itemcount",
516 num_bookmarks_on_bookmark_bar +
517 num_bookmarks_in_other_bookmarks_folder);
518 }
519 {
520 OPEN_ELEMENT_FOR_SCOPE("bookmarklocation");
521 WriteAttribute("name", "toolbar");
522 WriteIntAttribute("foldercount", num_folders_on_bookmark_bar);
523 WriteIntAttribute("itemcount", num_bookmarks_on_bookmark_bar);
524 }
525 }
526
527 {
528 OPEN_ELEMENT_FOR_SCOPE("keywords");
529 WriteIntAttribute("count", pref->GetInteger(prefs::kNumKeywords));
530 }
531
532 if (profile_metrics)
533 WriteAllProfilesMetrics(*profile_metrics);
534
535 EndElement(); // profile
536}
537
538void MetricsLog::WriteAllProfilesMetrics(
539 const DictionaryValue& all_profiles_metrics) {
540 const std::wstring profile_prefix(prefs::kProfilePrefix);
541 for (DictionaryValue::key_iterator i = all_profiles_metrics.begin_keys();
542 i != all_profiles_metrics.end_keys(); ++i) {
543 const std::wstring& key_name = *i;
544 if (key_name.compare(0, profile_prefix.size(), profile_prefix) == 0) {
545 DictionaryValue* profile;
546 if (all_profiles_metrics.GetDictionary(key_name, &profile))
547 WriteProfileMetrics(key_name.substr(profile_prefix.size()), *profile);
548 }
549 }
550}
551
552void MetricsLog::WriteProfileMetrics(const std::wstring& profileidhash,
553 const DictionaryValue& profile_metrics) {
554 OPEN_ELEMENT_FOR_SCOPE("userprofile");
555 WriteAttribute("profileidhash", WideToUTF8(profileidhash));
556 for (DictionaryValue::key_iterator i = profile_metrics.begin_keys();
557 i != profile_metrics.end_keys(); ++i) {
558 Value* value;
559 if (profile_metrics.Get(*i, &value)) {
560 DCHECK(*i != L"id");
561 switch (value->GetType()) {
562 case Value::TYPE_STRING: {
563 std::wstring string_value;
564 if (value->GetAsString(&string_value)) {
565 OPEN_ELEMENT_FOR_SCOPE("profileparam");
566 WriteAttribute("name", WideToUTF8(*i));
567 WriteAttribute("value", WideToUTF8(string_value));
568 }
569 break;
570 }
571
572 case Value::TYPE_BOOLEAN: {
573 bool bool_value;
574 if (value->GetAsBoolean(&bool_value)) {
575 OPEN_ELEMENT_FOR_SCOPE("profileparam");
576 WriteAttribute("name", WideToUTF8(*i));
577 WriteIntAttribute("value", bool_value ? 1 : 0);
578 }
579 break;
580 }
581
582 case Value::TYPE_INTEGER: {
583 int int_value;
584 if (value->GetAsInteger(&int_value)) {
585 OPEN_ELEMENT_FOR_SCOPE("profileparam");
586 WriteAttribute("name", WideToUTF8(*i));
587 WriteIntAttribute("value", int_value);
588 }
589 break;
590 }
591
592 default:
593 NOTREACHED();
594 break;
595 }
596 }
597 }
598}
599
600void MetricsLog::RecordOmniboxOpenedURL(const AutocompleteLog& log) {
601 DCHECK(!locked_);
602
603 StartElement("uielement");
604 WriteAttribute("action", "autocomplete");
605 WriteAttribute("targetidhash", "");
606 // TODO(kochi): Properly track windows.
607 WriteIntAttribute("window", 0);
608 WriteCommonEventAttributes();
609
610 StartElement("autocomplete");
611
612 WriteIntAttribute("typedlength", static_cast<int>(log.text.length()));
613 WriteIntAttribute("completedlength",
614 static_cast<int>(log.inline_autocompleted_length));
615 WriteIntAttribute("selectedindex", static_cast<int>(log.selected_index));
616
617 for (AutocompleteResult::const_iterator i(log.result.begin());
618 i != log.result.end(); ++i) {
619 StartElement("autocompleteitem");
620 if (i->provider)
621 WriteAttribute("provider", i->provider->name());
622 WriteIntAttribute("relevance", i->relevance);
623 WriteIntAttribute("isstarred", i->starred ? 1 : 0);
624 EndElement(); // autocompleteitem
625 }
626 EndElement(); // autocomplete
627 EndElement(); // uielement
628
629 ++num_events_;
630}
631
632// TODO(JAR): A The following should really be part of the histogram class.
633// Internal state is being needlessly exposed, and it would be hard to reuse
634// this code. If we moved this into the Histogram class, then we could use
635// the same infrastructure for logging StatsCounters, RatesCounters, etc.
636void MetricsLog::RecordHistogramDelta(const Histogram& histogram,
637 const Histogram::SampleSet& snapshot) {
638 DCHECK(!locked_);
639 DCHECK(0 != snapshot.TotalCount());
640 snapshot.CheckSize(histogram);
641
642 // We will ignore the MAX_INT/infinite value in the last element of range[].
643
644 OPEN_ELEMENT_FOR_SCOPE("histogram");
645
646 WriteAttribute("name", CreateBase64Hash(histogram.histogram_name()));
647
648 WriteInt64Attribute("sum", snapshot.sum());
649 WriteInt64Attribute("sumsquares", snapshot.square_sum());
650
651 for (size_t i = 0; i < histogram.bucket_count(); i++) {
652 if (snapshot.counts(i)) {
653 OPEN_ELEMENT_FOR_SCOPE("histogrambucket");
654 WriteIntAttribute("min", histogram.ranges(i));
655 WriteIntAttribute("max", histogram.ranges(i + 1));
656 WriteIntAttribute("count", snapshot.counts(i));
657 }
658 }
659}