summaryrefslogtreecommitdiffstats
path: root/sql
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
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')
-rw-r--r--sql/connection.cc26
-rw-r--r--sql/connection.h10
2 files changed, 36 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;
diff --git a/sql/connection.h b/sql/connection.h
index 8cf4d71..b9f45ec 100644
--- a/sql/connection.h
+++ b/sql/connection.h
@@ -143,6 +143,13 @@ class SQL_EXPORT Connection {
error_delegate_.reset(delegate);
}
+ // SQLite error codes for errors on all connections are logged to
+ // enum histogram "Sqlite.Error". Setting this additionally logs
+ // errors to the histogram |name|.
+ void set_error_histogram_name(const std::string& name) {
+ error_histogram_name_ = name;
+ }
+
// Initialization ------------------------------------------------------------
// Initializes the SQL connection for the given file, returning true if the
@@ -457,6 +464,9 @@ class SQL_EXPORT Connection {
// commands or statements. It can be null which means default handling.
scoped_ptr<ErrorDelegate> error_delegate_;
+ // Auxiliary error-code histogram.
+ std::string error_histogram_name_;
+
DISALLOW_COPY_AND_ASSIGN(Connection);
};