on xenial help sign in
Add a D-Bus interface to control some debug facilities on the fly
2f3e8afMichael Zanetti
@@ -162,3 +162,27 @@ $ PYTHONPATH=../tests/autopilot autopilot3 run unity8.some.very.long.test.name
162or run them all with
162or run them all with
163
163
164$ PYTHONPATH=../tests/autopilot autopilot3 run unity8
164$ PYTHONPATH=../tests/autopilot autopilot3 run unity8
165+
166+Debugging techniques
167+====================
168+
169+Unity8 heavily uses Qt and with that Qt debugging techniques mostly apply in the
170+same fashion. There are, however, some additional unity8-specific notes:
171+
172+* Enable/disable Qt scenegraph visualizer on the fly:
173+
174+ $ qdbus com.canonical.Unity8.Debugging /com/canonical/Unity8/Debugging SetSceneGraphVisualizer <mode>
175+
176+ This is equivalent to exporting QSG_VISUALIZE=<mode> before running unity8, except it does it on the
177+ fly.
178+
179+* Toggle slow animations on the fly:
180+
181+ $ qdbus com.canonical.Unity8.Debugging /com/canonical/Unity8/Debugging SetSlowAnimations <true|false>
182+
183+* Change logging filter rules on the fly:
184+
185+ $ qdbus com.canonical.Unity8.Debugging /com/canonical/Unity8/Debugging SetLoggingFilterRules <filter>
186+
187+ This is equivalent to exporting QT_LOGGING_RULES or defining them in QT_LOGGING_CONF, except it does
188+ it on the fly.
src/CMakeLists.txt+9−2
@@ -1,11 +1,18 @@
1+add_subdirectory(libunity8-private)
2+
1pkg_check_modules(CONNECTIVITY REQUIRED connectivity-qt1)
3pkg_check_modules(CONNECTIVITY REQUIRED connectivity-qt1)
2
4
3include_directories(
5include_directories(
4 SYSTEM
6 SYSTEM
5 ${Qt5Gui_PRIVATE_INCLUDE_DIRS}
7 ${Qt5Gui_PRIVATE_INCLUDE_DIRS}
8+ ${Qt5Quick_PRIVATE_INCLUDE_DIRS}
6 ${CONNECTIVITY_INCLUDE_DIRS}
9 ${CONNECTIVITY_INCLUDE_DIRS}
7)
10)
8
11
12+include_directories(
13+ ${libunity8-private_SOURCE_DIR}
14+)
15+
9file(GLOB_RECURSE QML_FILES
16file(GLOB_RECURSE QML_FILES
10 ${CMAKE_SOURCE_DIR}/qml/*
17 ${CMAKE_SOURCE_DIR}/qml/*
11 ${CMAKE_SOURCE_DIR}/tests/*.qml
18 ${CMAKE_SOURCE_DIR}/tests/*.qml
@@ -25,6 +32,7 @@ set(SOURCE_FILES
25 ShellView.cpp
32 ShellView.cpp
26 UnityCommandLineParser.cpp
33 UnityCommandLineParser.cpp
27 UnixSignalHandler.cpp
34 UnixSignalHandler.cpp
35+ DebuggingController.cpp
28 ${QML_FILES} # This is to make qml and image files appear in the IDE's project tree
36 ${QML_FILES} # This is to make qml and image files appear in the IDE's project tree
29)
37)
30
38
@@ -39,7 +47,7 @@ qt5_use_modules(${SHELL_APP} DBus Gui Qml Quick Test)
39if (NOT "${ANDROID_PROPERTIES_INCLUDE_DIRS}" STREQUAL "")
47if (NOT "${ANDROID_PROPERTIES_INCLUDE_DIRS}" STREQUAL "")
40 set_target_properties(${SHELL_APP} PROPERTIES INCLUDE_DIRECTORIES ${ANDROID_PROPERTIES_INCLUDE_DIRS})
48 set_target_properties(${SHELL_APP} PROPERTIES INCLUDE_DIRECTORIES ${ANDROID_PROPERTIES_INCLUDE_DIRS})
41endif()
49endif()
42−target_link_libraries(${SHELL_APP} ${ANDROID_PROPERTIES_LDFLAGS} UbuntuGestures connectivity-qt1)
50+target_link_libraries(${SHELL_APP} ${ANDROID_PROPERTIES_LDFLAGS} UbuntuGestures connectivity-qt1 unity8-private)
43
51
44if (ENABLE_TOUCH_EMULATION)
52if (ENABLE_TOUCH_EMULATION)
45 target_link_libraries(${SHELL_APP} ${MOUSETOUCHADAPTOR_LIBS_LDFLAGS})
53 target_link_libraries(${SHELL_APP} ${MOUSETOUCHADAPTOR_LIBS_LDFLAGS})
@@ -52,4 +60,3 @@ install(TARGETS ${SHELL_APP}
52
60
53add_subdirectory(Panel)
61add_subdirectory(Panel)
54add_subdirectory(Dash)
62add_subdirectory(Dash)
55−add_subdirectory(libunity8-private)
src/DebuggingController.cppnew file+92
@@ -0,0 +1,92 @@
1+/*
2+ * Copyright (C) 2016 - Canonical Ltd.
3+ *
4+ * This program is free software: you can redistribute it and/or modify it
5+ * under the terms of the GNU Lesser General Public License, as
6+ * published by the Free Software Foundation; either version 2.1 or 3.0
7+ * of the License.
8+ *
9+ * This program is distributed in the hope that it will be useful, but
10+ * WITHOUT ANY WARRANTY; without even the implied warranties of
11+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
12+ * PURPOSE. See the applicable version of the GNU Lesser General Public
13+ * License for more details.
14+ *
15+ * You should have received a copy of both the GNU Lesser General Public
16+ * License along with this program. If not, see <http://www.gnu.org/licenses/>
17+ */
18+
19+#include "DebuggingController.h"
20+
21+#include <QGuiApplication>
22+#include <QWindow>
23+#include <private/qquickwindow_p.h>
24+#include <private/qabstractanimationjob_p.h>
25+#include <private/qquickitem_p.h>
26+#include <private/qsgrenderer_p.h>
27+
28+
29+class ApplySceneGraphVisualizationJob : public QRunnable
30+{
31+public:
32+ ApplySceneGraphVisualizationJob(QQuickWindow *window, QByteArray renderMode)
33+ : m_window(window), m_renderMode(renderMode){}
34+ void run() override
35+ {
36+ qDebug() << "Setting custom render mode to:" << m_renderMode;
37+
38+ QQuickWindowPrivate *winPriv = QQuickWindowPrivate::get(m_window);
39+
40+ winPriv->customRenderMode = m_renderMode;
41+ delete winPriv->renderer;
42+ winPriv->renderer = nullptr;
43+
44+ QTimer::singleShot(10, m_window, &QQuickWindow::update); // force another frame
45+ }
46+
47+ QQuickWindow *m_window;
48+ QByteArray m_renderMode;
49+};
50+
51+DebuggingController::DebuggingController(QObject *parent):
52+ UnityDBusObject(QStringLiteral("/com/canonical/Unity8/Debugging"), QStringLiteral("com.canonical.Unity8"), true, parent)
53+{
54+}
55+
56+void DebuggingController::SetSceneGraphVisualizer(const QString &visualizer)
57+{
58+ QByteArray pendingRenderMode;
59+ QStringList supportedRenderModes = {"clip", "overdraw", "changes", "batches"};
60+ if (supportedRenderModes.contains(visualizer)) {
61+ pendingRenderMode = visualizer.toLatin1();
62+ }
63+
64+ Q_FOREACH (QWindow *window, QGuiApplication::allWindows()) {
65+ QQuickWindow* qquickWindow = qobject_cast<QQuickWindow*>(window);
66+ if (qquickWindow) {
67+
68+#if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0)
69+ // Qt does some performance optimizations that break custom render modes.
70+ // Thus the optimizations are only applied if there is no custom render mode set.
71+ // So we need to make the scenegraph recheck whether a custom render mode is set.
72+ // We do this by simply recreating the renderer.
73+ qquickWindow->scheduleRenderJob(new ApplySceneGraphVisualizationJob(qquickWindow, pendingRenderMode),
74+ QQuickWindow::AfterSwapStage);
75+#else
76+ QQuickWindowPrivate *winPriv = QQuickWindowPrivate::get(qquickWindow);
77+ winPriv->customRenderMode = visualizer.toLatin1();
78+#endif
79+ qquickWindow->update();
80+ }
81+ }
82+}
83+
84+void DebuggingController::SetSlowAnimations(bool slowAnimations)
85+{
86+ QUnifiedTimer::instance()->setSlowModeEnabled(slowAnimations);
87+}
88+
89+void DebuggingController::SetLoggingFilterRules(const QString &filterRules)
90+{
91+ QLoggingCategory::setFilterRules(filterRules);
92+}
src/DebuggingController.hnew file+57
@@ -0,0 +1,57 @@
1+/*
2+ * Copyright (C) 2016 - Canonical Ltd.
3+ *
4+ * This program is free software: you can redistribute it and/or modify it
5+ * under the terms of the GNU Lesser General Public License, as
6+ * published by the Free Software Foundation; either version 2.1 or 3.0
7+ * of the License.
8+ *
9+ * This program is distributed in the hope that it will be useful, but
10+ * WITHOUT ANY WARRANTY; without even the implied warranties of
11+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
12+ * PURPOSE. See the applicable version of the GNU Lesser General Public
13+ * License for more details.
14+ *
15+ * You should have received a copy of both the GNU Lesser General Public
16+ * License along with this program. If not, see <http://www.gnu.org/licenses/>
17+ */
18+
19+
20+#ifndef DEBUGGINGCONTROLLER_H
21+#define DEBUGGINGCONTROLLER_H
22+
23+#include <QQmlEngine>
24+#include <QQmlExtensionPlugin>
25+#include <QQuickWindow>
26+#include <QMutex>
27+
28+#include "unitydbusobject.h"
29+
30+class DebuggingController: public UnityDBusObject
31+{
32+ Q_OBJECT
33+ Q_CLASSINFO("D-Bus Interface", "com.canonical.Unity8.Debugging")
34+
35+public:
36+ DebuggingController(QObject *parent = nullptr);
37+ ~DebuggingController() = default;
38+
39+public Q_SLOTS:
40+ /**
41+ * Set the QSG_VISUALIZE mode. This follows the vlues supported by Qt in
42+ * http://doc.qt.io/qt-5/qtquick-visualcanvas-scenegraph-renderer.html
43+ */
44+ Q_SCRIPTABLE void SetSceneGraphVisualizer(const QString &visualizer);
45+
46+ /**
47+ * Slow down animations for better inspection.
48+ */
49+ Q_SCRIPTABLE void SetSlowAnimations(bool slowAnimations);
50+
51+ /**
52+ * Set the QLoggingCategory filter rules.
53+ */
54+ Q_SCRIPTABLE void SetLoggingFilterRules(const QString &filterRules);
55+
56+};
57+#endif // DEBUGGINGCONTROLLER_H
src/ShellApplication.cpp+2
@@ -30,6 +30,7 @@
30#include <paths.h>
30#include <paths.h>
31#include "CachingNetworkManagerFactory.h"
31#include "CachingNetworkManagerFactory.h"
32#include "UnityCommandLineParser.h"
32#include "UnityCommandLineParser.h"
33+#include "DebuggingController.h"
33
34
34ShellApplication::ShellApplication(int & argc, char ** argv, bool isMirServer)
35ShellApplication::ShellApplication(int & argc, char ** argv, bool isMirServer)
35 : QGuiApplication(argc, argv)
36 : QGuiApplication(argc, argv)
@@ -95,6 +96,7 @@ ShellApplication::ShellApplication(int & argc, char ** argv, bool isMirServer)
95 }
96 }
96 #endif
97 #endif
97
98
99+ new DebuggingController(this);
98
100
99 // Some hard-coded policy for now.
101 // Some hard-coded policy for now.
100 // NB: We don't support more than two screens at the moment
102 // NB: We don't support more than two screens at the moment
tests/uqmlscene/CMakeLists.txt+10−6
@@ -1,20 +1,23 @@
1add_executable(uqmlscene
1add_executable(uqmlscene
2 ${shellapplication_MOC_SRCS}
2 ${shellapplication_MOC_SRCS}
3 main.cpp
3 main.cpp
4+ ${CMAKE_SOURCE_DIR}/src/DebuggingController.cpp
4 )
5 )
5
6
6−qt5_use_modules(uqmlscene Qml Quick Test)
7+qt5_use_modules(uqmlscene Qml Quick Test DBus)
7pkg_check_modules(XCB REQUIRED xcb)
8pkg_check_modules(XCB REQUIRED xcb)
8
9
9include_directories(
10include_directories(
10− ${CMAKE_CURRENT_BINARY_DIR}
11+ SYSTEM
11− ${CMAKE_SOURCE_DIR}/src
12+ ${Qt5Quick_PRIVATE_INCLUDE_DIRS}
12− ${CMAKE_SOURCE_DIR}/libs/UbuntuGestures
13+ ${Qt5Gui_PRIVATE_INCLUDE_DIRS}
13)
14)
14
15
15include_directories(
16include_directories(
16− SYSTEM
17+ ${CMAKE_CURRENT_BINARY_DIR}
17− ${Qt5Gui_PRIVATE_INCLUDE_DIRS}
18+ ${CMAKE_SOURCE_DIR}/src
19+ ${CMAKE_SOURCE_DIR}/libs/UbuntuGestures
20+ ${libunity8-private_SOURCE_DIR}
18)
21)
19
22
20if (NOT "${XCB_INCLUDE_DIRS}" STREQUAL "")
23if (NOT "${XCB_INCLUDE_DIRS}" STREQUAL "")
@@ -26,6 +29,7 @@ target_link_libraries(uqmlscene
26 ${Qt5Quick_LIBRARIES}
29 ${Qt5Quick_LIBRARIES}
27 ${XCB_LDFLAGS}
30 ${XCB_LDFLAGS}
28 UbuntuGestures
31 UbuntuGestures
32+ unity8-private
29 )
33 )
30
34
31install(TARGETS uqmlscene
35install(TARGETS uqmlscene
tests/uqmlscene/main.cpp+4
@@ -63,6 +63,8 @@
63#include <QtCore/QTranslator>
63#include <QtCore/QTranslator>
64#include <QtCore/QLibraryInfo>
64#include <QtCore/QLibraryInfo>
65
65
66+#include "DebuggingController.h"
67+
66#ifdef QML_RUNTIME_TESTING
68#ifdef QML_RUNTIME_TESTING
67class RenderStatistics
69class RenderStatistics
68{
70{
@@ -466,6 +468,8 @@ int main(int argc, char ** argv)
466
468
467 int exitCode = 0;
469 int exitCode = 0;
468
470
471+ new DebuggingController(&app);
472+
469 if (!options.file.isEmpty()) {
473 if (!options.file.isEmpty()) {
470 if (!options.versionDetection || checkVersion(options.file)) {
474 if (!options.versionDetection || checkVersion(options.file)) {
471#ifndef QT_NO_TRANSLATION
475#ifndef QT_NO_TRANSLATION