1/*
2 Copyright (c) 2003-2005 Max Howell <max.howell@methylblue.com>
3 Copyright (c) 2007-2009 Mark Kretschmann <kretschmann@kde.org>
4 Copyright (c) 2010 Kevin Funk <krf@electrostorm.net>
5 Copyright (c) 2011 Harald Sitter <sitter@kde.org>
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library. If not, see <http://www.gnu.org/licenses/>.
19*/
20
21#ifndef PHONON_DEBUG_H
22#define PHONON_DEBUG_H
23
24// We always want debug output available at runtime
25#undef QT_NO_DEBUG_OUTPUT
26#undef KDE_NO_DEBUG_OUTPUT
27
28#include <QtCore/QDebug>
29#include <QtCore/QMutex>
30
31#if QT_VERSION >= 0x040700
32# include <QtCore/QElapsedTimer>
33#else
34# include <QtCore/QTime>
35#endif
36
37// Platform specific macros
38#ifdef _WIN32 // krazy:exclude=cpp we really want to check a compiler feature here :P
39#define __PRETTY_FUNCTION__ __FUNCTION__
40#endif
41#ifdef __SUNPRO_CC
42#define __PRETTY_FUNCTION__ __FILE__
43#endif
44
45/**
46 * @namespace Debug
47 * @short kdebug with indentation functionality and convenience macros
48 * @author Max Howell <max.howell@methylblue.com>
49 *
50 * Usage:
51 *
52 * #define DEBUG_PREFIX "Blah"
53 * #include "debug.h"
54 *
55 * void function()
56 * {
57 * Debug::Block myBlock( __PRETTY_FUNCTION__ );
58 *
59 * debug() << "output1" << endl;
60 * debug() << "output2" << endl;
61 * }
62 *
63 * Will output:
64 *
65 * app: BEGIN: void function()
66 * app: [Blah] output1
67 * app: [Blah] output2
68 * app: END: void function(): Took 0.1s
69 *
70 * @see Block
71 * @see CrashHelper
72 * @see ListStream
73 */
74namespace Debug
75{
76 extern QRecursiveMutex mutex;
77
78 enum DebugLevel {
79 DEBUG_INFO = 0,
80 DEBUG_WARN = 1,
81 DEBUG_ERROR = 2,
82 DEBUG_FATAL = 3,
83 DEBUG_NONE = 4
84 };
85
86 QDebug dbgstream( DebugLevel level = DEBUG_INFO );
87 bool debugEnabled();
88 bool debugColorEnabled();
89 DebugLevel minimumDebugLevel();
90 void setColoredDebug( bool enable );
91 void setMinimumDebugLevel( DebugLevel level );
92 QString indent();
93
94 static inline QDebug dbgstreamwrapper( DebugLevel level ) { return dbgstream( level ); }
95
96 static inline QDebug debug() { return dbgstreamwrapper( level: DEBUG_INFO ); }
97 static inline QDebug warning() { return dbgstreamwrapper( level: DEBUG_WARN ); }
98 static inline QDebug error() { return dbgstreamwrapper( level: DEBUG_ERROR ); }
99 static inline QDebug fatal() { return dbgstreamwrapper( level: DEBUG_FATAL ); }
100
101 void perfLog( const QString &message, const QString &func );
102}
103
104using Debug::debug;
105using Debug::warning;
106using Debug::error;
107using Debug::fatal;
108
109/// Standard function announcer
110#define DEBUG_FUNC_INFO { Debug::mutex.lock(); qDebug() << Debug::indent() ; Debug::mutex.unlock(); }
111
112/// Announce a line
113#define DEBUG_LINE_INFO { Debug::mutex.lock(); qDebug() << Debug::indent() << "Line: " << __LINE__; Debug::mutex.unlock(); }
114
115/// Convenience macro for making a standard Debug::Block
116#define DEBUG_BLOCK Debug::Block uniquelyNamedStackAllocatedStandardBlock( __PRETTY_FUNCTION__ );
117
118/// Performance logging
119#define PERF_LOG( msg ) { Debug::perfLog( msg, __PRETTY_FUNCTION__ ); }
120
121class BlockPrivate;
122
123namespace Debug
124{
125 /**
126 * @class Debug::Block
127 * @short Use this to label sections of your code
128 *
129 * Usage:
130 *
131 * void function()
132 * {
133 * Debug::Block myBlock( "section" );
134 *
135 * debug() << "output1" << endl;
136 * debug() << "output2" << endl;
137 * }
138 *
139 * Will output:
140 *
141 * app: BEGIN: section
142 * app: [prefix] output1
143 * app: [prefix] output2
144 * app: END: section - Took 0.1s
145 *
146 */
147 class Block
148 {
149 public:
150 explicit Block( const char *name );
151 ~Block();
152
153 private:
154#if QT_VERSION >= 0x040700
155 QElapsedTimer m_startTime;
156#else
157 QTime m_startTime;
158#endif
159 const char *m_label;
160 int m_color;
161 };
162
163 /**
164 * @name Debug::stamp()
165 * @short To facilitate crash/freeze bugs, by making it easy to mark code that has been processed
166 *
167 * Usage:
168 *
169 * {
170 * Debug::stamp();
171 * function1();
172 * Debug::stamp();
173 * function2();
174 * Debug::stamp();
175 * }
176 *
177 * Will output (assuming the crash occurs in function2()
178 *
179 * app: Stamp: 1
180 * app: Stamp: 2
181 *
182 */
183 void stamp();
184}
185
186#include <QtCore/QVariant>
187
188namespace Debug
189{
190 /**
191 * @class Debug::List
192 * @short You can pass anything to this and it will output it as a list
193 *
194 * debug() << (Debug::List() << anInt << aString << aQStringList << aDouble) << endl;
195 */
196
197 typedef QList<QVariant> List;
198}
199
200#endif
201

source code of phonon-vlc/src/utils/debug.h