Commit 33d67519 authored by Harald Sitter's avatar Harald Sitter 🌹
Browse files

port to davros for debugging

parent d04b9864
......@@ -17,6 +17,7 @@ endif(PHONON_FOUND_EXPERIMENTAL)
# libVLC
set(LIBVLC_MIN_VERSION "1.1.1")
find_package(LIBVLC REQUIRED)
find_package(Davros REQUIRED)
add_definitions(${QT_DEFINITIONS})
remove_definitions(-DQT3_SUPPORT_WARNINGS -DQT3_SUPPORT)
......
......@@ -31,7 +31,6 @@ set(phonon_vlc_SRCS
audiooutput.cpp
audiodataoutput.cpp
backend.cpp
debug.cpp
devicemanager.cpp
effect.cpp
effectmanager.cpp
......@@ -59,7 +58,9 @@ target_link_libraries(phonon_vlc
${QT_QTCORE_LIBRARY}
${QT_QTGUI_LIBRARY}
${PHONON_LIBRARY}
${LIBVLC_LIBRARY})
${LIBVLC_LIBRARY}
${DAVROS_LIBRARY}
)
if(WIN32)
install(TARGETS phonon_vlc DESTINATION bin/phonon_backend)
......
......@@ -83,10 +83,11 @@ Backend::Backend(QObject *parent, const QVariantList &)
// Check if we should enable debug output
int debugLevel = qgetenv("PHONON_VLC_DEBUG").toInt();
if (debugLevel > 3) { // 3 is maximum
if (debugLevel > 3) // 3 is maximum
debugLevel = 3;
}
Debug::setMinimumDebugLevel((Debug::DebugLevel)((int) Debug::DEBUG_NONE - 1 - debugLevel));
else if (debugLevel < 0) // 0 is minmum
debugLevel = 0;
Davros::setMinimumDebugLevel(static_cast<QtMsgType>(debugLevel));
// Actual libVLC initialisation
if (LibVLC::init()) {
......
/*
Copyright (c) 2003-2005 Max Howell <max.howell@methylblue.com>
Copyright (c) 2007-2009 Mark Kretschmann <kretschmann@kde.org>
Copyright (c) 2010 Kevin Funk <krf@electrostorm.net>
Copyright (c) 2011 Harald Sitter <sitter@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "debug.h"
#include "debug_p.h"
#include <QtCore/QMutex>
#include <QtCore/QObject>
#include <QtGui/QApplication>
#ifdef Q_OS_UNIX
# include <unistd.h>
#endif
// Define Application wide prefix
#ifndef APP_PREFIX
#define APP_PREFIX QLatin1String( "PHONON-VLC" )
#endif
#define DEBUG_INDENT_OBJECTNAME QLatin1String("Debug_Indent_object")
QMutex Debug::mutex( QMutex::Recursive );
using namespace Debug;
static bool s_debugColorsEnabled = true;
static DebugLevel s_debugLevel = DEBUG_NONE;
IndentPrivate::IndentPrivate(QObject* parent)
: QObject(parent)
{
setObjectName( DEBUG_INDENT_OBJECTNAME );
}
/**
* We can't use a statically instantiated QString for the indent, because
* static namespaces are unique to each dlopened library. So we piggy back
* the QString on the KApplication instance
*/
IndentPrivate* IndentPrivate::instance()
{
QObject* qOApp = reinterpret_cast<QObject*>(qApp);
QObject* obj = qOApp ? qOApp->findChild<QObject*>( DEBUG_INDENT_OBJECTNAME ) : 0;
return (obj ? static_cast<IndentPrivate*>( obj ) : new IndentPrivate( qApp ));
}
/*
Text color codes (use last digit here)
30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
*/
static int s_colors[] = { 1, 2, 4, 5, 6 }; // no yellow and white for sanity
static int s_colorIndex = 0;
static QString toString( DebugLevel level )
{
switch( level )
{
case DEBUG_WARN:
return "[WARNING]";
case DEBUG_ERROR:
return "[ERROR__]";
case DEBUG_FATAL:
return "[FATAL__]";
default:
return QString();
}
}
static int toColor( DebugLevel level )
{
switch( level ) {
case DEBUG_WARN:
return 3; // red
case DEBUG_ERROR:
case DEBUG_FATAL:
return 1; // yellow
default:
return 0; // default: black
}
}
static QString colorize( const QString &text, int color = s_colorIndex )
{
if( !debugColorEnabled() )
return text;
return QString( "\x1b[00;3%1m%2\x1b[00;39m" ).arg( QString::number(s_colors[color]), text );
}
static QString reverseColorize( const QString &text, int color )
{
if( !debugColorEnabled() )
return text;
return QString( "\x1b[07;3%1m%2\x1b[00;39m" ).arg( QString::number(color), text );
}
QString Debug::indent()
{
return IndentPrivate::instance()->m_string;
}
bool Debug::debugEnabled()
{
return s_debugLevel < DEBUG_NONE;
}
bool Debug::debugColorEnabled()
{
return s_debugColorsEnabled;
}
DebugLevel Debug::minimumDebugLevel()
{
return s_debugLevel;
}
void Debug::setColoredDebug( bool enable )
{
s_debugColorsEnabled = enable;
}
void Debug::setMinimumDebugLevel(DebugLevel level)
{
s_debugLevel = level;
}
QDebug Debug::dbgstream( DebugLevel level )
{
if ( level < s_debugLevel )
return nullDebug();
mutex.lock();
const QString currentIndent = indent();
mutex.unlock();
QString text = QString("%1%2").arg( APP_PREFIX ).arg( currentIndent );
if ( level > DEBUG_INFO )
text.append( ' ' + reverseColorize( toString(level), toColor( level ) ) );
return QDebug( QtDebugMsg ) << qPrintable( text );
}
void Debug::perfLog( const QString &message, const QString &func )
{
#ifdef Q_OS_UNIX
if( !debugEnabled() )
return;
QString str = QString( "MARK: %1: %2 %3" ).arg( qApp->applicationName(), func, message );
access( str.toLocal8Bit().data(), F_OK );
#endif
}
Block::Block( const char *label )
: m_label( label )
, m_color( s_colorIndex )
{
if( !debugEnabled() )
return;
#if QT_VERSION >= 0x040700
m_startTime.start();
#else
m_startTime = QTime::currentTime();
#endif
mutex.lock();
s_colorIndex = (s_colorIndex + 1) % 5;
dbgstream()
<< qPrintable( colorize( QLatin1String( "BEGIN:" ), m_color ) )
<< m_label;
IndentPrivate::instance()->m_string += QLatin1String(" ");
mutex.unlock();
}
Block::~Block()
{
if( !debugEnabled() )
return;
#if QT_VERSION >= 0x040700
const double duration = m_startTime.elapsed() / 1000.0;
#else
const double duration = (double)m_startTime.msecsTo( QTime::currentTime() ) / 1000.0;
#endif
mutex.lock();
IndentPrivate::instance()->m_string.truncate( Debug::indent().length() - 2 );
mutex.unlock();
// Print timing information, and a special message (DELAY) if the method took longer than 5s
if( duration < 5.0 )
{
dbgstream()
<< qPrintable( colorize( QLatin1String( "END__:" ), m_color ) )
<< m_label
<< qPrintable( colorize( QString( "[Took: %3s]")
.arg( QString::number(duration, 'g', 2) ), m_color ) );
}
else
{
dbgstream()
<< qPrintable( colorize( QString( "END__:" ), m_color ) )
<< m_label
<< qPrintable( reverseColorize( QString( "[DELAY Took (quite long) %3s]")
.arg( QString::number(duration, 'g', 2) ), toColor( DEBUG_WARN ) ) );
}
}
void Debug::stamp()
{
static int n = 0;
debug() << "| Stamp: " << ++n << endl;
}
/*
Copyright (c) 2003-2005 Max Howell <max.howell@methylblue.com>
Copyright (c) 2007-2009 Mark Kretschmann <kretschmann@kde.org>
Copyright (c) 2010 Kevin Funk <krf@electrostorm.net>
Copyright (c) 2011 Harald Sitter <sitter@kde.org>
This library is free software; you can redistribute it and/or
......@@ -18,189 +15,19 @@
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef AMAROK_DEBUG_H
#define AMAROK_DEBUG_H
#ifndef PHONON_VLC_DEBUG_H
#define PHONON_VLC_DEBUG_H
// We always want debug output available at runtime
#undef QT_NO_DEBUG_OUTPUT
#undef KDE_NO_DEBUG_OUTPUT
#define DAVROS_DEBUG_AREA "PHONON-VLC"
#include <QtCore/QDebug>
#include <QtCore/QMutex>
#include <davros/davros.h>
#include <davros/block.h>
#if QT_VERSION >= 0x040700
# include <QtCore/QElapsedTimer>
#else
# include <QtCore/QTime>
#endif
#define DEBUG_BLOCK DAVROS_BLOCK
// Platform specific macros
#ifdef _WIN32
#define __PRETTY_FUNCTION__ __FUNCTION__
#endif
#ifdef __SUNPRO_CC
#define __PRETTY_FUNCTION__ __FILE__
#endif
#define debug Davros::debug
#define warning Davros::warning
#define error Davros::error
#define fatal Davros::fatal
/**
* @namespace Debug
* @short kdebug with indentation functionality and convenience macros
* @author Max Howell <max.howell@methylblue.com>
*
* Usage:
*
* #define DEBUG_PREFIX "Blah"
* #include "debug.h"
*
* void function()
* {
* Debug::Block myBlock( __PRETTY_FUNCTION__ );
*
* debug() << "output1" << endl;
* debug() << "output2" << endl;
* }
*
* Will output:
*
* app: BEGIN: void function()
* app: [Blah] output1
* app: [Blah] output2
* app: END: void function(): Took 0.1s
*
* @see Block
* @see CrashHelper
* @see ListStream
*/
namespace Debug
{
extern QMutex mutex;
enum DebugLevel {
DEBUG_INFO = 0,
DEBUG_WARN = 1,
DEBUG_ERROR = 2,
DEBUG_FATAL = 3,
DEBUG_NONE = 4
};
QDebug dbgstream( DebugLevel level = DEBUG_INFO );
bool debugEnabled();
bool debugColorEnabled();
DebugLevel minimumDebugLevel();
void setColoredDebug( bool enable );
void setMinimumDebugLevel( DebugLevel level );
QString indent();
static inline QDebug dbgstreamwrapper( DebugLevel level ) { return dbgstream( level ); }
static inline QDebug debug() { return dbgstreamwrapper( DEBUG_INFO ); }
static inline QDebug warning() { return dbgstreamwrapper( DEBUG_WARN ); }
static inline QDebug error() { return dbgstreamwrapper( DEBUG_ERROR ); }
static inline QDebug fatal() { return dbgstreamwrapper( DEBUG_FATAL ); }
void perfLog( const QString &message, const QString &func );
}
using Debug::debug;
using Debug::warning;
using Debug::error;
using Debug::fatal;
/// Standard function announcer
#define DEBUG_FUNC_INFO { Debug::mutex.lock(); qDebug() << Debug::indent() ; Debug::mutex.unlock(); }
/// Announce a line
#define DEBUG_LINE_INFO { Debug::mutex.lock(); qDebug() << Debug::indent() << "Line: " << __LINE__; Debug::mutex.unlock(); }
/// Convenience macro for making a standard Debug::Block
#define DEBUG_BLOCK Debug::Block uniquelyNamedStackAllocatedStandardBlock( __PRETTY_FUNCTION__ );
/// Use this to remind yourself to finish the implementation of a function
#define AMAROK_NOTIMPLEMENTED warning() << "NOT-IMPLEMENTED:" << __PRETTY_FUNCTION__ << endl;
/// Use this to alert other developers to stop using a function
#define AMAROK_DEPRECATED warning() << "DEPRECATED:" << __PRETTY_FUNCTION__ << endl;
/// Performance logging
#define PERF_LOG( msg ) { Debug::perfLog( msg, __PRETTY_FUNCTION__ ); }
class BlockPrivate;
namespace Debug
{
/**
* @class Debug::Block
* @short Use this to label sections of your code
*
* Usage:
*
* void function()
* {
* Debug::Block myBlock( "section" );
*
* debug() << "output1" << endl;
* debug() << "output2" << endl;
* }
*
* Will output:
*
* app: BEGIN: section
* app: [prefix] output1
* app: [prefix] output2
* app: END: section - Took 0.1s
*
*/
class Block
{
public:
Block( const char *name );
~Block();
private:
#if QT_VERSION >= 0x040700
QElapsedTimer m_startTime;
#else
QTime m_startTime;
#endif
const char *m_label;
int m_color;
};
/**
* @name Debug::stamp()
* @short To facilitate crash/freeze bugs, by making it easy to mark code that has been processed
*
* Usage:
*
* {
* Debug::stamp();
* function1();
* Debug::stamp();
* function2();
* Debug::stamp();
* }
*
* Will output (assuming the crash occurs in function2()
*
* app: Stamp: 1
* app: Stamp: 2
*
*/
void stamp();
}
#include <QtCore/QVariant>
namespace Debug
{
/**
* @class Debug::List
* @short You can pass anything to this and it will output it as a list
*
* debug() << (Debug::List() << anInt << aString << aQStringList << aDouble) << endl;
*/
typedef QList<QVariant> List;
}
#endif
#endif // PHONON_VLC_DEBUG_H
/*
Copyright (c) 2010 Kevin Funk <krf@electrostorm.net>
Copyright (c) 2011 Casian Andrei <skeletk13@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef DEBUGPRIVATE_H
#define DEBUGPRIVATE_H
#include "debug.h"
#include <QtCore/QString>
class IndentPrivate
: public QObject
{
private:
explicit IndentPrivate(QObject* parent = 0);
public:
static IndentPrivate* instance();
QString m_string;
};
/*
* From kdelibs/kdecore/io
*/
class NoDebugStream: public QIODevice
{
// Q_OBJECT
public:
NoDebugStream() { open(WriteOnly); }
bool isSequential() const { return true; }
qint64 readData(char *, qint64) { return 0; /* eof */ }
qint64 readLineData(char *, qint64) { return 0; /* eof */ }
qint64 writeData(const char *, qint64 len) { return len; }
} devnull;
QDebug nullDebug()
{
return QDebug(&devnull);
}
#endif // DEBUGPRIVATE_H
......@@ -70,7 +70,7 @@ bool LibVLC::init()
args << QByteArray("--config=").append(QFile::encodeName(configFileName));
}
int debugLevel = 3 - (int) Debug::minimumDebugLevel();
int debugLevel = 3 - static_cast<int>(Davros::minimumDebugLevel());
if (debugLevel > 0) {
args << QByteArray("--verbose=").append(QString::number(debugLevel));
args << QByteArray("--extraintf=logger");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment