Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: chrome/common/metrics/metrics_log_manager.cc

Issue 81603002: Send UMA stability stats in a separate UMA log on startup. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/common/metrics/metrics_log_manager.h" 5 #include "chrome/common/metrics/metrics_log_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/sha1.h" 10 #include "base/sha1.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "base/timer/elapsed_timer.h"
12 #include "chrome/common/metrics/metrics_log_base.h" 13 #include "chrome/common/metrics/metrics_log_base.h"
13 14
14 MetricsLogManager::SerializedLog::SerializedLog() {} 15 MetricsLogManager::SerializedLog::SerializedLog() {}
15 MetricsLogManager::SerializedLog::~SerializedLog() {} 16 MetricsLogManager::SerializedLog::~SerializedLog() {}
16 17
17 bool MetricsLogManager::SerializedLog::IsEmpty() const { 18 bool MetricsLogManager::SerializedLog::IsEmpty() const {
18 return log_text_.empty(); 19 return log_text_.empty();
19 } 20 }
20 21
21 void MetricsLogManager::SerializedLog::SwapLogText(std::string* log_text) { 22 void MetricsLogManager::SerializedLog::SwapLogText(std::string* log_text) {
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 DCHECK_LT(static_cast<unsigned int>(last_provisional_store_index_), 161 DCHECK_LT(static_cast<unsigned int>(last_provisional_store_index_),
161 source_list->size()); 162 source_list->size());
162 source_list->erase(source_list->begin() + last_provisional_store_index_); 163 source_list->erase(source_list->begin() + last_provisional_store_index_);
163 last_provisional_store_index_ = -1; 164 last_provisional_store_index_ = -1;
164 } 165 }
165 166
166 void MetricsLogManager::PersistUnsentLogs() { 167 void MetricsLogManager::PersistUnsentLogs() {
167 DCHECK(log_serializer_.get()); 168 DCHECK(log_serializer_.get());
168 if (!log_serializer_.get()) 169 if (!log_serializer_.get())
169 return; 170 return;
171 base::ElapsedTimer timer;
170 // Remove any ongoing logs that are over the serialization size limit. 172 // Remove any ongoing logs that are over the serialization size limit.
171 if (max_ongoing_log_store_size_) { 173 if (max_ongoing_log_store_size_) {
172 for (std::vector<SerializedLog>::iterator it = unsent_ongoing_logs_.begin(); 174 for (std::vector<SerializedLog>::iterator it = unsent_ongoing_logs_.begin();
173 it != unsent_ongoing_logs_.end();) { 175 it != unsent_ongoing_logs_.end();) {
174 size_t log_size = it->log_text().length(); 176 size_t log_size = it->log_text().length();
175 if (log_size > max_ongoing_log_store_size_) { 177 if (log_size > max_ongoing_log_store_size_) {
176 UMA_HISTOGRAM_COUNTS("UMA.Large Accumulated Log Not Persisted", 178 UMA_HISTOGRAM_COUNTS("UMA.Large Accumulated Log Not Persisted",
177 static_cast<int>(log_size)); 179 static_cast<int>(log_size));
178 it = unsent_ongoing_logs_.erase(it); 180 it = unsent_ongoing_logs_.erase(it);
179 } else { 181 } else {
180 ++it; 182 ++it;
181 } 183 }
182 } 184 }
183 } 185 }
184 log_serializer_->SerializeLogs(unsent_initial_logs_, 186 log_serializer_->SerializeLogs(unsent_initial_logs_,
185 MetricsLogBase::INITIAL_LOG); 187 MetricsLogBase::INITIAL_LOG);
186 log_serializer_->SerializeLogs(unsent_ongoing_logs_, 188 log_serializer_->SerializeLogs(unsent_ongoing_logs_,
187 MetricsLogBase::ONGOING_LOG); 189 MetricsLogBase::ONGOING_LOG);
190 UMA_HISTOGRAM_TIMES("UMA.StoreLogsTime", timer.Elapsed());
188 } 191 }
189 192
190 void MetricsLogManager::LoadPersistedUnsentLogs() { 193 void MetricsLogManager::LoadPersistedUnsentLogs() {
191 DCHECK(log_serializer_.get()); 194 DCHECK(log_serializer_.get());
192 if (!log_serializer_.get()) 195 if (!log_serializer_.get())
193 return; 196 return;
197 base::ElapsedTimer timer;
194 log_serializer_->DeserializeLogs(MetricsLogBase::INITIAL_LOG, 198 log_serializer_->DeserializeLogs(MetricsLogBase::INITIAL_LOG,
195 &unsent_initial_logs_); 199 &unsent_initial_logs_);
196 log_serializer_->DeserializeLogs(MetricsLogBase::ONGOING_LOG, 200 log_serializer_->DeserializeLogs(MetricsLogBase::ONGOING_LOG,
197 &unsent_ongoing_logs_); 201 &unsent_ongoing_logs_);
202 UMA_HISTOGRAM_TIMES("UMA.LoadLogsTime", timer.Elapsed());
198 } 203 }
199 204
200 void MetricsLogManager::CompressCurrentLog(SerializedLog* compressed_log) { 205 void MetricsLogManager::CompressCurrentLog(SerializedLog* compressed_log) {
201 std::string log_text; 206 std::string log_text;
202 current_log_->GetEncodedLog(&log_text); 207 current_log_->GetEncodedLog(&log_text);
203 compressed_log->SwapLogText(&log_text); 208 compressed_log->SwapLogText(&log_text);
204 } 209 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698