summaryrefslogtreecommitdiffstats
path: root/sql/statement.cc
diff options
context:
space:
mode:
authorshess <shess@chromium.org>2015-06-02 17:19:32 -0700
committerCommit bot <commit-bot@chromium.org>2015-06-03 00:19:59 +0000
commit58b8df8572e25ff91b3073213651aed4ebd675b5 (patch)
tree8e92bdbc754f347c05515489799fc798baa17e19 /sql/statement.cc
parented09d907684cb6209090cf9dcbad91bfc2b11f56 (diff)
downloadchromium_src-58b8df8572e25ff91b3073213651aed4ebd675b5.zip
chromium_src-58b8df8572e25ff91b3073213651aed4ebd675b5.tar.gz
chromium_src-58b8df8572e25ff91b3073213651aed4ebd675b5.tar.bz2
[sql] Stats gathering for sql/ APIs.
Generate stats for how many SQL statements are executed, how many results they return, and how many changes they make. Generate timing values for how long is spent doing all queries, doing updating operations, doing autocommit updates, and commiting transactions. The goal of these metrics is to quantify results of decisions like enabling write-ahead log or memory-mapped I/O. BUG=489788,489444 Review URL: https://codereview.chromium.org/1145833002 Cr-Commit-Position: refs/heads/master@{#332503}
Diffstat (limited to 'sql/statement.cc')
-rw-r--r--sql/statement.cc57
1 files changed, 43 insertions, 14 deletions
diff --git a/sql/statement.cc b/sql/statement.cc
index 42b4598..038ebde 100644
--- a/sql/statement.cc
+++ b/sql/statement.cc
@@ -51,34 +51,63 @@ bool Statement::CheckValid() const {
return is_valid();
}
-bool Statement::Run() {
- DCHECK(!stepped_);
+int Statement::StepInternal(bool timer_flag) {
ref_->AssertIOAllowed();
if (!CheckValid())
- return false;
+ return SQLITE_ERROR;
+ const bool was_stepped = stepped_;
stepped_ = true;
- return CheckError(sqlite3_step(ref_->stmt())) == SQLITE_DONE;
+ int ret = SQLITE_ERROR;
+ if (!ref_->connection()) {
+ ret = sqlite3_step(ref_->stmt());
+ } else {
+ if (!timer_flag) {
+ ret = sqlite3_step(ref_->stmt());
+ } else {
+ const base::TimeTicks before = ref_->connection()->Now();
+ ret = sqlite3_step(ref_->stmt());
+ const base::TimeTicks after = ref_->connection()->Now();
+ const bool read_only = !!sqlite3_stmt_readonly(ref_->stmt());
+ ref_->connection()->RecordTimeAndChanges(after - before, read_only);
+ }
+
+ if (!was_stepped)
+ ref_->connection()->RecordOneEvent(Connection::EVENT_STATEMENT_RUN);
+
+ if (ret == SQLITE_ROW)
+ ref_->connection()->RecordOneEvent(Connection::EVENT_STATEMENT_ROWS);
+ }
+ return CheckError(ret);
}
-bool Statement::Step() {
- ref_->AssertIOAllowed();
- if (!CheckValid())
- return false;
+bool Statement::Run() {
+ DCHECK(!stepped_);
+ return StepInternal(true) == SQLITE_DONE;
+}
- stepped_ = true;
- return CheckError(sqlite3_step(ref_->stmt())) == SQLITE_ROW;
+bool Statement::RunWithoutTimers() {
+ DCHECK(!stepped_);
+ return StepInternal(false) == SQLITE_DONE;
+}
+
+bool Statement::Step() {
+ return StepInternal(true) == SQLITE_ROW;
}
void Statement::Reset(bool clear_bound_vars) {
ref_->AssertIOAllowed();
if (is_valid()) {
- // We don't call CheckError() here because sqlite3_reset() returns
- // the last error that Step() caused thereby generating a second
- // spurious error callback.
if (clear_bound_vars)
sqlite3_clear_bindings(ref_->stmt());
- sqlite3_reset(ref_->stmt());
+
+ // StepInternal() cannot track success because statements may be reset
+ // before reaching SQLITE_DONE. Don't call CheckError() because
+ // sqlite3_reset() returns the last step error, which StepInternal() already
+ // checked.
+ const int rc =sqlite3_reset(ref_->stmt());
+ if (rc == SQLITE_OK && ref_->connection())
+ ref_->connection()->RecordOneEvent(Connection::EVENT_STATEMENT_SUCCESS);
}
succeeded_ = false;