diff options
Diffstat (limited to 'sql')
-rw-r--r-- | sql/connection.cc | 26 | ||||
-rw-r--r-- | sql/connection.h | 10 |
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); }; |