Skip to content

Commit bb31a75

Browse files
committed
Skip profiling of sqlite3_step
It looks like sqlite3_step can vary quite drastically from one request to the next. This seems to be caused by more or fewer calls to sqlite3VdbeSorterWrite. It would be great if we could find a way to make execution of this function more consistent, but at this point I don't know how. Closes GH-12130
1 parent 3433dab commit bb31a75

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

ext/pdo_sqlite/sqlite_statement.c

+17-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
#include "php_pdo_sqlite.h"
2727
#include "php_pdo_sqlite_int.h"
2828

29+
#ifdef HAVE_VALGRIND
30+
# include "valgrind/callgrind.h"
31+
#endif
2932

3033
static int pdo_sqlite_stmt_dtor(pdo_stmt_t *stmt)
3134
{
@@ -48,7 +51,14 @@ static int pdo_sqlite_stmt_execute(pdo_stmt_t *stmt)
4851
}
4952

5053
S->done = 0;
51-
switch (sqlite3_step(S->stmt)) {
54+
#ifdef HAVE_VALGRIND
55+
CALLGRIND_TOGGLE_COLLECT;
56+
#endif
57+
int result = sqlite3_step(S->stmt);
58+
#ifdef HAVE_VALGRIND
59+
CALLGRIND_TOGGLE_COLLECT;
60+
#endif
61+
switch (result) {
5262
case SQLITE_ROW:
5363
S->pre_fetched = 1;
5464
php_pdo_stmt_set_column_count(stmt, sqlite3_data_count(S->stmt));
@@ -214,7 +224,13 @@ static int pdo_sqlite_stmt_fetch(pdo_stmt_t *stmt,
214224
if (S->done) {
215225
return 0;
216226
}
227+
#ifdef HAVE_VALGRIND
228+
CALLGRIND_TOGGLE_COLLECT;
229+
#endif
217230
i = sqlite3_step(S->stmt);
231+
#ifdef HAVE_VALGRIND
232+
CALLGRIND_TOGGLE_COLLECT;
233+
#endif
218234
switch (i) {
219235
case SQLITE_ROW:
220236
return 1;

ext/sqlite3/sqlite3.c

+29
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
#include "SAPI.h"
3232
#include "sqlite3_arginfo.h"
3333

34+
#ifdef HAVE_VALGRIND
35+
# include "valgrind/callgrind.h"
36+
#endif
37+
3438
ZEND_DECLARE_MODULE_GLOBALS(sqlite3)
3539

3640
static PHP_GINIT_FUNCTION(sqlite3);
@@ -595,7 +599,14 @@ PHP_METHOD(SQLite3, query)
595599
result->column_count = -1;
596600
ZVAL_OBJ(&result->stmt_obj_zval, Z_OBJ(stmt));
597601

602+
603+
#ifdef HAVE_VALGRIND
604+
CALLGRIND_TOGGLE_COLLECT;
605+
#endif
598606
return_code = sqlite3_step(result->stmt_obj->stmt);
607+
#ifdef HAVE_VALGRIND
608+
CALLGRIND_TOGGLE_COLLECT;
609+
#endif
599610

600611
switch (return_code) {
601612
case SQLITE_ROW: /* Valid Row */
@@ -697,7 +708,13 @@ PHP_METHOD(SQLite3, querySingle)
697708
RETURN_FALSE;
698709
}
699710

711+
#ifdef HAVE_VALGRIND
712+
CALLGRIND_TOGGLE_COLLECT;
713+
#endif
700714
return_code = sqlite3_step(stmt);
715+
#ifdef HAVE_VALGRIND
716+
CALLGRIND_TOGGLE_COLLECT;
717+
#endif
701718

702719
switch (return_code) {
703720
case SQLITE_ROW: /* Valid Row */
@@ -1796,7 +1813,13 @@ PHP_METHOD(SQLite3Stmt, execute)
17961813
RETURN_FALSE;
17971814
}
17981815

1816+
#ifdef HAVE_VALGRIND
1817+
CALLGRIND_TOGGLE_COLLECT;
1818+
#endif
17991819
return_code = sqlite3_step(stmt_obj->stmt);
1820+
#ifdef HAVE_VALGRIND
1821+
CALLGRIND_TOGGLE_COLLECT;
1822+
#endif
18001823

18011824
switch (return_code) {
18021825
case SQLITE_ROW: /* Valid Row */
@@ -1953,7 +1976,13 @@ PHP_METHOD(SQLite3Result, fetchArray)
19531976

19541977
SQLITE3_CHECK_INITIALIZED(result_obj->db_obj, result_obj->stmt_obj->initialised, SQLite3Result)
19551978

1979+
#ifdef HAVE_VALGRIND
1980+
CALLGRIND_TOGGLE_COLLECT;
1981+
#endif
19561982
ret = sqlite3_step(result_obj->stmt_obj->stmt);
1983+
#ifdef HAVE_VALGRIND
1984+
CALLGRIND_TOGGLE_COLLECT;
1985+
#endif
19571986
switch (ret) {
19581987
case SQLITE_ROW:
19591988
/* If there was no return value then just skip fetching */

0 commit comments

Comments
 (0)