Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(400)

Side by Side Diff: sql/connection.cc

Issue 14976003: Histogram versions and extended error codes for SQLite databases. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Oops - need old histograms for continuity. Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sql/connection.h ('k') | sql/meta_table.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "sql/connection.h" 5 #include "sql/connection.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
12 #include "base/metrics/sparse_histogram.h"
12 #include "base/string_util.h" 13 #include "base/string_util.h"
13 #include "base/stringprintf.h" 14 #include "base/stringprintf.h"
14 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
15 #include "sql/statement.h" 16 #include "sql/statement.h"
16 #include "third_party/sqlite/sqlite3.h" 17 #include "third_party/sqlite/sqlite3.h"
17 18
18 namespace { 19 namespace {
19 20
20 // Spin for up to a second waiting for the lock to clear when setting 21 // Spin for up to a second waiting for the lock to clear when setting
21 // up the database. 22 // up the database.
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 } 702 }
702 703
703 void Connection::StatementRefDeleted(StatementRef* ref) { 704 void Connection::StatementRefDeleted(StatementRef* ref) {
704 StatementRefSet::iterator i = open_statements_.find(ref); 705 StatementRefSet::iterator i = open_statements_.find(ref);
705 if (i == open_statements_.end()) 706 if (i == open_statements_.end())
706 DLOG(FATAL) << "Could not find statement"; 707 DLOG(FATAL) << "Could not find statement";
707 else 708 else
708 open_statements_.erase(i); 709 open_statements_.erase(i);
709 } 710 }
710 711
712 void Connection::AddTaggedHistogram(const std::string& name,
713 size_t sample) const {
714 if (histogram_tag_.empty())
715 return;
716
717 // TODO(shess): The histogram macros create a bit of static storage
718 // for caching the histogram object. This code shouldn't execute
719 // often enough for such caching to be crucial. If it becomes an
720 // issue, the object could be cached alongside histogram_prefix_.
721 std::string full_histogram_name = name + "." + histogram_tag_;
722 base::HistogramBase* histogram =
723 base::SparseHistogram::FactoryGet(
724 full_histogram_name,
725 base::HistogramBase::kUmaTargetedHistogramFlag);
726 if (histogram)
727 histogram->Add(sample);
728 }
729
711 int Connection::OnSqliteError(int err, sql::Statement *stmt) { 730 int Connection::OnSqliteError(int err, sql::Statement *stmt) {
712 // Strip extended error codes. 731 UMA_HISTOGRAM_SPARSE_SLOWLY("Sqlite.Error", err);
713 int base_err = err&0xff; 732 AddTaggedHistogram("Sqlite.Error", err);
714
715 static size_t kSqliteErrorMax = 50;
716 UMA_HISTOGRAM_ENUMERATION("Sqlite.Error", base_err, kSqliteErrorMax);
717 if (base_err == SQLITE_IOERR) {
718 // TODO(shess): Consider folding the IOERR range into the main
719 // histogram directly. Perhaps 30..49? The downside risk would
720 // be that SQLite core adds a bunch of codes and this becomes a
721 // complicated mapping.
722 static size_t kSqliteIOErrorMax = 20;
723 UMA_HISTOGRAM_ENUMERATION("Sqlite.Error.IOERR", err>>8, kSqliteIOErrorMax);
724 }
725
726 if (!error_histogram_name_.empty()) {
727 // TODO(shess): The histogram macros create a bit of static
728 // storage for caching the histogram object. Since SQLite is
729 // being used for I/O, generally without error, this code
730 // shouldn't execute often enough for such caching to be crucial.
731 // If it becomes an issue, the object could be cached alongside
732 // error_histogram_name_.
733 base::HistogramBase* histogram =
734 base::LinearHistogram::FactoryGet(
735 error_histogram_name_, 1, kSqliteErrorMax, kSqliteErrorMax + 1,
736 base::HistogramBase::kUmaTargetedHistogramFlag);
737 if (histogram)
738 histogram->Add(base_err);
739 }
740 733
741 // Always log the error. 734 // Always log the error.
742 LOG(ERROR) << "sqlite error " << err 735 LOG(ERROR) << "sqlite error " << err
743 << ", errno " << GetLastErrno() 736 << ", errno " << GetLastErrno()
744 << ": " << GetErrorMessage(); 737 << ": " << GetErrorMessage();
745 738
746 if (error_delegate_.get()) 739 if (error_delegate_.get())
747 return error_delegate_->OnError(err, this, stmt); 740 return error_delegate_->OnError(err, this, stmt);
748 741
749 // The default handling is to assert on debug and to ignore on release. 742 // The default handling is to assert on debug and to ignore on release.
750 DLOG(FATAL) << GetErrorMessage(); 743 DLOG(FATAL) << GetErrorMessage();
751 return err; 744 return err;
752 } 745 }
753 746
754 } // namespace sql 747 } // namespace sql
OLDNEW
« no previous file with comments | « sql/connection.h ('k') | sql/meta_table.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698