aboutsummaryrefslogtreecommitdiffstats
path: root/src/ruleparser.cpp
diff options
context:
space:
mode:
authorTorgny Nyblom <kde@nyblom.org>2010-12-04 20:53:43 +0100
committerTorgny Nyblom <kde@nyblom.org>2010-12-04 20:53:43 +0100
commitce56750e8a47e3be86cf0c0964a145c7d7f943e5 (patch)
tree53f1f80707fc7f147a111a85593ecb92e72a67d5 /src/ruleparser.cpp
parent6e13e426db84b9137b98ba80552b91e3684085cd (diff)
downloadsvn2git-ce56750e8a47e3be86cf0c0964a145c7d7f943e5.tar
svn2git-ce56750e8a47e3be86cf0c0964a145c7d7f943e5.tar.gz
svn2git-ce56750e8a47e3be86cf0c0964a145c7d7f943e5.tar.bz2
svn2git-ce56750e8a47e3be86cf0c0964a145c7d7f943e5.tar.xz
svn2git-ce56750e8a47e3be86cf0c0964a145c7d7f943e5.zip
Add an option to print some stats after a run.
Diffstat (limited to 'src/ruleparser.cpp')
-rw-r--r--src/ruleparser.cpp88
1 files changed, 88 insertions, 0 deletions
diff --git a/src/ruleparser.cpp b/src/ruleparser.cpp
index 27ab0ca..f7d201c 100644
--- a/src/ruleparser.cpp
+++ b/src/ruleparser.cpp
@@ -21,6 +21,7 @@
#include <QDebug>
#include "ruleparser.h"
+#include "CommandLineParser.h"
RulesList::RulesList(const QString &filenames)
: m_filenames(filenames)
@@ -193,6 +194,7 @@ void Rules::load(const QString &filename)
if (!match.repository.isEmpty())
match.action = Match::Export;
m_matchRules += match;
+ Stats::instance()->addRule(match);
state = ReadingNone;
continue;
}
@@ -232,6 +234,92 @@ void Rules::load(const QString &filename)
}
}
+Stats *Stats::self = 0;
+
+class Stats::Private
+{
+public:
+ Private();
+
+ void printStats() const;
+ void ruleMatched(const Rules::Match &rule, const int rev);
+ void addRule(const Rules::Match &rule);
+private:
+ QMap<QString,int> m_usedRules;
+};
+
+Stats::Stats() : d(new Private())
+{
+ use = CommandLineParser::instance()->contains("stats");
+}
+
+Stats::~Stats()
+{
+ delete d;
+}
+
+void Stats::init()
+{
+ if(self)
+ delete self;
+ self = new Stats();
+}
+
+Stats* Stats::instance()
+{
+ return self;
+}
+
+void Stats::printStats() const
+{
+ if(use)
+ d->printStats();
+}
+
+void Stats::ruleMatched(const Rules::Match &rule, const int rev)
+{
+ if(use)
+ d->ruleMatched(rule, rev);
+}
+
+void Stats::addRule( const Rules::Match &rule)
+{
+ if(use)
+ d->addRule(rule);
+}
+
+Stats::Private::Private()
+{
+}
+
+void Stats::Private::printStats() const
+{
+ printf("\nRule stats\n");
+ foreach(const QString name, m_usedRules.keys()) {
+ printf("%s was matched %i times\n", qPrintable(name), m_usedRules[name]);
+ }
+}
+
+void Stats::Private::ruleMatched(const Rules::Match &rule, const int rev)
+{
+ Q_UNUSED(rev);
+ const QString name = rule.info();
+ if(!m_usedRules.contains(name)) {
+ m_usedRules.insert(name, 1);
+ qWarning() << "New match rule, should have been added when created.";
+ } else {
+ m_usedRules[name]++;
+ }
+}
+
+void Stats::Private::addRule( const Rules::Match &rule)
+{
+ const QString name = rule.info();
+ if(m_usedRules.contains(name))
+ qWarning() << "Rule" << name << "was added multiple times.";
+ m_usedRules.insert(name, 0);
+}
+
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug s, const Rules::Match &rule)
{