summaryrefslogtreecommitdiffstats
path: root/sql/connection.cc
diff options
context:
space:
mode:
authorshess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-03 23:59:14 +0000
committershess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-03 23:59:14 +0000
commitc088e3a35dcb52d62255f97307960b8ad3aaffa7 (patch)
tree4b8638a366467cbaa4915575ed47fd72b5d8a2a6 /sql/connection.cc
parent8d469a234bbc0e1b59fb4d5315be697069f780c1 (diff)
downloadchromium_src-c088e3a35dcb52d62255f97307960b8ad3aaffa7.zip
chromium_src-c088e3a35dcb52d62255f97307960b8ad3aaffa7.tar.gz
chromium_src-c088e3a35dcb52d62255f97307960b8ad3aaffa7.tar.bz2
Bake targeted error histogram support directly into sql::Connection.
Previously there was a convoluted template system to unique histogram names for purposes of tracking database errors separately. This was needed due to the static cache used by the histogram macros. Instead, just log the histogram manually without using a static cache. Additionally, pull the histogram functionality right up into the connection, rather than requiring formalized delegation to get it. BUG=none Review URL: https://chromiumcodereview.appspot.com/11474030 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@175055 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sql/connection.cc')
-rw-r--r--sql/connection.cc26
1 files changed, 26 insertions, 0 deletions
diff --git a/sql/connection.cc b/sql/connection.cc
index 99bc381..e7fa87c 100644
--- a/sql/connection.cc
+++ b/sql/connection.cc
@@ -653,8 +653,34 @@ void Connection::ClearCache() {
}
int Connection::OnSqliteError(int err, sql::Statement *stmt) {
+ // Strip extended error codes.
+ int base_err = err&0xff;
+
+ static size_t kSqliteErrorMax = 50;
+ UMA_HISTOGRAM_ENUMERATION("Sqlite.Error", base_err, kSqliteErrorMax);
+ if (!error_histogram_name_.empty()) {
+ // TODO(shess): The histogram macros create a bit of static
+ // storage for caching the histogram object. Since SQLite is
+ // being used for I/O, generally without error, this code
+ // shouldn't execute often enough for such caching to be crucial.
+ // If it becomes an issue, the object could be cached alongside
+ // error_histogram_name_.
+ base::Histogram* histogram =
+ base::LinearHistogram::FactoryGet(
+ error_histogram_name_, 1, kSqliteErrorMax, kSqliteErrorMax + 1,
+ base::Histogram::kUmaTargetedHistogramFlag);
+ if (histogram)
+ histogram->Add(base_err);
+ }
+
+ // Always log the error.
+ LOG(ERROR) << "sqlite error " << err
+ << ", errno " << GetLastErrno()
+ << ": " << GetErrorMessage();
+
if (error_delegate_.get())
return error_delegate_->OnError(err, this, stmt);
+
// The default handling is to assert on debug and to ignore on release.
DLOG(FATAL) << GetErrorMessage();
return err;