2019-05-23 04:20:00 +08:00
|
|
|
/*
|
2022-07-19 19:40:43 +08:00
|
|
|
Copyright (c) 2008-2022 Jan W. Krieger (<jan@jkrieger.de>)
|
2019-05-23 04:20:00 +08:00
|
|
|
|
|
|
|
|
|
|
|
This software is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Lesser General Public License (LGPL) as published by
|
|
|
|
the Free Software Foundation, either version 2.1 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program 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 (LGPL) for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License (LGPL)
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-06-02 21:38:09 +08:00
|
|
|
#include "jkqtcommon/jkqtpdebuggingtools.h"
|
2019-05-23 04:20:00 +08:00
|
|
|
#include <QDebug>
|
|
|
|
#include <QApplication>
|
2024-01-08 19:53:11 +08:00
|
|
|
#include <QThread>
|
2019-05-23 04:20:00 +08:00
|
|
|
|
2023-06-30 19:52:17 +08:00
|
|
|
namespace JKQTPAutoOutputTimer_private {
|
|
|
|
thread_local int global_indent=0;
|
|
|
|
}
|
2019-05-23 04:20:00 +08:00
|
|
|
|
2019-06-21 21:46:53 +08:00
|
|
|
JKQTPAutoOutputTimer::JKQTPAutoOutputTimer(const QString& _message) :
|
|
|
|
QElapsedTimer(),message(_message),indent()
|
2019-05-23 04:20:00 +08:00
|
|
|
{
|
2023-06-30 19:52:17 +08:00
|
|
|
this->indent=QString(JKQTPAutoOutputTimer_private::global_indent, QLatin1Char(' '));
|
|
|
|
JKQTPAutoOutputTimer_private::global_indent+=4;
|
2019-05-23 04:20:00 +08:00
|
|
|
#if QT_VERSION >= 0x040800
|
2024-01-08 19:53:11 +08:00
|
|
|
qDebug()<<QThread::currentThread()<<": "+this->indent+"TIMER_START: "+message;
|
2019-05-23 04:20:00 +08:00
|
|
|
#else
|
2024-01-08 19:53:11 +08:00
|
|
|
qDebug()<<QThread::currentThread()<<": "+this->indent+"TIMER_START: "+message;
|
2019-05-23 04:20:00 +08:00
|
|
|
#endif
|
|
|
|
start();
|
|
|
|
}
|
|
|
|
|
|
|
|
JKQTPAutoOutputTimer::~JKQTPAutoOutputTimer()
|
|
|
|
{
|
|
|
|
#if QT_VERSION >= 0x040800
|
2024-01-08 19:53:11 +08:00
|
|
|
qDebug()<<QThread::currentThread()<<": "+this->indent+"TIMER_END: "+message+" DUR: "<<double(nsecsElapsed())/1.0e6<<"ms";
|
2019-05-23 04:20:00 +08:00
|
|
|
#else
|
2024-01-08 19:53:11 +08:00
|
|
|
qDebug()<<QThread::currentThread()<<": "+this->indent+"TIMER_END: "+message+" DUR: "<<double(elapsed())/1.0e3<<"ms";
|
2019-05-23 04:20:00 +08:00
|
|
|
#endif
|
2023-06-30 19:52:17 +08:00
|
|
|
JKQTPAutoOutputTimer_private::global_indent-=4;
|
2019-05-23 04:20:00 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void JKQTPAutoOutputTimer::write(const QString& message) const {
|
|
|
|
#if QT_VERSION >= 0x040800
|
2024-01-08 19:53:11 +08:00
|
|
|
qDebug()<<QThread::currentThread()<<": "+this->indent+"TIMER_MESSAGE: "+this->message+" "+message+" DUR: "<<double(nsecsElapsed())/1.0e6<<"ms";
|
2019-05-23 04:20:00 +08:00
|
|
|
#else
|
2024-01-08 19:53:11 +08:00
|
|
|
qDebug()<<QThread::currentThread()<<": "+this->indent+"TIMER_MESSAGE: "+this->message+" "+message+" DUR: "<<double(elapsed())/1.0e3<<"ms";
|
2019-05-23 04:20:00 +08:00
|
|
|
#endif
|
|
|
|
}
|