hyperion.ng/libsrc/utils/Profiler.cpp
redPanther f39f074dcf add logger/compiler class (#680)
* implement make install
set CMAKE_INSTALL_PREFIX e.g. to /opt to install to /opt/hyperion
set ENABLE_SYSTEM_INSTALL to ON to activate installation
after compiling use
make install
or
make install/strip
(for performance/size optimized binaries - compile in Release to get best performance)

* cleanup cmake files
use
cmake -DINSTALL_PREFIX=/opt/hyperion ..
to install all files to hyperion or
cmake -DINSTALL_PREFIX=/usr/
to install to usr. install folders are linux standard. bin go to bin folder and additionals (effects) go to share/hyperion

* add uninstall target - be patient with that, this will remove files from your system
install service files to share/hyperion - if you want to use them you have to make a symlink to your location of service files

* optimize build release script
install service files into hyperion share folder (services not activated, this must be done by distribution package script)
initial support of cmake option -DPLATFORM= option. This selects platform specific cmake flags. no need for -DENABLE_... options (unless you want some special things)
automatic detect for apple build

* update submodule

* fix cmake error when no platform is given

* initial support for deb,rpm and tgz packages - no usefull content atm!

* make packeages contain usefull stuff

* add license
make packes more functional. package specific install missing yet

* implement debian postinstall

* disable rpm generation until it has a working state

* add hypercon compat

* add posibility for multiple config files. first one found is taken

* remove hyperion comaptlayer
services is not started automaticly

* rework debian postinstall:
- remove /opt compatibility complety. This makes more trouble as it is usefull
- when hyperiond already started, restart it
- cleanup

* add deb package dependencies

* wipe out last support for /opt installation

* change default effect path in config to /usr

* revert service files and config files

* remove last occurences of ENABLE_PROTOBUF
fix cmake warnings and make it ready for cmake 3
fix refactoring of hyperiond.cpp creates no objects for network services

* all arguments via reference ...

* fix xbmcchecker not working

* add logger class

* - profiler must be activated with ENABLE_PROFILER, otherwise an error will raise
-> this should prevent profiler gets into release code

* fix profiler


Former-commit-id: b716dd40dbf5b837356eec876d85ec71c86d5c6c
2016-06-05 16:08:55 +02:00

99 lines
2.8 KiB
C++

#include "HyperionConfig.h"
#include "utils/Profiler.h"
#include <QFileInfo>
#include <QString>
struct StopWatchItem {
const char* sourceFile;
const char* func;
unsigned int line;
clock_t startTime;
};
static unsigned int blockCounter = 0;
static std::map<std::string,StopWatchItem> GlobalProfilerMap;
Logger* Profiler::_logger = nullptr;
std::string profiler_getBaseName( std::string sourceFile)
{
QFileInfo fi( sourceFile.c_str() );
return fi.fileName().toStdString();
}
double getClockDelta(clock_t start)
{
return ((double)(clock() - start) / CLOCKS_PER_SEC) ;
}
Profiler::Profiler(const char* sourceFile, const char* func, unsigned int line) :
_file(sourceFile),
_func(func),
_line(line),
_blockId(blockCounter++),
_startTime(clock())
{
Profiler::initLogger();
_logger->Message(Logger::DEBUG,_file,_func,_line,">>> enter block %d", _blockId);
}
Profiler::~Profiler()
{
_logger->Message( Logger::DEBUG, _file,_func, _line, "<<< exit block %d, executed for %f s", _blockId, getClockDelta(_startTime) );
}
void Profiler::initLogger()
{
if (_logger == nullptr )
_logger = Logger::getInstance("PROFILER", Logger::DEBUG);
}
void Profiler::TimerStart(const std::string timerName, const char* sourceFile, const char* func, unsigned int line)
{
std::pair<std::map<std::string,StopWatchItem>::iterator,bool> ret;
Profiler::initLogger();
StopWatchItem item = {sourceFile, func, line};
ret = GlobalProfilerMap.emplace(timerName, item);
if ( ! ret.second )
{
if ( ret.first->second.sourceFile == sourceFile && ret.first->second.func == func && ret.first->second.line == line )
{
_logger->Message(Logger::DEBUG, sourceFile, func, line, "restart timer '%s'", timerName.c_str() );
ret.first->second.startTime = clock();
}
else
{
_logger->Message(Logger::DEBUG, sourceFile, func, line, "ERROR timer '%s' started in multiple locations. First occurence %s:%d:%s()",
timerName.c_str(), profiler_getBaseName(ret.first->second.sourceFile).c_str(), ret.first->second.line, ret.first->second.func );
}
}
else
{
_logger->Message(Logger::DEBUG, sourceFile, func, line, "start timer '%s'", timerName.c_str() );
}
}
void Profiler::TimerGetTime(const std::string timerName, const char* sourceFile, const char* func, unsigned int line)
{
std::map<std::string,StopWatchItem>::iterator ret = GlobalProfilerMap.find(timerName);
Profiler::initLogger();
if (ret != GlobalProfilerMap.end())
{
_logger->Message(Logger::DEBUG, sourceFile, func, line, "timer '%s' started at %s:%d:%s() took %f s execution time until here", timerName.c_str(),
profiler_getBaseName(ret->second.sourceFile).c_str(), ret->second.line, ret->second.func, getClockDelta(ret->second.startTime) );
}
else
{
_logger->Message(Logger::DEBUG, sourceFile, func, line, "ERROR timer '%s' not started", timerName.c_str() );
}
}