From 707a8cb280f1c5c4989aaf21090b600c4e06da65 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Thu, 21 Jun 2012 18:35:37 -0400 Subject: [PATCH] Add more specialized SQL debugging --- src/libtomahawk/database/Database.cpp | 3 ++- src/libtomahawk/database/TomahawkSqlQuery.cpp | 23 +++++++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/libtomahawk/database/Database.cpp b/src/libtomahawk/database/Database.cpp index 32a1a7467..4fb612d32 100644 --- a/src/libtomahawk/database/Database.cpp +++ b/src/libtomahawk/database/Database.cpp @@ -51,7 +51,7 @@ Database::Database( const QString& dbname, QObject* parent ) else m_maxConcurrentThreads = qBound( DEFAULT_WORKER_THREADS, QThread::idealThreadCount(), MAX_WORKER_THREADS ); - tDebug() << Q_FUNC_INFO << "Using" << m_maxConcurrentThreads << "database worker threads"; + tDebug() << Q_FUNC_INFO << "Using" << m_maxConcurrentThreads << "database worker threads; current (GUI) thread is " << QThread::currentThread(); connect( m_impl, SIGNAL( indexReady() ), SIGNAL( indexReady() ) ); connect( m_impl, SIGNAL( indexReady() ), SIGNAL( ready() ) ); @@ -142,6 +142,7 @@ Database::impl() QThread* thread = QThread::currentThread(); if ( !m_implHash.contains( thread ) ) { + tDebug() << Q_FUNC_INFO << "Creating database impl for thread " << QThread::currentThread(); DatabaseImpl* impl = m_impl->clone(); m_implHash.insert( thread, impl ); } diff --git a/src/libtomahawk/database/TomahawkSqlQuery.cpp b/src/libtomahawk/database/TomahawkSqlQuery.cpp index ff2c52d55..7e12b756c 100644 --- a/src/libtomahawk/database/TomahawkSqlQuery.cpp +++ b/src/libtomahawk/database/TomahawkSqlQuery.cpp @@ -63,6 +63,13 @@ TomahawkSqlQuery::exec( const QString& query ) bool TomahawkSqlQuery::exec() { + bool log = false; +#ifdef TOMAHAWK_QUERY_ANALYZE + log = true; +#endif + if ( log ) + tLog( LOGSQL ) << "TomahawkSqlQuery::exec running in thread " << QThread::currentThread(); + QTime t; t.start(); @@ -81,14 +88,9 @@ TomahawkSqlQuery::exec() showError(); int e = t.elapsed(); - bool log = ( e >= QUERY_THRESHOLD ); -#ifdef TOMAHAWK_QUERY_ANALYZE - log = true; -#endif - - if ( log ) - tLog( LOGSQL ) << "TomahawkSqlQuery (" << t.elapsed() << "ms ):" << lastQuery(); + if ( log || e >= QUERY_THRESHOLD ) + tLog( LOGSQL ) << "TomahawkSqlQuery::exec (" << t.elapsed() << "ms ):" << lastQuery(); return ret; } @@ -97,6 +99,13 @@ TomahawkSqlQuery::exec() bool TomahawkSqlQuery::commitTransaction() { + bool log = false; +#ifdef TOMAHAWK_QUERY_ANALYZE + log = true; +#endif + if ( log ) + tLog( LOGSQL ) << "TomahawkSqlQuery::commitTransaction running in thread " << QThread::currentThread(); + unsigned int retries = 0; while ( !m_db.commit() && ++retries < 10 ) {