OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/metrics_log.h" | 5 #include "chrome/browser/metrics_log.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/file_version_info.h" | 9 #include "base/file_version_info.h" |
10 #include "base/md5.h" | 10 #include "base/md5.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 return reinterpret_cast<const unsigned char*>(input); | 34 return reinterpret_cast<const unsigned char*>(input); |
35 } | 35 } |
36 | 36 |
37 // static | 37 // static |
38 void MetricsLog::RegisterPrefs(PrefService* local_state) { | 38 void MetricsLog::RegisterPrefs(PrefService* local_state) { |
39 local_state->RegisterListPref(prefs::kStabilityPluginStats); | 39 local_state->RegisterListPref(prefs::kStabilityPluginStats); |
40 } | 40 } |
41 | 41 |
42 MetricsLog::MetricsLog(const std::string& client_id, int session_id) | 42 MetricsLog::MetricsLog(const std::string& client_id, int session_id) |
43 : start_time_(Time::Now()), | 43 : start_time_(Time::Now()), |
44 num_events_(0), | 44 client_id_(client_id), |
| 45 session_id_(IntToString(session_id)), |
45 locked_(false), | 46 locked_(false), |
46 buffer_(NULL), | 47 buffer_(NULL), |
47 writer_(NULL), | 48 writer_(NULL), |
48 client_id_(client_id), | 49 num_events_(0) { |
49 session_id_(IntToString(session_id)) { | |
50 | 50 |
51 buffer_ = xmlBufferCreate(); | 51 buffer_ = xmlBufferCreate(); |
52 DCHECK(buffer_); | 52 DCHECK(buffer_); |
53 | 53 |
54 writer_ = xmlNewTextWriterMemory(buffer_, 0); | 54 writer_ = xmlNewTextWriterMemory(buffer_, 0); |
55 DCHECK(writer_); | 55 DCHECK(writer_); |
56 | 56 |
57 int result = xmlTextWriterSetIndent(writer_, 2); | 57 int result = xmlTextWriterSetIndent(writer_, 2); |
58 DCHECK_EQ(0, result); | 58 DCHECK_EQ(0, result); |
59 | 59 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 std::string MetricsLog::CreateHash(const std::string& value) { | 103 std::string MetricsLog::CreateHash(const std::string& value) { |
104 MD5Context ctx; | 104 MD5Context ctx; |
105 MD5Init(&ctx); | 105 MD5Init(&ctx); |
106 MD5Update(&ctx, value.data(), value.length()); | 106 MD5Update(&ctx, value.data(), value.length()); |
107 | 107 |
108 MD5Digest digest; | 108 MD5Digest digest; |
109 MD5Final(&digest, &ctx); | 109 MD5Final(&digest, &ctx); |
110 | 110 |
111 unsigned char reverse[8]; // UMA only uses first 8 chars of hash. | 111 unsigned char reverse[8]; // UMA only uses first 8 chars of hash. |
112 DCHECK(arraysize(digest.a) >= arraysize(reverse)); | 112 DCHECK(arraysize(digest.a) >= arraysize(reverse)); |
113 for (int i = 0; i < arraysize(reverse); ++i) | 113 for (size_t i = 0; i < arraysize(reverse); ++i) |
114 reverse[i] = digest.a[arraysize(reverse) - i - 1]; | 114 reverse[i] = digest.a[arraysize(reverse) - i - 1]; |
115 LOG(INFO) << "Metrics: Hash numeric [" << value << "]=[" | 115 LOG(INFO) << "Metrics: Hash numeric [" << value << "]=[" |
116 << *reinterpret_cast<const uint64*>(&reverse[0]) << "]"; | 116 << *reinterpret_cast<const uint64*>(&reverse[0]) << "]"; |
117 return std::string(reinterpret_cast<char*>(digest.a), arraysize(digest.a)); | 117 return std::string(reinterpret_cast<char*>(digest.a), arraysize(digest.a)); |
118 } | 118 } |
119 | 119 |
120 std::string MetricsLog::CreateBase64Hash(const std::string& string) { | 120 std::string MetricsLog::CreateBase64Hash(const std::string& string) { |
121 std::string encoded_digest; | 121 std::string encoded_digest; |
122 if (net::Base64Encode(CreateHash(string), &encoded_digest)) { | 122 if (net::Base64Encode(CreateHash(string), &encoded_digest)) { |
123 DLOG(INFO) << "Metrics: Hash [" << encoded_digest << "]=[" << string << "]"; | 123 DLOG(INFO) << "Metrics: Hash [" << encoded_digest << "]=[" << string << "]"; |
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 | 635 |
636 for (size_t i = 0; i < histogram.bucket_count(); i++) { | 636 for (size_t i = 0; i < histogram.bucket_count(); i++) { |
637 if (snapshot.counts(i)) { | 637 if (snapshot.counts(i)) { |
638 OPEN_ELEMENT_FOR_SCOPE("histogrambucket"); | 638 OPEN_ELEMENT_FOR_SCOPE("histogrambucket"); |
639 WriteIntAttribute("min", histogram.ranges(i)); | 639 WriteIntAttribute("min", histogram.ranges(i)); |
640 WriteIntAttribute("max", histogram.ranges(i + 1)); | 640 WriteIntAttribute("max", histogram.ranges(i + 1)); |
641 WriteIntAttribute("count", snapshot.counts(i)); | 641 WriteIntAttribute("count", snapshot.counts(i)); |
642 } | 642 } |
643 } | 643 } |
644 } | 644 } |
OLD | NEW |