diff options
author | shess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-15 09:10:39 +0000 |
---|---|---|
committer | shess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-15 09:10:39 +0000 |
commit | 210ce0afe2a62a3d902b30bec98e31606e12132c (patch) | |
tree | 94d576b989e5ecd784ce19676bfca0aef3959399 /sql | |
parent | 0b0032accd7d6b8034bfb7380b4c524ab286c412 (diff) | |
download | chromium_src-210ce0afe2a62a3d902b30bec98e31606e12132c.zip chromium_src-210ce0afe2a62a3d902b30bec98e31606e12132c.tar.gz chromium_src-210ce0afe2a62a3d902b30bec98e31606e12132c.tar.bz2 |
Histogram versions and extended error codes for SQLite databases.
Track database versions across the fleet for purposes of making
decisions about whether old migration code can be removed.
As part of this, refactor histogram code to key off a
per-database tag rather than histogram name, and to log in a
form which can be fanned out via the field trial logic in
histograms.xml
[FYI michaeln from webkit/OWNERS, erikwright from {chrome,content}/net/OWNERS, sky for chrome/browser/history/OWNERS]
BUG=none
TBR=michaeln@chromium.org, erikwright@chromium.org, sky@chromium.org
Review URL: https://chromiumcodereview.appspot.com/14976003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@200216 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sql')
-rw-r--r-- | sql/connection.cc | 49 | ||||
-rw-r--r-- | sql/connection.h | 18 | ||||
-rw-r--r-- | sql/meta_table.cc | 2 |
3 files changed, 34 insertions, 35 deletions
diff --git a/sql/connection.cc b/sql/connection.cc index 29708e4..54aeb89 100644 --- a/sql/connection.cc +++ b/sql/connection.cc @@ -9,6 +9,7 @@ #include "base/files/file_path.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/utf_string_conversions.h" @@ -708,35 +709,27 @@ 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 diff --git a/sql/connection.h b/sql/connection.h index cebc774..44b97f6 100644 --- a/sql/connection.h +++ b/sql/connection.h @@ -146,13 +146,17 @@ 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; + // 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; + // Initialization ------------------------------------------------------------ // Initializes the SQL connection for the given file, returning true if the @@ -497,8 +501,8 @@ 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_; + // Tag for auxiliary histograms. + std::string histogram_tag_; DISALLOW_COPY_AND_ASSIGN(Connection); }; diff --git a/sql/meta_table.cc b/sql/meta_table.cc index 45f4ee0..d1bf14c 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(); } |