on xenial help sign in
Add a D-Bus interface to control some debug facilities on the fly

Approved by: Gerry Boland, Unity8 CI Bot

commit2f3e8af1507b5b00d711b1f2349d04152890c216 authorMichael Zanetti <michael.zanetti@canonical.com> dateTue 10 Jan 2017, 14:43 (10 years ago) parent0a7a1de3db2cc7
7 files changed+198−8
CODING+24 src/CMakeLists.txt+9−2 src/DebuggingController.cpp+92 src/DebuggingController.h+57 src/ShellApplication.cpp+2 tests/uqmlscene/CMakeLists.txt+10−6 tests/uqmlscene/main.cpp+4
CODING+24
@@ -162,3 +162,27 @@ $ PYTHONPATH=../tests/autopilot autopilot3 run unity8.some.very.long.test.name
162162or run them all with
163163
164164$ 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+
13pkg_check_modules(CONNECTIVITY REQUIRED connectivity-qt1)
24
35include_directories(
46 SYSTEM
57 ${Qt5Gui_PRIVATE_INCLUDE_DIRS}
8+ ${Qt5Quick_PRIVATE_INCLUDE_DIRS}
69 ${CONNECTIVITY_INCLUDE_DIRS}
710)
811
12+include_directories(
13+ ${libunity8-private_SOURCE_DIR}
14+)
15+
916file(GLOB_RECURSE QML_FILES
1017 ${CMAKE_SOURCE_DIR}/qml/*
1118 ${CMAKE_SOURCE_DIR}/tests/*.qml
@@ -25,6 +32,7 @@ set(SOURCE_FILES
2532 ShellView.cpp
2633 UnityCommandLineParser.cpp
2734 UnixSignalHandler.cpp
35+ DebuggingController.cpp
2836 ${QML_FILES} # This is to make qml and image files appear in the IDE's project tree
2937)
3038
@@ -39,7 +47,7 @@ qt5_use_modules(${SHELL_APP} DBus Gui Qml Quick Test)
3947if (NOT "${ANDROID_PROPERTIES_INCLUDE_DIRS}" STREQUAL "")
4048 set_target_properties(${SHELL_APP} PROPERTIES INCLUDE_DIRECTORIES ${ANDROID_PROPERTIES_INCLUDE_DIRS})
4149endif()
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)
4351
4452if (ENABLE_TOUCH_EMULATION)
4553 target_link_libraries(${SHELL_APP} ${MOUSETOUCHADAPTOR_LIBS_LDFLAGS})
@@ -52,4 +60,3 @@ install(TARGETS ${SHELL_APP}
5260
5361add_subdirectory(Panel)
5462add_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 @@
3030#include <paths.h>
3131#include "CachingNetworkManagerFactory.h"
3232#include "UnityCommandLineParser.h"
33+#include "DebuggingController.h"
3334
3435ShellApplication::ShellApplication(int & argc, char ** argv, bool isMirServer)
3536 : QGuiApplication(argc, argv)
@@ -95,6 +96,7 @@ ShellApplication::ShellApplication(int & argc, char ** argv, bool isMirServer)
9596 }
9697 #endif
9798
99+ new DebuggingController(this);
98100
99101 // Some hard-coded policy for now.
100102 // NB: We don't support more than two screens at the moment
tests/uqmlscene/CMakeLists.txt+10−6
@@ -1,20 +1,23 @@
11add_executable(uqmlscene
22 ${shellapplication_MOC_SRCS}
33 main.cpp
4+ ${CMAKE_SOURCE_DIR}/src/DebuggingController.cpp
45 )
56
6−qt5_use_modules(uqmlscene Qml Quick Test)
7+qt5_use_modules(uqmlscene Qml Quick Test DBus)
78pkg_check_modules(XCB REQUIRED xcb)
89
910include_directories(
10− ${CMAKE_CURRENT_BINARY_DIR}
11− ${CMAKE_SOURCE_DIR}/src
12− ${CMAKE_SOURCE_DIR}/libs/UbuntuGestures
11+ SYSTEM
12+ ${Qt5Quick_PRIVATE_INCLUDE_DIRS}
13+ ${Qt5Gui_PRIVATE_INCLUDE_DIRS}
1314)
1415
1516include_directories(
16− SYSTEM
17− ${Qt5Gui_PRIVATE_INCLUDE_DIRS}
17+ ${CMAKE_CURRENT_BINARY_DIR}
18+ ${CMAKE_SOURCE_DIR}/src
19+ ${CMAKE_SOURCE_DIR}/libs/UbuntuGestures
20+ ${libunity8-private_SOURCE_DIR}
1821)
1922
2023if (NOT "${XCB_INCLUDE_DIRS}" STREQUAL "")
@@ -26,6 +29,7 @@ target_link_libraries(uqmlscene
2629 ${Qt5Quick_LIBRARIES}
2730 ${XCB_LDFLAGS}
2831 UbuntuGestures
32+ unity8-private
2933 )
3034
3135install(TARGETS uqmlscene
tests/uqmlscene/main.cpp+4
@@ -63,6 +63,8 @@
6363#include <QtCore/QTranslator>
6464#include <QtCore/QLibraryInfo>
6565
66+#include "DebuggingController.h"
67+
6668#ifdef QML_RUNTIME_TESTING
6769class RenderStatistics
6870{
@@ -466,6 +468,8 @@ int main(int argc, char ** argv)
466468
467469 int exitCode = 0;
468470
471+ new DebuggingController(&app);
472+
469473 if (!options.file.isEmpty()) {
470474 if (!options.versionDetection || checkVersion(options.file)) {
471475#ifndef QT_NO_TRANSLATION