diff options
author | Torne (Richard Coles) <torne@google.com> | 2013-05-29 14:40:03 +0100 |
---|---|---|
committer | Torne (Richard Coles) <torne@google.com> | 2013-05-29 14:40:03 +0100 |
commit | 90dce4d38c5ff5333bea97d859d4e484e27edf0c (patch) | |
tree | 9c51c7dd97d24b15befa97a3482c51851e5383a1 /sql | |
parent | 1515035f5917d10d363b0888a3615d581ad8b83f (diff) | |
download | chromium_org-90dce4d38c5ff5333bea97d859d4e484e27edf0c.tar.gz |
Merge from Chromium at DEPS revision r202854
This commit was generated by merge_to_master.py.
Change-Id: Idca323f71ef844a9e04f454d4f070b1e398f2deb
Diffstat (limited to 'sql')
-rw-r--r-- | sql/connection.cc | 90 | ||||
-rw-r--r-- | sql/connection.h | 50 | ||||
-rw-r--r-- | sql/diagnostic_error_delegate.h | 38 | ||||
-rw-r--r-- | sql/error_delegate_util.h | 23 | ||||
-rw-r--r-- | sql/meta_table.cc | 2 | ||||
-rw-r--r-- | sql/sql.gyp | 1 | ||||
-rw-r--r-- | sql/sql.target.darwin-arm.mk | 7 | ||||
-rw-r--r-- | sql/sql.target.darwin-x86.mk | 7 | ||||
-rw-r--r-- | sql/sql.target.linux-arm.mk | 7 | ||||
-rw-r--r-- | sql/sql.target.linux-x86.mk | 7 |
10 files changed, 123 insertions, 109 deletions
diff --git a/sql/connection.cc b/sql/connection.cc index 29708e4116..09d8195df5 100644 --- a/sql/connection.cc +++ b/sql/connection.cc @@ -7,10 +7,13 @@ #include <string.h> #include "base/files/file_path.h" +#include "base/file_util.h" #include "base/logging.h" #include "base/metrics/histogram.h" +#include "base/metrics/sparse_histogram.h" #include "base/string_util.h" #include "base/stringprintf.h" +#include "base/strings/string_split.h" #include "base/utf_string_conversions.h" #include "sql/statement.h" #include "third_party/sqlite/sqlite3.h" @@ -128,6 +131,20 @@ Connection::~Connection() { } bool Connection::Open(const base::FilePath& path) { + if (!histogram_tag_.empty()) { + int64 size_64 = 0; + if (file_util::GetFileSize(path, &size_64)) { + size_t sample = static_cast<size_t>(size_64 / 1024); + std::string full_histogram_name = "Sqlite.SizeKB." + histogram_tag_; + base::HistogramBase* histogram = + base::Histogram::FactoryGet( + full_histogram_name, 1, 1000000, 50, + base::HistogramBase::kUmaTargetedHistogramFlag); + if (histogram) + histogram->Add(sample); + } + } + #if defined(OS_WIN) return OpenInternal(WideToUTF8(path.value())); #elif defined(OS_POSIX) @@ -708,41 +725,40 @@ void Connection::StatementRefDeleted(StatementRef* ref) { open_statements_.erase(i); } +void Connection::AddTaggedHistogram(const std::string& name, + size_t sample) const { + if (histogram_tag_.empty()) + return; + + // TODO(shess): The histogram macros create a bit of static storage + // for caching the histogram object. This code shouldn't execute + // often enough for such caching to be crucial. If it becomes an + // issue, the object could be cached alongside histogram_prefix_. + std::string full_histogram_name = name + "." + histogram_tag_; + base::HistogramBase* histogram = + base::SparseHistogram::FactoryGet( + full_histogram_name, + base::HistogramBase::kUmaTargetedHistogramFlag); + if (histogram) + histogram->Add(sample); +} + 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 (base_err == SQLITE_IOERR) { - // TODO(shess): Consider folding the IOERR range into the main - // histogram directly. Perhaps 30..49? The downside risk would - // be that SQLite core adds a bunch of codes and this becomes a - // complicated mapping. - static size_t kSqliteIOErrorMax = 20; - UMA_HISTOGRAM_ENUMERATION("Sqlite.Error.IOERR", err>>8, kSqliteIOErrorMax); - } - - 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::HistogramBase* histogram = - base::LinearHistogram::FactoryGet( - error_histogram_name_, 1, kSqliteErrorMax, kSqliteErrorMax + 1, - base::HistogramBase::kUmaTargetedHistogramFlag); - if (histogram) - histogram->Add(base_err); - } + UMA_HISTOGRAM_SPARSE_SLOWLY("Sqlite.Error", err); + AddTaggedHistogram("Sqlite.Error", err); // Always log the error. LOG(ERROR) << "sqlite error " << err << ", errno " << GetLastErrno() << ": " << GetErrorMessage(); + if (!error_callback_.is_null()) { + error_callback_.Run(err, stmt); + return err; + } + + // TODO(shess): Remove |error_delegate_| once everything is + // converted to |error_callback_|. if (error_delegate_.get()) return error_delegate_->OnError(err, this, stmt); @@ -751,4 +767,22 @@ int Connection::OnSqliteError(int err, sql::Statement *stmt) { return err; } +// TODO(shess): Allow specifying integrity_check versus quick_check. +// TODO(shess): Allow specifying maximum results (default 100 lines). +bool Connection::IntegrityCheck(std::vector<std::string>* messages) { + const char kSql[] = "PRAGMA integrity_check"; + sql::Statement stmt(GetUniqueStatement(kSql)); + + messages->clear(); + + // The pragma appears to return all results (up to 100 by default) + // as a single string. This doesn't appear to be an API contract, + // it could return separate lines, so loop _and_ split. + while (stmt.Step()) { + std::string result(stmt.ColumnString(0)); + base::SplitString(result, '\n', messages); + } + return stmt.Succeeded(); +} + } // namespace sql diff --git a/sql/connection.h b/sql/connection.h index cebc774fa5..049d7cf5b4 100644 --- a/sql/connection.h +++ b/sql/connection.h @@ -8,8 +8,10 @@ #include <map> #include <set> #include <string> +#include <vector> #include "base/basictypes.h" +#include "base/callback.h" #include "base/compiler_specific.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" @@ -138,21 +140,53 @@ class SQL_EXPORT Connection { // This must be called before Open() to have an effect. void set_exclusive_locking() { exclusive_locking_ = true; } + // Set an error-handling callback. On errors, the error number (and + // statement, if available) will be passed to the callback. + // + // If no callback is set, the default action is to crash in debug + // mode or return failure in release mode. + // + // TODO(shess): ErrorDelegate allowed for returning a different + // error. Determine if this is necessary for the callback. In my + // experience, this is not well-tested and probably not safe, and + // current clients always return the same error passed. + // Additionally, most errors don't admit to a clean way to retry the + // failed operation, so converting an error to SQLITE_OK is probably + // not feasible. + typedef base::Callback<void(int, Statement*)> ErrorCallback; + void set_error_callback(const ErrorCallback& callback) { + error_callback_ = callback; + } + void reset_error_callback() { + error_callback_.Reset(); + } + // Sets the object that will handle errors. Recomended that it should be set // before calling Open(). If not set, the default is to ignore errors on // release and assert on debug builds. // Takes ownership of |delegate|. + // NOTE(shess): Deprecated, use set_error_callback(). void set_error_delegate(ErrorDelegate* delegate) { 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; + // Set this tag to enable additional connection-type histogramming + // for SQLite error codes and database version numbers. + void set_histogram_tag(const std::string& tag) { + histogram_tag_ = tag; } + // Record a sparse UMA histogram sample under + // |name|+"."+|histogram_tag_|. If |histogram_tag_| is empty, no + // histogram is recorded. + void AddTaggedHistogram(const std::string& name, size_t sample) const; + + // Run "PRAGMA integrity_check" and post each line of results into + // |messages|. Returns the success of running the statement - per + // the SQLite documentation, if no errors are found the call should + // succeed, and a single value "ok" should be in messages. + bool IntegrityCheck(std::vector<std::string>* messages); + // Initialization ------------------------------------------------------------ // Initializes the SQL connection for the given file, returning true if the @@ -493,12 +527,14 @@ class SQL_EXPORT Connection { // databases. bool poisoned_; + ErrorCallback error_callback_; + // This object handles errors resulting from all forms of executing sqlite // 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_; + // Tag for auxiliary histograms. + std::string histogram_tag_; DISALLOW_COPY_AND_ASSIGN(Connection); }; diff --git a/sql/diagnostic_error_delegate.h b/sql/diagnostic_error_delegate.h deleted file mode 100644 index 78b3d9d815..0000000000 --- a/sql/diagnostic_error_delegate.h +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef SQL_DIAGNOSTIC_ERROR_DELEGATE_H_ -#define SQL_DIAGNOSTIC_ERROR_DELEGATE_H_ - -#include "base/logging.h" -#include "sql/connection.h" -#include "sql/error_delegate_util.h" -#include "sql/sql_export.h" - -namespace sql { - -// This class handles the exceptional sqlite errors that we might encounter -// if for example the db is corrupted. Right now we just generate a UMA -// histogram for release and an assert for debug builds. -// See error_delegate_util.h for an explanation as to why this class is a -// template. -template <class UniqueT> -class DiagnosticErrorDelegate : public ErrorDelegate { - public: - DiagnosticErrorDelegate() {} - virtual ~DiagnosticErrorDelegate() {} - - virtual int OnError(int error, Connection* connection, - Statement* stmt) { - LogAndRecordErrorInHistogram<UniqueT>(error, connection); - return error; - } - - private: - DISALLOW_COPY_AND_ASSIGN(DiagnosticErrorDelegate); -}; - -} // namespace sql - -#endif // SQL_DIAGNOSTIC_ERROR_DELEGATE_H_ diff --git a/sql/error_delegate_util.h b/sql/error_delegate_util.h index 6b90ccf8b4..0c67c07ec7 100644 --- a/sql/error_delegate_util.h +++ b/sql/error_delegate_util.h @@ -5,8 +5,6 @@ #ifndef SQL_ERROR_DELEGATE_UTIL_H_ #define SQL_ERROR_DELEGATE_UTIL_H_ -#include "base/metrics/histogram.h" -#include "sql/connection.h" #include "sql/sql_export.h" namespace sql { @@ -15,27 +13,6 @@ namespace sql { // |error|. SQL_EXPORT bool IsErrorCatastrophic(int error); -// Log error in console in debug mode and generate a UMA histogram in release -// mode for |error| for |UniqueT::name()|. -// This function is templated because histograms need to be singletons. That is -// why they are always static at the function scope. The template parameter -// makes the compiler create unique functions that don't share the same static -// variable. -template <class UniqueT> -void LogAndRecordErrorInHistogram(int error, - sql::Connection* connection) { - LOG(ERROR) << "sqlite error " << error - << ", errno " << connection->GetLastErrno() - << ": " << connection->GetErrorMessage(); - - // Trim off the extended error codes. - error &= 0xff; - - // The histogram values from sqlite result codes currently go from 1 to 26 - // but 50 gives them room to grow. - UMA_HISTOGRAM_ENUMERATION(UniqueT::name(), error, 50); -} - } // namespace sql #endif // SQL_ERROR_DELEGATE_UTIL_H_ diff --git a/sql/meta_table.cc b/sql/meta_table.cc index 45f4ee09db..d1bf14c70d 100644 --- a/sql/meta_table.cc +++ b/sql/meta_table.cc @@ -52,6 +52,8 @@ bool MetaTable::Init(Connection* db, int version, int compatible_version) { // there, we should create an index. SetVersionNumber(version); SetCompatibleVersionNumber(compatible_version); + } else { + db_->AddTaggedHistogram("Sqlite.Version", GetVersionNumber()); } return transaction.Commit(); } diff --git a/sql/sql.gyp b/sql/sql.gyp index 0d8f8be967..86cfbc9160 100644 --- a/sql/sql.gyp +++ b/sql/sql.gyp @@ -18,7 +18,6 @@ 'sources': [ 'connection.cc', 'connection.h', - 'diagnostic_error_delegate.h', 'error_delegate_util.cc', 'error_delegate_util.h', 'init_status.h', diff --git a/sql/sql.target.darwin-arm.mk b/sql/sql.target.darwin-arm.mk index 94855306eb..7f89750ab1 100644 --- a/sql/sql.target.darwin-arm.mk +++ b/sql/sql.target.darwin-arm.mk @@ -71,6 +71,7 @@ MY_DEFS := \ '-DNO_TCMALLOC' \ '-DDISABLE_NACL' \ '-DCHROMIUM_BUILD' \ + '-DENABLE_DOUBLE_RESOURCE_LOAD_TIMING' \ '-DUSE_LIBJPEG_TURBO=1' \ '-DUSE_PROPRIETARY_CODECS' \ '-DENABLE_GPU=1' \ @@ -98,9 +99,9 @@ LOCAL_C_INCLUDES := \ $(gyp_shared_intermediate_dir)/shim_headers/icuuc/target \ $(LOCAL_PATH) \ $(LOCAL_PATH)/third_party/sqlite \ - $(GYP_ABS_ANDROID_TOP_DIR)/frameworks/wilhelm/include \ - $(GYP_ABS_ANDROID_TOP_DIR)/bionic \ - $(GYP_ABS_ANDROID_TOP_DIR)/external/stlport/stlport + $(PWD)/frameworks/wilhelm/include \ + $(PWD)/bionic \ + $(PWD)/external/stlport/stlport LOCAL_C_INCLUDES := $(GYP_COPIED_SOURCE_ORIGIN_DIRS) $(LOCAL_C_INCLUDES) diff --git a/sql/sql.target.darwin-x86.mk b/sql/sql.target.darwin-x86.mk index b6fe163a38..108a4f4db7 100644 --- a/sql/sql.target.darwin-x86.mk +++ b/sql/sql.target.darwin-x86.mk @@ -73,6 +73,7 @@ MY_DEFS := \ '-DNO_TCMALLOC' \ '-DDISABLE_NACL' \ '-DCHROMIUM_BUILD' \ + '-DENABLE_DOUBLE_RESOURCE_LOAD_TIMING' \ '-DUSE_LIBJPEG_TURBO=1' \ '-DUSE_PROPRIETARY_CODECS' \ '-DENABLE_GPU=1' \ @@ -100,9 +101,9 @@ LOCAL_C_INCLUDES := \ $(gyp_shared_intermediate_dir)/shim_headers/icuuc/target \ $(LOCAL_PATH) \ $(LOCAL_PATH)/third_party/sqlite \ - $(GYP_ABS_ANDROID_TOP_DIR)/frameworks/wilhelm/include \ - $(GYP_ABS_ANDROID_TOP_DIR)/bionic \ - $(GYP_ABS_ANDROID_TOP_DIR)/external/stlport/stlport + $(PWD)/frameworks/wilhelm/include \ + $(PWD)/bionic \ + $(PWD)/external/stlport/stlport LOCAL_C_INCLUDES := $(GYP_COPIED_SOURCE_ORIGIN_DIRS) $(LOCAL_C_INCLUDES) diff --git a/sql/sql.target.linux-arm.mk b/sql/sql.target.linux-arm.mk index 94855306eb..7f89750ab1 100644 --- a/sql/sql.target.linux-arm.mk +++ b/sql/sql.target.linux-arm.mk @@ -71,6 +71,7 @@ MY_DEFS := \ '-DNO_TCMALLOC' \ '-DDISABLE_NACL' \ '-DCHROMIUM_BUILD' \ + '-DENABLE_DOUBLE_RESOURCE_LOAD_TIMING' \ '-DUSE_LIBJPEG_TURBO=1' \ '-DUSE_PROPRIETARY_CODECS' \ '-DENABLE_GPU=1' \ @@ -98,9 +99,9 @@ LOCAL_C_INCLUDES := \ $(gyp_shared_intermediate_dir)/shim_headers/icuuc/target \ $(LOCAL_PATH) \ $(LOCAL_PATH)/third_party/sqlite \ - $(GYP_ABS_ANDROID_TOP_DIR)/frameworks/wilhelm/include \ - $(GYP_ABS_ANDROID_TOP_DIR)/bionic \ - $(GYP_ABS_ANDROID_TOP_DIR)/external/stlport/stlport + $(PWD)/frameworks/wilhelm/include \ + $(PWD)/bionic \ + $(PWD)/external/stlport/stlport LOCAL_C_INCLUDES := $(GYP_COPIED_SOURCE_ORIGIN_DIRS) $(LOCAL_C_INCLUDES) diff --git a/sql/sql.target.linux-x86.mk b/sql/sql.target.linux-x86.mk index b6fe163a38..108a4f4db7 100644 --- a/sql/sql.target.linux-x86.mk +++ b/sql/sql.target.linux-x86.mk @@ -73,6 +73,7 @@ MY_DEFS := \ '-DNO_TCMALLOC' \ '-DDISABLE_NACL' \ '-DCHROMIUM_BUILD' \ + '-DENABLE_DOUBLE_RESOURCE_LOAD_TIMING' \ '-DUSE_LIBJPEG_TURBO=1' \ '-DUSE_PROPRIETARY_CODECS' \ '-DENABLE_GPU=1' \ @@ -100,9 +101,9 @@ LOCAL_C_INCLUDES := \ $(gyp_shared_intermediate_dir)/shim_headers/icuuc/target \ $(LOCAL_PATH) \ $(LOCAL_PATH)/third_party/sqlite \ - $(GYP_ABS_ANDROID_TOP_DIR)/frameworks/wilhelm/include \ - $(GYP_ABS_ANDROID_TOP_DIR)/bionic \ - $(GYP_ABS_ANDROID_TOP_DIR)/external/stlport/stlport + $(PWD)/frameworks/wilhelm/include \ + $(PWD)/bionic \ + $(PWD)/external/stlport/stlport LOCAL_C_INCLUDES := $(GYP_COPIED_SOURCE_ORIGIN_DIRS) $(LOCAL_C_INCLUDES) |