You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
139 lines
3.8 KiB
139 lines
3.8 KiB
15 years ago
|
/***************************************************************************
|
||
|
debug-profiler.h - description
|
||
|
-------------------
|
||
|
begin : Sat May 28 2005
|
||
|
copyright : (C) 2005 by Martin Witte
|
||
|
email : witte@kawo1.rwth-aachen.de
|
||
|
***************************************************************************/
|
||
|
|
||
|
/***************************************************************************
|
||
|
* *
|
||
|
* 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"
|
||
|
|
||
14 years ago
|
#include <tqstringlist.h>
|
||
15 years ago
|
|
||
|
#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();
|
||
|
}
|
||
|
|
||
14 years ago
|
void Profiler::startProfile(const TQString &descr)
|
||
15 years ago
|
{
|
||
|
stopInternalCounter();
|
||
|
|
||
13 years ago
|
if (m_ProfileData.contains(descr)) {
|
||
15 years ago
|
profile_data &d = m_ProfileData[descr];
|
||
|
d.startCounter = m_internalCounter;
|
||
|
} else {
|
||
|
m_ProfileData.insert(descr, profile_data(m_internalCounter));
|
||
|
}
|
||
|
|
||
|
startInternalCounter();
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
void Profiler::stopProfile (const TQString &descr)
|
||
15 years ago
|
{
|
||
|
stopInternalCounter();
|
||
|
|
||
13 years ago
|
if (!descr.isNull() && m_ProfileData.contains(descr)) {
|
||
15 years ago
|
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();
|
||
|
|
||
14 years ago
|
TQStringList keys=m_ProfileData.keys();
|
||
15 years ago
|
keys.sort();
|
||
14 years ago
|
TQValueListIterator<TQString> it = keys.begin();
|
||
|
TQValueListIterator<TQString> end = keys.end();
|
||
15 years ago
|
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];
|
||
14 years ago
|
printf(("%-"+TQString::number(l)+"s: total: %3.8f (%9lli) avg: %3.8f min: %3.8f max: %3.8f\n").ascii(),
|
||
15 years ago
|
(*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;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
BlockProfiler::BlockProfiler(const TQString &descr)
|
||
15 years ago
|
: 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);
|
||
14 years ago
|
m_Description = TQString();
|
||
15 years ago
|
}
|
||
|
|