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

Unified Diff: sql/connection.h

Issue 1145833002: [sql] Stats gathering for sql/ APIs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix build breaks. BUILD.gn needs to follow sql.gyp, tracker had histogram tag set after open, EVEN… Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sql/BUILD.gn ('k') | sql/connection.cc » ('j') | sql/connection.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sql/connection.h
diff --git a/sql/connection.h b/sql/connection.h
index 17d11914ae082ad3cfc7effb8cb4e9dbb2268c69..e969f8d68fed968d2f7a70734f935426bb2cc412 100644
--- a/sql/connection.h
+++ b/sql/connection.h
@@ -25,6 +25,7 @@ struct sqlite3_stmt;
namespace base {
class FilePath;
+class HistogramBase;
}
namespace sql {
@@ -32,6 +33,12 @@ namespace sql {
class Recovery;
class Statement;
+// To allow some test classes to be friended.
+namespace test {
+class ScopedScalarFunction;
+class ScopedCommitHook;
+}
rmcilroy 2015/05/21 22:54:48 AFAIK friended classes don't need to be declared (
Scott Hess - ex-Googler 2015/05/21 23:42:37 "no class named ..." error. It may be because of
rmcilroy 2015/05/22 08:48:23 Interesting, good to know.
+
// Uniquely identifies a statement. There are two modes of operation:
//
// - In the most common mode, you will use the source file and line number to
@@ -140,17 +147,50 @@ class SQL_EXPORT Connection {
error_callback_.Reset();
}
- // 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;
- }
+ // Set this to enable additional per-connection histogramming. Must be called
+ // before Open().
+ void set_histogram_tag(const std::string& 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;
+ // Track various API calls and results.
+ enum Events {
+ // Number of statements run, either with sql::Statement or Execute*().
+ EVENT_STATEMENT_RUN = 0,
+
+ // Number of rows returned by statements run.
+ EVENT_STATEMENT_ROWS,
+
+ // Number of statements successfully run (all steps returned SQLITE_DONE or
+ // SQLITE_ROW).
+ EVENT_STATEMENT_SUCCESS,
+
+ // Number of statements run by Execute() or ExecuteAndReturnErrorCode().
+ EVENT_EXECUTE,
+
+ // Number of rows changed by autocommit statements.
+ EVENT_CHANGES_AUTOCOMMIT,
+
+ // Number of rows changed by statements in transactions.
+ EVENT_CHANGES,
+
+ // Count actual SQLite transaction statements (not including nesting).
+ EVENT_BEGIN,
+ EVENT_COMMIT,
+ EVENT_ROLLBACK,
+
+ // Leave this at the end.
+ // TODO(shess): |EVENT_MAX| causes compile fail on Windows.
+ EVENT_MX
+ };
+ void RecordEvent(Events event, size_t count);
+ void RecordOneEvent(Events event) {
+ RecordEvent(event, 1);
+ }
+
// 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
@@ -415,6 +455,9 @@ class SQL_EXPORT Connection {
// (they should go through Statement).
friend class Statement;
+ friend class test::ScopedScalarFunction;
+ friend class test::ScopedCommitHook;
+
// Internal initialize function used by both Init and InitInMemory. The file
// name is always 8 bits since we want to use the 8-bit version of
// sqlite3_open. The string can also be sqlite's special ":memory:" string.
@@ -548,6 +591,30 @@ class SQL_EXPORT Connection {
const char* pragma_sql,
std::vector<std::string>* messages) WARN_UNUSED_RESULT;
+ // Record time spent executing explicit COMMIT statements.
+ void CommitTime(const base::TimeDelta& delta);
rmcilroy 2015/05/21 22:54:48 I think it would be clearer with "Record" prefixed
Scott Hess - ex-Googler 2015/05/21 23:42:37 Done.
+
+ // Record time in DML (Data Manipulation Language) statements such as INSERT
+ // or UPDATE outside of an explicit transaction. Due to implementation
+ // limitations time spent on DDL (Data Definition Language) statements such as
+ // ALTER and CREATE is not included.
+ void AutoCommitTime(const base::TimeDelta& delta);
+
+ // Record all time spent on updating the database. This includes CommitTime()
+ // and AutoCommitTime(), plus any time spent spilling to the journal if
+ // transactions do not fit in cache.
+ void UpdateTime(const base::TimeDelta& delta);
+
+ // Record all time spent running statements, including time spent doing
+ // updates and time spent on read-only queries.
+ void QueryTime(const base::TimeDelta& delta);
+
+ // Record |delta| as query time if |read_only| (from sqlite3_stmt_readonly) is
+ // true, autocommit time if the database is not in a transaction, or update
+ // time if the database is in a transaction. Also records change count to
+ // EVENT_CHANGES_AUTOCOMMIT or EVENT_CHANGES_COMMIT.
+ void ChangeHelper(const base::TimeDelta& delta, bool read_only);
rmcilroy 2015/05/21 22:54:48 nit - maybe RecordTimeAndChangesHelper?
Scott Hess - ex-Googler 2015/05/21 23:42:37 Went with RecordTimeAndChanges(), helper seems red
rmcilroy 2015/05/22 08:48:23 SGTM!
+
// The actual sqlite database. Will be NULL before Init has been called or if
// Init resulted in an error.
sqlite3* db_;
@@ -594,6 +661,22 @@ class SQL_EXPORT Connection {
// Tag for auxiliary histograms.
std::string histogram_tag_;
+ // Linear histogram for RecordEvent().
+ base::HistogramBase* stats_histogram_;
+
+ // Histogram for tracking time taken in commit.
+ base::HistogramBase* commit_time_histogram_;
+
+ // Histogram for tracking time taken in autocommit updates.
+ base::HistogramBase* autocommit_time_histogram_;
+
+ // Histogram for tracking time taken in updates (including commit and
+ // autocommit).
+ base::HistogramBase* update_time_histogram_;
+
+ // Histogram for tracking time taken in all queries.
+ base::HistogramBase* query_time_histogram_;
+
DISALLOW_COPY_AND_ASSIGN(Connection);
};
« no previous file with comments | « sql/BUILD.gn ('k') | sql/connection.cc » ('j') | sql/connection.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698