OLD | NEW |
---|---|
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" |
(...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
701 } | 701 } |
702 | 702 |
703 void Connection::StatementRefDeleted(StatementRef* ref) { | 703 void Connection::StatementRefDeleted(StatementRef* ref) { |
704 StatementRefSet::iterator i = open_statements_.find(ref); | 704 StatementRefSet::iterator i = open_statements_.find(ref); |
705 if (i == open_statements_.end()) | 705 if (i == open_statements_.end()) |
706 DLOG(FATAL) << "Could not find statement"; | 706 DLOG(FATAL) << "Could not find statement"; |
707 else | 707 else |
708 open_statements_.erase(i); | 708 open_statements_.erase(i); |
709 } | 709 } |
710 | 710 |
711 void Connection::AddLinearHistogram(const std::string& suffix, | |
jar (doing other things)
2013/05/07 23:46:41
It is also tempting to use the sparse histogram to
| |
712 size_t sample, size_t sample_max) const { | |
jar (doing other things)
2013/05/07 23:46:41
nit: one arg per line
Scott Hess - ex-Googler
2013/05/08 19:56:18
Done.
| |
713 if (!histogram_prefix_.empty()) { | |
jar (doing other things)
2013/05/07 23:46:41
nit: personal preference. Early return on empty()
Scott Hess - ex-Googler
2013/05/08 19:56:18
Done. I had pulled it out of the earlier context
| |
714 // TODO(shess): The histogram macros create a bit of static | |
715 // storage for caching the histogram object. Since SQLite is | |
716 // being used for I/O, generally without error, this code | |
717 // shouldn't execute often enough for such caching to be crucial. | |
718 // If it becomes an issue, the object could be cached alongside | |
719 // histogram_prefix_. | |
720 std::string full_histogram_name = histogram_prefix_ + suffix; | |
721 base::HistogramBase* histogram = | |
722 base::LinearHistogram::FactoryGet( | |
723 full_histogram_name, 1, sample_max, sample_max + 1, | |
724 base::HistogramBase::kUmaTargetedHistogramFlag); | |
725 if (histogram) | |
726 histogram->Add(sample); | |
727 } | |
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 // Strip extended error codes. |
713 int base_err = err&0xff; | 732 int base_err = err&0xff; |
714 | 733 |
715 static size_t kSqliteErrorMax = 50; | 734 static size_t kSqliteErrorMax = 50; |
716 UMA_HISTOGRAM_ENUMERATION("Sqlite.Error", base_err, kSqliteErrorMax); | 735 UMA_HISTOGRAM_ENUMERATION("Sqlite.Error", base_err, kSqliteErrorMax); |
717 if (base_err == SQLITE_IOERR) { | 736 if (base_err == SQLITE_IOERR) { |
718 // TODO(shess): Consider folding the IOERR range into the main | 737 // TODO(shess): Consider folding the IOERR range into the main |
719 // histogram directly. Perhaps 30..49? The downside risk would | 738 // histogram directly. Perhaps 30..49? The downside risk would |
720 // be that SQLite core adds a bunch of codes and this becomes a | 739 // be that SQLite core adds a bunch of codes and this becomes a |
721 // complicated mapping. | 740 // complicated mapping. |
722 static size_t kSqliteIOErrorMax = 20; | 741 static size_t kSqliteIOErrorMax = 20; |
723 UMA_HISTOGRAM_ENUMERATION("Sqlite.Error.IOERR", err>>8, kSqliteIOErrorMax); | 742 UMA_HISTOGRAM_ENUMERATION("Sqlite.Error.IOERR", err>>8, kSqliteIOErrorMax); |
724 } | 743 } |
725 | 744 |
726 if (!error_histogram_name_.empty()) { | 745 AddLinearHistogram(".Error", base_err, kSqliteErrorMax); |
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 | 746 |
741 // Always log the error. | 747 // Always log the error. |
742 LOG(ERROR) << "sqlite error " << err | 748 LOG(ERROR) << "sqlite error " << err |
743 << ", errno " << GetLastErrno() | 749 << ", errno " << GetLastErrno() |
744 << ": " << GetErrorMessage(); | 750 << ": " << GetErrorMessage(); |
745 | 751 |
746 if (error_delegate_.get()) | 752 if (error_delegate_.get()) |
747 return error_delegate_->OnError(err, this, stmt); | 753 return error_delegate_->OnError(err, this, stmt); |
748 | 754 |
749 // The default handling is to assert on debug and to ignore on release. | 755 // The default handling is to assert on debug and to ignore on release. |
750 DLOG(FATAL) << GetErrorMessage(); | 756 DLOG(FATAL) << GetErrorMessage(); |
751 return err; | 757 return err; |
752 } | 758 } |
753 | 759 |
754 } // namespace sql | 760 } // namespace sql |
OLD | NEW |