From 73b8fe58c6fb985898d2bbf431926f0628e2b0a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=20Vr=C3=A1til?= Date: Sat, 11 Apr 2015 11:44:49 +0200 Subject: Async: add runtime executor tracing for easier debugging --- async/src/debug.cpp | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 async/src/debug.cpp (limited to 'async/src/debug.cpp') diff --git a/async/src/debug.cpp b/async/src/debug.cpp new file mode 100644 index 0000000..9dfad1a --- /dev/null +++ b/async/src/debug.cpp @@ -0,0 +1,73 @@ +/* + * Copyright 2015 Daniel Vrátil + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2 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 Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library. If not, see . + */ + +#include "debug.h" +#include "async.h" + +#include + +#ifdef __GNUG__ +#include +#include +#endif + +namespace Async +{ + +Q_LOGGING_CATEGORY(Debug, "org.kde.async", QtWarningMsg); +Q_LOGGING_CATEGORY(Trace, "org.kde.async.trace", QtWarningMsg); + +QString demangleName(const char *name) +{ +#ifdef __GNUG__ + int status = 1; // uses -3 to 0 error codes + std::unique_ptr demangled(abi::__cxa_demangle(name, 0, 0, &status), std::free); + if (status == 0) { + return QString(demangled.get()); + } +#endif + return QString(name); +} + +} + +using namespace Async; + +int Tracer::lastId = 0; + +Tracer::Tracer(Private::Execution *execution) + : mId(lastId++) + , mExecution(execution) +{ + msg(Async::Tracer::Start); +} + +Tracer::~Tracer() +{ + msg(Async::Tracer::End); + // FIXME: Does this work on parallel executions? + --lastId; + --mId; +} + +void Tracer::msg(Tracer::MsgType msgType) +{ + qCDebug(Trace).nospace() << (QString().fill(QLatin1Char(' '), mId * 2) % + (msgType == Async::Tracer::Start ? " START " : " END ") % + QString::number(mId) % " " % + mExecution->executor->mExecutorName); +} -- cgit v1.2.3