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
This commit is contained in:
Ilija Tovilo 2023-09-05 13:05:21 +02:00
parent 3433dab5f7
commit bb31a75321
No known key found for this signature in database
GPG key ID: A4F5D403F118200A
2 changed files with 46 additions and 1 deletions

View file

@ -26,6 +26,9 @@
#include "php_pdo_sqlite.h"
#include "php_pdo_sqlite_int.h"
#ifdef HAVE_VALGRIND
# include "valgrind/callgrind.h"
#endif
static int pdo_sqlite_stmt_dtor(pdo_stmt_t *stmt)
{
@ -48,7 +51,14 @@ static int pdo_sqlite_stmt_execute(pdo_stmt_t *stmt)
}
S->done = 0;
switch (sqlite3_step(S->stmt)) {
#ifdef HAVE_VALGRIND
CALLGRIND_TOGGLE_COLLECT;
#endif
int result = sqlite3_step(S->stmt);
#ifdef HAVE_VALGRIND
CALLGRIND_TOGGLE_COLLECT;
#endif
switch (result) {
case SQLITE_ROW:
S->pre_fetched = 1;
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,
if (S->done) {
return 0;
}
#ifdef HAVE_VALGRIND
CALLGRIND_TOGGLE_COLLECT;
#endif
i = sqlite3_step(S->stmt);
#ifdef HAVE_VALGRIND
CALLGRIND_TOGGLE_COLLECT;
#endif
switch (i) {
case SQLITE_ROW:
return 1;

View file

@ -31,6 +31,10 @@
#include "SAPI.h"
#include "sqlite3_arginfo.h"
#ifdef HAVE_VALGRIND
# include "valgrind/callgrind.h"
#endif
ZEND_DECLARE_MODULE_GLOBALS(sqlite3)
static PHP_GINIT_FUNCTION(sqlite3);
@ -595,7 +599,14 @@ PHP_METHOD(SQLite3, query)
result->column_count = -1;
ZVAL_OBJ(&result->stmt_obj_zval, Z_OBJ(stmt));
#ifdef HAVE_VALGRIND
CALLGRIND_TOGGLE_COLLECT;
#endif
return_code = sqlite3_step(result->stmt_obj->stmt);
#ifdef HAVE_VALGRIND
CALLGRIND_TOGGLE_COLLECT;
#endif
switch (return_code) {
case SQLITE_ROW: /* Valid Row */
@ -697,7 +708,13 @@ PHP_METHOD(SQLite3, querySingle)
RETURN_FALSE;
}
#ifdef HAVE_VALGRIND
CALLGRIND_TOGGLE_COLLECT;
#endif
return_code = sqlite3_step(stmt);
#ifdef HAVE_VALGRIND
CALLGRIND_TOGGLE_COLLECT;
#endif
switch (return_code) {
case SQLITE_ROW: /* Valid Row */
@ -1796,7 +1813,13 @@ PHP_METHOD(SQLite3Stmt, execute)
RETURN_FALSE;
}
#ifdef HAVE_VALGRIND
CALLGRIND_TOGGLE_COLLECT;
#endif
return_code = sqlite3_step(stmt_obj->stmt);
#ifdef HAVE_VALGRIND
CALLGRIND_TOGGLE_COLLECT;
#endif
switch (return_code) {
case SQLITE_ROW: /* Valid Row */
@ -1953,7 +1976,13 @@ PHP_METHOD(SQLite3Result, fetchArray)
SQLITE3_CHECK_INITIALIZED(result_obj->db_obj, result_obj->stmt_obj->initialised, SQLite3Result)
#ifdef HAVE_VALGRIND
CALLGRIND_TOGGLE_COLLECT;
#endif
ret = sqlite3_step(result_obj->stmt_obj->stmt);
#ifdef HAVE_VALGRIND
CALLGRIND_TOGGLE_COLLECT;
#endif
switch (ret) {
case SQLITE_ROW:
/* If there was no return value then just skip fetching */