File indexing completed on 2024-04-28 16:32:04
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 // std::clock_t 0034 #include <ctime> 0035 0036 // linux has __GNUC_PREREQ, NetBSD has __GNUC_PREREQ__ 0037 #if defined(__GNUC_PREREQ) && !defined(__GNUC_PREREQ__) 0038 # define __GNUC_PREREQ__ __GNUC_PREREQ 0039 #endif 0040 0041 #if !defined(__GNUC_PREREQ__) 0042 # if defined __GNUC__ 0043 # define __GNUC_PREREQ__(x, y) \ 0044 ((__GNUC__ == (x) && __GNUC_MINOR__ >= (y)) || \ 0045 (__GNUC__ > (x))) 0046 # else 0047 # define __GNUC_PREREQ__(x, y) 0 0048 # endif 0049 #endif 0050 0051 # if defined __cplusplus ? __GNUC_PREREQ__ (2, 6) : __GNUC_PREREQ__ (2, 4) 0052 # define MY_FUNCTION __PRETTY_FUNCTION__ 0053 # else 0054 # if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L 0055 # define MY_FUNCTION __func__ 0056 # else 0057 # define MY_FUNCTION __FILE__ ":" __LINE__ 0058 # endif 0059 # endif 0060 0061 // some logging 0062 #if !defined(KDE_NO_DEBUG_OUTPUT) 0063 #define TELLICO_LOG 0064 #endif 0065 0066 #ifndef DEBUG_PREFIX 0067 #define FUNC_PREFIX "" 0068 #else 0069 #define FUNC_PREFIX "[" DEBUG_PREFIX "] " 0070 #endif 0071 0072 #define myDebug() qDebug() 0073 #define myWarning() qWarning() 0074 #ifdef TELLICO_LOG 0075 #define myLog() qDebug() 0076 #else 0077 #define myLog() //qDebug() 0078 #endif 0079 0080 namespace Debug { 0081 0082 class Block { 0083 0084 public: 0085 Block(const char* label) : m_start(std::clock()), m_label(label) { 0086 QDebug(QtDebugMsg) << "BEGIN:" << label; 0087 } 0088 0089 ~Block() { 0090 std::clock_t finish = std::clock(); 0091 const double duration = (double) (finish - m_start) / CLOCKS_PER_SEC; 0092 QDebug(QtDebugMsg) << " END:" << m_label << "- duration =" << duration; 0093 } 0094 0095 private : 0096 std::clock_t m_start; 0097 const char* m_label; 0098 }; 0099 0100 } 0101 0102 /// Standard function announcer 0103 #define DEBUG_FUNC myDebug() << Q_FUNC_INFO; 0104 0105 /// Announce a line 0106 #define DEBUG_LINE myDebug() << "[" << __FILE__ << ":" << __LINE__ << "]"; 0107 0108 /// Convenience macro for making a standard Debug::Block 0109 #ifndef WIN32 0110 #define DEBUG_BLOCK Debug::Block uniquelyNamedStackAllocatedStandardBlock( MY_FUNCTION ); 0111 #else 0112 #define DEBUG_BLOCK 0113 #endif 0114 0115 #if defined(TELLICO_LOG) && !defined(WIN32) && (defined(__unix__) || defined(__unix)) 0116 #include <unistd.h> 0117 // see https://www.gnome.org/~federico/news-2006-03.html#timeline-tools 0118 // strace -ttt -f -o /tmp/logfile.strace src/tellico 0119 // plot-timeline.py -o prettygraph.png /tmp/logfile.strace 0120 #define MARK do { \ 0121 char str[128]; \ 0122 ::snprintf(str, 128, "MARK: %s: %s (%d)", metaObject()->className(), MY_FUNCTION, __LINE__); \ 0123 ::access (str, F_OK); \ 0124 } while(false) 0125 #define MARK_MSG(s) do { \ 0126 char str[128]; \ 0127 ::snprintf(str, 128, "MARK: %s: %s (%d)", metaObject()->className(), s, __LINE__); \ 0128 ::access (str, F_OK); \ 0129 } while(false) 0130 #define MARK_LINE do { \ 0131 char str[128]; \ 0132 ::snprintf(str, 128, "MARK: tellico: %s (%d)", __FILE__, __LINE__); \ 0133 ::access (str, F_OK); \ 0134 } while(false) 0135 #else 0136 #define MARK 0137 #define MARK_MSG(s) 0138 #define MARK_LINE 0139 #endif 0140 0141 #endif