summaryrefslogtreecommitdiffstats
path: root/kradio3/src/debug-profiler.cpp
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-02-22 18:23:26 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-02-22 18:23:26 +0000
commitae364d9bed0589bf1a22cd5f530c563462379e3e (patch)
treee32727e2664e7ce68d0d30270afa040320ae35a1 /kradio3/src/debug-profiler.cpp
downloadtderadio-ae364d9bed0589bf1a22cd5f530c563462379e3e.tar.gz
tderadio-ae364d9bed0589bf1a22cd5f530c563462379e3e.zip
Added old KDE3 version of kradio
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/kradio@1094417 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kradio3/src/debug-profiler.cpp')
-rw-r--r--kradio3/src/debug-profiler.cpp138
1 files changed, 138 insertions, 0 deletions
diff --git a/kradio3/src/debug-profiler.cpp b/kradio3/src/debug-profiler.cpp
new file mode 100644
index 0000000..8c5a9ab
--- /dev/null
+++ b/kradio3/src/debug-profiler.cpp
@@ -0,0 +1,138 @@
+/***************************************************************************
+ debug-profiler.h - description
+ -------------------
+ begin : Sat May 28 2005
+ copyright : (C) 2005 by Martin Witte
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "include/debug-profiler.h"
+
+#include <qstringlist.h>
+
+#include <sys/resource.h>
+
+TimeProfiler global_time_profiler;
+MemProfiler global_mem_profiler;
+
+Profiler::Profiler()
+{
+}
+
+
+Profiler::~Profiler()
+{
+ m_tmpStartVal = 0;
+}
+
+void Profiler::stopInternalCounter()
+{
+ long long counter = getCounter();
+ long long diff = counter - m_tmpStartVal;
+ m_internalCounter += diff;
+}
+
+void Profiler::startInternalCounter() {
+ m_tmpStartVal = getCounter();
+}
+
+void Profiler::startProfile(const QString &descr)
+{
+ stopInternalCounter();
+
+ if (m_ProfileData.contains(descr)) {
+ profile_data &d = m_ProfileData[descr];
+ d.startCounter = m_internalCounter;
+ } else {
+ m_ProfileData.insert(descr, profile_data(m_internalCounter));
+ }
+
+ startInternalCounter();
+}
+
+
+void Profiler::stopProfile (const QString &descr)
+{
+ stopInternalCounter();
+
+ if (!descr.isNull() && m_ProfileData.contains(descr)) {
+ profile_data &d = m_ProfileData[descr];
+ long long diff = m_internalCounter - d.startCounter;
+ d.accumulatedCounter += diff;
+ if (d.maxCounter < diff)
+ d.maxCounter = diff;
+ if (d.minCounter > diff)
+ d.minCounter = diff;
+ d.callCounter++;
+ }
+
+ startInternalCounter();
+}
+
+
+void Profiler::printData ()
+{
+ stopInternalCounter();
+
+ QStringList keys=m_ProfileData.keys();
+ keys.sort();
+ QValueListIterator<QString> it = keys.begin();
+ QValueListIterator<QString> end = keys.end();
+ for (; it != end; ++it) {
+ int l = (*it).length();
+ l = (((l-1) / 25) + 1) * 25;
+ if (l < 50) l = 50;
+ const profile_data &d = m_ProfileData[*it];
+ printf(("%-"+QString::number(l)+"s: total: %3.8f (%9lli) avg: %3.8f min: %3.8f max: %3.8f\n").ascii(),
+ (*it).ascii(),
+ (double)d.accumulatedCounter / 1.666e9,
+ d.callCounter,
+ (double)d.accumulatedCounter / (double)d.callCounter / 1.666e9,
+ (double)d.minCounter / 1.666e9,
+ (double)d.maxCounter / 1.666e9);
+ }
+
+ startInternalCounter();
+}
+
+
+long long MemProfiler::getCounter() const
+{
+ struct rusage usg;
+ if (getrusage(RUSAGE_SELF, &usg) == 0) {
+ return usg.ru_idrss + usg.ru_isrss;
+ } else {
+ return 0;
+ }
+}
+
+
+BlockProfiler::BlockProfiler(const QString &descr)
+ : m_Description(descr)
+{
+ global_mem_profiler.startProfile(m_Description);
+ global_time_profiler.startProfile(m_Description);
+}
+
+BlockProfiler::~BlockProfiler()
+{
+ global_time_profiler.stopProfile(m_Description);
+ global_mem_profiler.stopProfile(m_Description);
+}
+
+void BlockProfiler::stop()
+{
+ global_time_profiler.stopProfile(m_Description);
+ global_mem_profiler.stopProfile(m_Description);
+ m_Description = QString::null;
+}
+