Chromium Code Reviews| Index: sql/connection.cc |
| diff --git a/sql/connection.cc b/sql/connection.cc |
| index 29708e41164a95376d4ae7deb392214647b04e63..c64f023253fcc01cd6397ecb5ee9857b3e60bbc9 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,31 +709,51 @@ void Connection::StatementRefDeleted(StatementRef* ref) { |
| open_statements_.erase(i); |
| } |
| +void Connection::AddSparseHistogram(const std::string& suffix, |
| + size_t sample) const { |
| + if (histogram_prefix_.empty()) |
| + return; |
| + |
| + // 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 |
| + // histogram_prefix_. |
| + std::string full_histogram_name = histogram_prefix_ + suffix; |
| + 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) { |
| + UMA_HISTOGRAM_SPARSE_SLOWLY("Sqlite.ExtendedError", err); |
| + AddSparseHistogram(".ExtendedError", err); |
| + |
| + // TODO(shess): Use of linear histograms predates existence of |
| + // sparse histograms. Remove the .Error histograms once the |
|
jar (doing other things)
2013/05/13 22:05:59
I think you can nicely get away with using the exi
Scott Hess - ex-Googler
2013/05/13 22:43:08
Done.
|
| + // .ExtendedError histograms have reached stable. |
| + |
| // 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()) { |
| + if (!histogram_prefix_.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_. |
| + std::string error_histogram_name = histogram_prefix_ + ".Error"; |
| base::HistogramBase* histogram = |
| base::LinearHistogram::FactoryGet( |
| - error_histogram_name_, 1, kSqliteErrorMax, kSqliteErrorMax + 1, |
| + error_histogram_name, 1, kSqliteErrorMax, kSqliteErrorMax + 1, |
| base::HistogramBase::kUmaTargetedHistogramFlag); |
| if (histogram) |
| histogram->Add(base_err); |