File indexing completed on 2024-04-28 05:08:26

0001 /***************************************************************************
0002     Copyright (C) 2003-2009 Robby Stephenson <robby@periapsis.org>
0003  ***************************************************************************/
0004 
0005 /***************************************************************************
0006  *                                                                         *
0007  *   This program is free software; you can redistribute it and/or         *
0008  *   modify it under the terms of the GNU General Public License as        *
0009  *   published by the Free Software Foundation; either version 2 of        *
0010  *   the License or (at your option) version 3 or any later version        *
0011  *   accepted by the membership of KDE e.V. (or its successor approved     *
0012  *   by the membership of KDE e.V.), which shall act as a proxy            *
0013  *   defined in Section 14 of version 3 of the license.                    *
0014  *                                                                         *
0015  *   This program is distributed in the hope that it will be useful,       *
0016  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0017  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0018  *   GNU General Public License for more details.                          *
0019  *                                                                         *
0020  *   You should have received a copy of the GNU General Public License     *
0021  *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
0022  *                                                                         *
0023  ***************************************************************************/
0024 
0025 #ifndef TELLICO_DEBUG_H
0026 #define TELLICO_DEBUG_H
0027 
0028 // some of this was borrowed from amarok/src/debug.h
0029 // which is copyright Max Howell <max.howell@methylblue.com>
0030 // amarok is licensed under the GPL
0031 
0032 #include <QDebug>
0033 #include <QLoggingCategory>
0034 
0035 // std::clock_t
0036 #include <ctime>
0037 
0038 // linux has __GNUC_PREREQ, NetBSD has __GNUC_PREREQ__
0039 #if defined(__GNUC_PREREQ) && !defined(__GNUC_PREREQ__)
0040 #  define __GNUC_PREREQ__ __GNUC_PREREQ
0041 #endif
0042 
0043 #if !defined(__GNUC_PREREQ__)
0044 #  if defined __GNUC__
0045 #    define __GNUC_PREREQ__(x, y) \
0046             ((__GNUC__ == (x) && __GNUC_MINOR__ >= (y)) || \
0047              (__GNUC__ > (x)))
0048 #  else
0049 #    define __GNUC_PREREQ__(x, y)   0
0050 #  endif
0051 #endif
0052 
0053 # if defined __cplusplus ? __GNUC_PREREQ__ (2, 6) : __GNUC_PREREQ__ (2, 4)
0054 #   define MY_FUNCTION  __PRETTY_FUNCTION__
0055 # else
0056 #  if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
0057 #   define MY_FUNCTION  __func__
0058 #  else
0059 #   define MY_FUNCTION  __FILE__ ":" __LINE__
0060 #  endif
0061 # endif
0062 
0063 #ifndef DEBUG_PREFIX
0064   #define FUNC_PREFIX ""
0065 #else
0066   #define FUNC_PREFIX "[" DEBUG_PREFIX "] "
0067 #endif
0068 
0069 Q_DECLARE_LOGGING_CATEGORY(TELLICO)
0070 
0071 #define myLog()     qCInfo(TELLICO)
0072 #define myDebug()   qDebug(TELLICO)
0073 #define myWarning() qCWarning(TELLICO)
0074 
0075 namespace Debug {
0076 
0077 class Block {
0078 
0079 public:
0080   Block(const char* label);
0081 
0082   ~Block();
0083 
0084 private :
0085   std::clock_t m_start;
0086   const char* m_label;
0087 };
0088 
0089 }
0090 
0091 /// Standard function announcer
0092 #define DEBUG_FUNC myDebug() << Q_FUNC_INFO;
0093 
0094 /// Announce a line
0095 #define DEBUG_LINE myDebug() << "[" << __FILE__ << ":" << __LINE__ << "]";
0096 
0097 /// Convenience macro for making a standard Debug::Block
0098 #ifndef WIN32
0099 #define DEBUG_BLOCK Debug::Block uniquelyNamedStackAllocatedStandardBlock( MY_FUNCTION );
0100 #else
0101 #define DEBUG_BLOCK
0102 #endif
0103 
0104 #if !defined(QT_NO_INFO_OUTPUT) && !defined(WIN32) && (defined(__unix__) || defined(__unix))
0105 #include <unistd.h>
0106 // see https://www.gnome.org/~federico/news-2006-03.html#timeline-tools
0107 // strace -ttt -f -o /tmp/logfile.strace src/tellico
0108 // plot-timeline.py -o prettygraph.png /tmp/logfile.strace
0109 #define MARK do { \
0110     char str[128]; \
0111     ::snprintf(str, 128, "MARK: %s: %s (%d)", metaObject()->className(), MY_FUNCTION, __LINE__); \
0112     ::access (str, F_OK); \
0113   } while(false)
0114 #define MARK_MSG(s) do { \
0115     char str[128]; \
0116     ::snprintf(str, 128, "MARK: %s: %s (%d)", metaObject()->className(), s, __LINE__); \
0117     ::access (str, F_OK); \
0118   } while(false)
0119 #define MARK_LINE do { \
0120     char str[128]; \
0121     ::snprintf(str, 128, "MARK: tellico: %s (%d)", __FILE__, __LINE__); \
0122     ::access (str, F_OK); \
0123   } while(false)
0124 #else
0125 #define MARK
0126 #define MARK_MSG(s)
0127 #define MARK_LINE
0128 #endif
0129 
0130 #endif