When using the ParallelLogger default file logger, and using options(LOG_DATABASECONNECTOR_SQL = TRUE), DatabaseConnector will log all SQL sent to the server, and the time to get a response.

This function parses the log file, producing a data frame with time per query.

extractQueryTimes(logFileName)

Arguments

logFileName

Name of the ParallelLogger log file. Assumes the file was created using the default file logger.

Value

A data frame with queries and their run times in milliseconds.

Examples


connection <- connect(dbms = "sqlite", server = ":memory:")
#> Connecting using SQLite driver
logFile <- tempfile(fileext = ".log")
ParallelLogger::addDefaultFileLogger(fileName = logFile, name = "MY_LOGGER")
#> Currently in a tryCatch or withCallingHandlers block, so unable to add global calling handlers. ParallelLogger will not capture R messages, errors, and warnings, only explicit calls to ParallelLogger. (This message will not be shown again this R session)
options(LOG_DATABASECONNECTOR_SQL = TRUE)

executeSql(connection, "CREATE TABLE test (x INT);")
#>   |                                                                              |                                                                      |   0%  |                                                                              |======================================================================| 100%
#> Executing SQL took 0.0121 secs
querySql(connection, "SELECT * FROM test;")
#> [1] X
#> <0 rows> (or 0-length row.names)

extractQueryTimes(logFile)
#>                       query           startTime milliseconds      thread
#> 1 CREATE TABLE test (x INT) 2023-12-11 12:09:22            1 Main thread
#> 2        SELECT * FROM test 2023-12-11 12:09:22            1 Main thread

ParallelLogger::unregisterLogger("MY_LOGGER")
#> [1] TRUE
unlink(logFile)
disconnect(connection)