summaryrefslogtreecommitdiffstats
path: root/async/src/debug.cpp
diff options
context:
space:
mode:
authorDan Vrátil <dvratil@redhat.com>2015-04-11 11:44:49 +0200
committerDan Vrátil <dvratil@redhat.com>2015-04-11 11:44:49 +0200
commit73b8fe58c6fb985898d2bbf431926f0628e2b0a9 (patch)
tree5500fbfcca6ccc12cb744dd18c3f790e94f5fc9c /async/src/debug.cpp
parent8d5f4e8485db0bfc0745a9852bac9eceab3b769f (diff)
downloadsink-73b8fe58c6fb985898d2bbf431926f0628e2b0a9.tar.gz
sink-73b8fe58c6fb985898d2bbf431926f0628e2b0a9.zip
Async: add runtime executor tracing for easier debugging
Diffstat (limited to 'async/src/debug.cpp')
-rw-r--r--async/src/debug.cpp73
1 files changed, 73 insertions, 0 deletions
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 @@
1/*
2 * Copyright 2015 Daniel Vrátil <dvratil@redhat.com>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public License as
6 * published by the Free Software Foundation; either version 2 of
7 * the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "debug.h"
19#include "async.h"
20
21#include <QStringBuilder>
22
23#ifdef __GNUG__
24#include <cxxabi.h>
25#include <memory>
26#endif
27
28namespace Async
29{
30
31Q_LOGGING_CATEGORY(Debug, "org.kde.async", QtWarningMsg);
32Q_LOGGING_CATEGORY(Trace, "org.kde.async.trace", QtWarningMsg);
33
34QString demangleName(const char *name)
35{
36#ifdef __GNUG__
37 int status = 1; // uses -3 to 0 error codes
38 std::unique_ptr<char, void(*)(void*)> demangled(abi::__cxa_demangle(name, 0, 0, &status), std::free);
39 if (status == 0) {
40 return QString(demangled.get());
41 }
42#endif
43 return QString(name);
44}
45
46}
47
48using namespace Async;
49
50int Tracer::lastId = 0;
51
52Tracer::Tracer(Private::Execution *execution)
53 : mId(lastId++)
54 , mExecution(execution)
55{
56 msg(Async::Tracer::Start);
57}
58
59Tracer::~Tracer()
60{
61 msg(Async::Tracer::End);
62 // FIXME: Does this work on parallel executions?
63 --lastId;
64 --mId;
65}
66
67void Tracer::msg(Tracer::MsgType msgType)
68{
69 qCDebug(Trace).nospace() << (QString().fill(QLatin1Char(' '), mId * 2) %
70 (msgType == Async::Tracer::Start ? " START " : " END ") %
71 QString::number(mId) % " " %
72 mExecution->executor->mExecutorName);
73}