on xenial help sign in
removed debug log
commitee0e9fd10c9e979cf1a5cc42f6a33c78be6efb2d authorNick Dedekind <nick.dedekind@canonical.com> dateMon 27 Mar 2017, 16:39 (10 years ago) parent916a0ea
11 files changed+2−448
plugins/Unity/CMakeLists.txt−1 plugins/Unity/Debug/CMakeLists.txt−30 plugins/Unity/Debug/consolelog.cpp−221 plugins/Unity/Debug/consolelog.h−87 plugins/Unity/Debug/plugin.cpp−31 plugins/Unity/Debug/plugin.h−32 plugins/Unity/Debug/qmldir−3 qml/Shell.qml−16 src/DebuggingController.cpp+1−12 src/DebuggingController.h−14 tests/qmltests/tst_Shell.qml+1−1
plugins/Unity/CMakeLists.txt−1
@@ -1,6 +1,5 @@
11add_subdirectory(ApplicationMenu)
22add_subdirectory(Connectivity)
3−add_subdirectory(Debug)
43add_subdirectory(Indicators)
54add_subdirectory(Launcher)
65add_subdirectory(Session)
plugins/Unity/Debug/CMakeLists.txtdeleted−30
@@ -1,30 +0,0 @@
1−include_directories(
2− ${CMAKE_CURRENT_SOURCE_DIR}
3− ${CMAKE_CURRENT_BINARY_DIR}
4−)
5−
6−include_directories(
7− SYSTEM
8− ${Qt5Gui_PRIVATE_INCLUDE_DIRS}
9− ${Qt5Quick_PRIVATE_INCLUDE_DIRS}
10− ${GIO_INCLUDE_DIRS}
11−)
12−
13−set(QMLPLUGIN_SRC
14− consolelog.cpp
15− plugin.cpp
16− )
17−
18−add_library(Debug-qml SHARED
19− ${QMLPLUGIN_SRC}
20− )
21−
22−# Because this is an internal support library, we want
23−# to expose all symbols in it. Consider changing this
24−# either to a static library or just using the
25−# files directly in targets.
26−set_target_properties(Debug-qml PROPERTIES COMPILE_FLAGS -fvisibility=default)
27−
28−qt5_use_modules(Debug-qml Qml Quick Concurrent)
29−
30−add_unity8_plugin(Unity.Debug 0.1 Unity/Debug TARGETS Debug-qml)
plugins/Unity/Debug/consolelog.cppdeleted−221
@@ -1,221 +0,0 @@
1−/*
2− * Copyright 2016 Canonical Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU Lesser General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU Lesser General Public License for more details.
12− *
13− * You should have received a copy of the GNU Lesser General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15−*/
16−
17−#include "consolelog.h"
18−
19−#include <unistd.h>
20−#include <stdio.h>
21−#include <thread>
22−#include <iostream>
23−#include <sys/ioctl.h>
24−
25−#include <functional>
26−
27−namespace
28−{
29−
30−int wait_fd(std::function<int(void)> fn)
31−{
32− int ret = -1;
33− bool fd_blocked = false;
34− do
35− {
36− ret = fn();
37− fd_blocked = (errno == EINTR || errno == EBUSY);
38− if (fd_blocked)
39− QThread::msleep(10);
40− }
41− while (ret < 0);
42− return ret;
43−}
44−
45−#define PIPE_WAIT(val) wait_fd(std::bind(pipe, val))
46−#define DUP_WAIT(fd) wait_fd(std::bind(dup, fd))
47−#define DUP2_WAIT(fd1, fd2) wait_fd(std::bind(dup2, fd1, fd2))
48−#define CLOSE_WAIT(fd) wait_fd(std::bind(close, fd))
49−
50−}
51−
52−LogRedirector::LogRedirector()
53− : m_ref(0)
54− , m_stop(false)
55−{
56− setObjectName("ConsoleLog");
57−
58− // make stdout & stderr streams unbuffered
59− // so that we don't need to flush the streams
60− // before capture and after capture
61− // (fflush can cause a deadlock if the stream is currently being used)
62− setvbuf(stdout,NULL,_IONBF,0);
63− setvbuf(stderr,NULL,_IONBF,0);
64−}
65−
66−void LogRedirector::run()
67−{
68− PIPE_WAIT(m_pipe);
69−
70− int oldStdOut = DUP_WAIT(fileno(stdout));
71− int oldStdErr = DUP_WAIT(fileno(stderr));
72−
73− DUP2_WAIT(m_pipe[WRITE], fileno(stdout));
74− DUP2_WAIT(m_pipe[WRITE], fileno(stderr));
75− CLOSE_WAIT(m_pipe[WRITE]);
76−
77− while(true) {
78− {
79− QMutexLocker lock(&m_mutex);
80− if (m_stop) break;
81− }
82− checkLog();
83− QThread::msleep(50);
84− }
85−
86− DUP2_WAIT(oldStdOut, fileno(stdout));
87− DUP2_WAIT(oldStdErr, fileno(stderr));
88−
89− CLOSE_WAIT(oldStdOut);
90− CLOSE_WAIT(oldStdErr);
91− CLOSE_WAIT(m_pipe[READ]);
92−}
93−
94−
95−void LogRedirector::checkLog()
96−{
97− // Do not allow read to block with no data.
98− // If we stop the thread while waiting a read,
99− // it will block the main thread waiting for this thread to stop.
100− int count = 0;
101− ioctl(m_pipe[READ], FIONREAD, &count);
102− if (count <= 0) return;
103−
104− std::string captured;
105− std::string buf;
106− const int bufSize = 1024;
107− buf.resize(bufSize);
108− int bytesRead = 0;
109− bytesRead = read(m_pipe[READ], &(*buf.begin()), bufSize);
110− while(bytesRead == bufSize)
111− {
112− captured += buf;
113− bytesRead = 0;
114− bytesRead = read(m_pipe[READ], &(*buf.begin()), bufSize);
115− }
116− if (bytesRead > 0)
117− {
118− buf.resize(bytesRead);
119− captured += buf;
120− }
121−
122− if (!captured.empty()) {
123− Q_EMIT log(QString::fromStdString(captured));
124− }
125−}
126−
127−LogRedirector *LogRedirector::instance()
128−{
129− static LogRedirector* log = nullptr;
130− if (!log) {
131− log = new LogRedirector();
132− }
133− return log;
134−}
135−
136−void LogRedirector::add(ConsoleLog* logger)
137−{
138− QMutexLocker lock(&m_mutex);
139− connect(this, &LogRedirector::log, logger, &ConsoleLog::logged, Qt::UniqueConnection);
140−
141− m_ref++;
142− if (!LogRedirector::instance()->isRunning()) {
143− m_stop = false;
144− LogRedirector::instance()->start();
145− }
146−}
147−
148−void LogRedirector::remove(ConsoleLog* logger)
149−{
150− QMutexLocker lock(&m_mutex);
151− disconnect(this, &LogRedirector::log, logger, &ConsoleLog::logged);
152−
153− m_ref = qMax(m_ref-1, 0);
154− if (m_ref == 0 && LogRedirector::instance()->isRunning()) {
155− m_stop = true;
156− lock.unlock();
157− LogRedirector::instance()->wait();
158− }
159−}
160−
161−ConsoleLog::ConsoleLog(QObject *parent)
162− : QObject(parent)
163− , m_enabled(false)
164− , m_maxLines(60)
165−{
166− auto updateEnabled = [this]() {
167− if (m_enabled) {
168− LogRedirector::instance()->add(this);
169− } else {
170− LogRedirector::instance()->remove(this);
171− }
172− };
173− connect(this, &ConsoleLog::enabledChanged, this, updateEnabled);
174−}
175−
176−ConsoleLog::~ConsoleLog()
177−{
178− if (m_enabled) {
179− LogRedirector::instance()->remove(this);
180− }
181−}
182−
183−void ConsoleLog::setEnabled(bool enabled)
184−{
185− if (m_enabled == enabled) {
186− return;
187− }
188−
189− m_enabled = enabled;
190− Q_EMIT enabledChanged();
191−}
192−
193−QString ConsoleLog::out() const
194−{
195− return m_out.join("\n");
196−}
197−
198−void ConsoleLog::setMaxLines(int maxLines)
199−{
200− if (m_maxLines == maxLines) {
201− return;
202− }
203−
204− m_maxLines = maxLines;
205− while (m_out.count() > m_maxLines) {
206− m_out.removeLast();
207− }
208− Q_EMIT outChanged();
209− Q_EMIT maxLinesChanged();
210−}
211−
212−void ConsoleLog::logged(QString captured)
213−{
214− QStringList li = captured.split("\n", QString::SkipEmptyParts);
215− li << m_out;
216− m_out = li;
217− while (m_out.count() > m_maxLines) {
218− m_out.removeLast();
219− }
220− Q_EMIT outChanged();
221−}
plugins/Unity/Debug/consolelog.hdeleted−87
@@ -1,87 +0,0 @@
1−/*
2− * Copyright 2016 Canonical Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU Lesser General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU Lesser General Public License for more details.
12− *
13− * You should have received a copy of the GNU Lesser General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15−*/
16−
17−#ifndef CONSOLELOG_H
18−#define CONSOLELOG_H
19−
20−#include <QThread>
21−#include <QMutex>
22−#include <QSet>
23−
24−class ConsoleLog;
25−
26−class LogRedirector : public QThread
27−{
28− Q_OBJECT
29−public:
30− static LogRedirector *instance();
31−
32− void add(ConsoleLog* logger);
33− void remove(ConsoleLog* logger);
34−
35−private Q_SLOTS:
36− void checkLog();
37−
38−Q_SIGNALS:
39− void log(QString log);
40−
41−private:
42− LogRedirector();
43− void run() Q_DECL_OVERRIDE;
44−
45− QMutex m_mutex;
46− int m_pipe[2];
47− int m_ref;
48− bool m_stop;
49−
50− enum PIPES { READ, WRITE };
51−};
52−
53−class ConsoleLog : public QObject
54−{
55− Q_OBJECT
56− Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
57− Q_PROPERTY(QString out READ out NOTIFY outChanged)
58− Q_PROPERTY(int maxLines READ maxLines WRITE setMaxLines NOTIFY maxLinesChanged)
59−public:
60− explicit ConsoleLog(QObject *parent = 0);
61− ~ConsoleLog();
62−
63− bool isEnabled() const { return m_enabled; }
64− void setEnabled(bool enabled);
65−
66− QString out() const;
67−
68− int maxLines() const { return m_maxLines; }
69− void setMaxLines(int maxLines);
70−
71−public Q_SLOTS:
72− void logged(QString captured);
73−
74−Q_SIGNALS:
75− void enabledChanged();
76− void outChanged();
77− void maxLinesChanged();
78−
79−private:
80− void updateEnabled();
81−
82− QStringList m_out;
83− bool m_enabled;
84− int m_maxLines;
85−};
86−
87−#endif // CONSOLELOG_H
plugins/Unity/Debug/plugin.cppdeleted−31
@@ -1,31 +0,0 @@
1−/*
2− * Copyright (C) 2016 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−// Qt
18−#include <QtQml/qqml.h>
19−
20−// self
21−#include "plugin.h"
22−
23−// local
24−#include "consolelog.h"
25−
26−void UnityDebugPlugin::registerTypes(const char *uri)
27−{
28− Q_ASSERT(uri == QLatin1String("Unity.Debug"));
29−
30− qmlRegisterType<ConsoleLog>(uri, 0, 1, "ConsoleLog");
31−}
plugins/Unity/Debug/plugin.hdeleted−32
@@ -1,32 +0,0 @@
1−/*
2− * Copyright (C) 2016 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−#ifndef UNITYDEBUG_PLUGIN_H
18−#define UNITYDEBUG_PLUGIN_H
19−
20−#include <QtQml/QQmlEngine>
21−#include <QtQml/QQmlExtensionPlugin>
22−
23−class UnityDebugPlugin : public QQmlExtensionPlugin
24−{
25− Q_OBJECT
26− Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
27−
28−public:
29− void registerTypes(const char *uri) override;
30−};
31−
32−#endif
plugins/Unity/Debug/qmldirdeleted−3
@@ -1,3 +0,0 @@
1−module Unity.Debug
2−plugin Debug-qml
3−typeinfo Debug.qmltypes
qml/Shell.qml−16
@@ -908,20 +908,4 @@ StyledItem {
908908 }
909909 }
910910 }
911−
912− Loader {
913− z: shutdownFadeOutRectangle.z + 1
914− active: DebuggingController.logOverlay
915−
916− sourceComponent: Text {
917− width: shell.width
918− height: shell.height
919−
920− text: consoleLog.out
921− Debug.ConsoleLog {
922− id: consoleLog
923− enabled: true
924− }
925− }
926− }
927911}
src/DebuggingController.cpp+1−12
@@ -49,8 +49,7 @@ public:
4949};
5050
5151DebuggingController::DebuggingController(QObject *parent):
52− UnityDBusObject(QStringLiteral("/com/canonical/Unity8/Debugging"), QStringLiteral("com.canonical.Unity8"), true, parent),
53− m_logOverlay(false)
52+ UnityDBusObject(QStringLiteral("/com/canonical/Unity8/Debugging"), QStringLiteral("com.canonical.Unity8"), true, parent)
5453{
5554}
5655
@@ -91,13 +90,3 @@ void DebuggingController::SetLoggingFilterRules(const QString &filterRules)
9190{
9291 QLoggingCategory::setFilterRules(filterRules);
9392}
94−
95−void DebuggingController::SetLogOverlay(bool logOverlay)
96−{
97− if (logOverlay == m_logOverlay) {
98− return;
99− }
100−
101− m_logOverlay = logOverlay;
102− Q_EMIT logOverlayChanged(m_logOverlay);
103−}
src/DebuggingController.h−14
@@ -32,14 +32,10 @@ class DebuggingController: public UnityDBusObject
3232 Q_OBJECT
3333 Q_CLASSINFO("D-Bus Interface", "com.canonical.Unity8.Debugging")
3434
35− Q_PROPERTY(bool logOverlay READ logOverlay NOTIFY logOverlayChanged)
36−
3735public:
3836 DebuggingController(QObject *parent = nullptr);
3937 ~DebuggingController() = default;
4038
41− bool logOverlay() const { return m_logOverlay; }
42−
4339public Q_SLOTS:
4440 /**
4541 * Set the QSG_VISUALIZE mode. This follows the vlues supported by Qt in
@@ -57,15 +53,5 @@ public Q_SLOTS:
5753 */
5854 Q_SCRIPTABLE void SetLoggingFilterRules(const QString &filterRules);
5955
60− /**
61− * Enable/Disable the shell console log overlay
62− */
63− Q_SCRIPTABLE void SetLogOverlay(bool logOverlay);
64−
65−Q_SIGNALS:
66− void logOverlayChanged(bool logOverlay);
67−
68−private:
69− bool m_logOverlay;
7056};
7157#endif // DEBUGGINGCONTROLLER_H
tests/qmltests/tst_Shell.qml+1−1
@@ -75,7 +75,7 @@ Rectangle {
7575
7676 QtObject {
7777 id: _screenWindow
78− property bool primary: false
78+ property bool primary: true
7979 }
8080 property alias screenWindow: _screenWindow
8181