Fossil SCM
Enhance the --sqltrace option to show the elapse time used by each SQL statement in milliseconds.
Commit
ada305fbc0c2e1d108f503bd8322621d67edefe12c9ba6aad4c46c5fc0f3b8f1
Parent
86619b995dc31d9…
1 file changed
+11
-2
M
src/db.c
+11
-2
| --- src/db.c | ||
| +++ src/db.c | ||
| @@ -1258,11 +1258,11 @@ | ||
| 1258 | 1258 | db, "is_selected", 1, SQLITE_UTF8, 0, file_is_selected,0,0 |
| 1259 | 1259 | ); |
| 1260 | 1260 | sqlite3_create_function( |
| 1261 | 1261 | db, "if_selected", 3, SQLITE_UTF8, 0, file_is_selected,0,0 |
| 1262 | 1262 | ); |
| 1263 | - if( g.fSqlTrace ) sqlite3_trace_v2(db, SQLITE_TRACE_STMT, db_sql_trace, 0); | |
| 1263 | + if( g.fSqlTrace ) sqlite3_trace_v2(db, SQLITE_TRACE_PROFILE, db_sql_trace, 0); | |
| 1264 | 1264 | db_add_aux_functions(db); |
| 1265 | 1265 | re_add_sql_func(db); /* The REGEXP operator */ |
| 1266 | 1266 | foci_register(db); /* The "files_of_checkin" virtual table */ |
| 1267 | 1267 | sqlite3_exec(db, "PRAGMA foreign_keys=OFF;", 0, 0, 0); |
| 1268 | 1268 | return db; |
| @@ -2316,14 +2316,23 @@ | ||
| 2316 | 2316 | LOCAL int db_sql_trace(unsigned m, void *notUsed, void *pP, void *pX){ |
| 2317 | 2317 | sqlite3_stmt *pStmt = (sqlite3_stmt*)pP; |
| 2318 | 2318 | char *zSql; |
| 2319 | 2319 | int n; |
| 2320 | 2320 | const char *zArg = (const char*)pX; |
| 2321 | + char zEnd[40]; | |
| 2321 | 2322 | if( zArg[0]=='-' ) return 0; |
| 2323 | + if( m & SQLITE_TRACE_PROFILE ){ | |
| 2324 | + sqlite3_int64 nNano = *(sqlite3_int64*)pX; | |
| 2325 | + double rMillisec = 0.000001 * nNano; | |
| 2326 | + sqlite3_snprintf(sizeof(zEnd),zEnd," /* %.3fms */\n", rMillisec); | |
| 2327 | + }else{ | |
| 2328 | + zEnd[0] = '\n'; | |
| 2329 | + zEnd[1] = 0; | |
| 2330 | + } | |
| 2322 | 2331 | zSql = sqlite3_expanded_sql(pStmt); |
| 2323 | 2332 | n = (int)strlen(zSql); |
| 2324 | - fossil_trace("%s%s\n", zSql, (n>0 && zSql[n-1]==';') ? "" : ";"); | |
| 2333 | + fossil_trace("%s%s%s", zSql, (n>0 && zSql[n-1]==';') ? "" : ";", zEnd); | |
| 2325 | 2334 | sqlite3_free(zSql); |
| 2326 | 2335 | return 0; |
| 2327 | 2336 | } |
| 2328 | 2337 | |
| 2329 | 2338 | /* |
| 2330 | 2339 |
| --- src/db.c | |
| +++ src/db.c | |
| @@ -1258,11 +1258,11 @@ | |
| 1258 | db, "is_selected", 1, SQLITE_UTF8, 0, file_is_selected,0,0 |
| 1259 | ); |
| 1260 | sqlite3_create_function( |
| 1261 | db, "if_selected", 3, SQLITE_UTF8, 0, file_is_selected,0,0 |
| 1262 | ); |
| 1263 | if( g.fSqlTrace ) sqlite3_trace_v2(db, SQLITE_TRACE_STMT, db_sql_trace, 0); |
| 1264 | db_add_aux_functions(db); |
| 1265 | re_add_sql_func(db); /* The REGEXP operator */ |
| 1266 | foci_register(db); /* The "files_of_checkin" virtual table */ |
| 1267 | sqlite3_exec(db, "PRAGMA foreign_keys=OFF;", 0, 0, 0); |
| 1268 | return db; |
| @@ -2316,14 +2316,23 @@ | |
| 2316 | LOCAL int db_sql_trace(unsigned m, void *notUsed, void *pP, void *pX){ |
| 2317 | sqlite3_stmt *pStmt = (sqlite3_stmt*)pP; |
| 2318 | char *zSql; |
| 2319 | int n; |
| 2320 | const char *zArg = (const char*)pX; |
| 2321 | if( zArg[0]=='-' ) return 0; |
| 2322 | zSql = sqlite3_expanded_sql(pStmt); |
| 2323 | n = (int)strlen(zSql); |
| 2324 | fossil_trace("%s%s\n", zSql, (n>0 && zSql[n-1]==';') ? "" : ";"); |
| 2325 | sqlite3_free(zSql); |
| 2326 | return 0; |
| 2327 | } |
| 2328 | |
| 2329 | /* |
| 2330 |
| --- src/db.c | |
| +++ src/db.c | |
| @@ -1258,11 +1258,11 @@ | |
| 1258 | db, "is_selected", 1, SQLITE_UTF8, 0, file_is_selected,0,0 |
| 1259 | ); |
| 1260 | sqlite3_create_function( |
| 1261 | db, "if_selected", 3, SQLITE_UTF8, 0, file_is_selected,0,0 |
| 1262 | ); |
| 1263 | if( g.fSqlTrace ) sqlite3_trace_v2(db, SQLITE_TRACE_PROFILE, db_sql_trace, 0); |
| 1264 | db_add_aux_functions(db); |
| 1265 | re_add_sql_func(db); /* The REGEXP operator */ |
| 1266 | foci_register(db); /* The "files_of_checkin" virtual table */ |
| 1267 | sqlite3_exec(db, "PRAGMA foreign_keys=OFF;", 0, 0, 0); |
| 1268 | return db; |
| @@ -2316,14 +2316,23 @@ | |
| 2316 | LOCAL int db_sql_trace(unsigned m, void *notUsed, void *pP, void *pX){ |
| 2317 | sqlite3_stmt *pStmt = (sqlite3_stmt*)pP; |
| 2318 | char *zSql; |
| 2319 | int n; |
| 2320 | const char *zArg = (const char*)pX; |
| 2321 | char zEnd[40]; |
| 2322 | if( zArg[0]=='-' ) return 0; |
| 2323 | if( m & SQLITE_TRACE_PROFILE ){ |
| 2324 | sqlite3_int64 nNano = *(sqlite3_int64*)pX; |
| 2325 | double rMillisec = 0.000001 * nNano; |
| 2326 | sqlite3_snprintf(sizeof(zEnd),zEnd," /* %.3fms */\n", rMillisec); |
| 2327 | }else{ |
| 2328 | zEnd[0] = '\n'; |
| 2329 | zEnd[1] = 0; |
| 2330 | } |
| 2331 | zSql = sqlite3_expanded_sql(pStmt); |
| 2332 | n = (int)strlen(zSql); |
| 2333 | fossil_trace("%s%s%s", zSql, (n>0 && zSql[n-1]==';') ? "" : ";", zEnd); |
| 2334 | sqlite3_free(zSql); |
| 2335 | return 0; |
| 2336 | } |
| 2337 | |
| 2338 | /* |
| 2339 |