From a25e189904980c1abb5da91c2002cae827aea9c2 Mon Sep 17 00:00:00 2001 From: nowrep Date: Tue, 26 Feb 2013 12:29:46 +0100 Subject: [PATCH] [AdBlock] Added debug output with ADBLOCK_DEBUG define. It will print the time needed to load all rules and also to block each url. --- src/lib/adblock/adblockmanager.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/lib/adblock/adblockmanager.cpp b/src/lib/adblock/adblockmanager.cpp index 0c0f5a25c..ebefa53a1 100644 --- a/src/lib/adblock/adblockmanager.cpp +++ b/src/lib/adblock/adblockmanager.cpp @@ -32,6 +32,12 @@ #include #include +//#define ADBLOCK_DEBUG + +#ifdef ADBLOCK_DEBUG +#include +#endif + AdBlockManager* AdBlockManager::s_adBlockManager = 0; AdBlockManager::AdBlockManager(QObject* parent) @@ -75,6 +81,10 @@ QList AdBlockManager::subscriptions() const QNetworkReply* AdBlockManager::block(const QNetworkRequest &request) { +#ifdef ADBLOCK_DEBUG + QElapsedTimer timer; + timer.start(); +#endif const QString &urlString = request.url().toEncoded(); const QString &urlDomain = request.url().host(); const QString &urlScheme = request.url().scheme(); @@ -100,10 +110,18 @@ QNetworkReply* AdBlockManager::block(const QNetworkRequest &request) AdBlockBlockedNetworkReply* reply = new AdBlockBlockedNetworkReply(subscription, blockedRule, this); reply->setRequest(request); +#ifdef ADBLOCK_DEBUG + qDebug() << "BLOCKED: " << timer.elapsed() << blockedRule->filter() << request.url(); +#endif + return reply; } } +#ifdef ADBLOCK_DEBUG + qDebug() << timer.elapsed() << request.url(); +#endif + return 0; } @@ -184,6 +202,11 @@ void AdBlockManager::load() return; } +#ifdef ADBLOCK_DEBUG + QElapsedTimer timer; + timer.start(); +#endif + Settings settings; settings.beginGroup("AdBlock"); m_enabled = settings.value("enabled", m_enabled).toBool(); @@ -249,6 +272,10 @@ void AdBlockManager::load() QTimer::singleShot(1000 * 60, this, SLOT(updateAllSubscriptions())); } +#ifdef ADBLOCK_DEBUG + qDebug() << "AdBlock loaded in" << timer.elapsed(); +#endif + m_loaded = true; }