Merge lp:~dandrader/qtubuntu/betterSessionName into lp:qtubuntu

Proposed by Daniel d'Andrada
Status: Merged
Approved by: Gerry Boland
Approved revision: no longer in the source branch.
Merged at revision: 322
Proposed branch: lp:~dandrader/qtubuntu/betterSessionName
Merge into: lp:qtubuntu
Diff against target: 104 lines (+44/-8)
2 files modified
src/ubuntumirclient/integration.cpp (+40/-6)
src/ubuntumirclient/integration.h (+4/-2)
To merge this branch: bzr merge lp:~dandrader/qtubuntu/betterSessionName
Reviewer Review Type Date Requested Status
Unity8 CI Bot continuous-integration Approve
Gerry Boland (community) Approve
Review via email: mp+296198@code.launchpad.net

Commit message

Generate better mir session names

Try to come up with some meaningful session name to uniquely identify this session,
helping with shell debugging

Description of the change

Immensely helpful to help make sense of unity8.log when debugging multiple/nested prompt sessions use cases such as in bug 1586219.

To post a comment you must log in.
Revision history for this message
Unity8 CI Bot (unity8-ci-bot) wrote :

PASSED: Continuous integration, rev:317
https://unity8-jenkins.ubuntu.com/job/lp-qtubuntu-ci/63/
Executed test runs:
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build/1759
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-0-fetch/1785
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/1732
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial+overlay/1732
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-1-sourcepkg/release=yakkety/1732
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=vivid+overlay/1725
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=vivid+overlay/1725/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=xenial+overlay/1725
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=xenial+overlay/1725/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=yakkety/1725
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=yakkety/1725/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=vivid+overlay/1725
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=vivid+overlay/1725/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=xenial+overlay/1725
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=xenial+overlay/1725/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=yakkety/1725
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=yakkety/1725/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=vivid+overlay/1725
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=vivid+overlay/1725/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=xenial+overlay/1725
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=xenial+overlay/1725/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=yakkety/1725
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=yakkety/1725/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://unity8-jenkins.ubuntu.com/job/lp-qtubuntu-ci/63/rebuild

review: Approve (continuous-integration)
Revision history for this message
Nick Dedekind (nick-dedekind) :
Revision history for this message
Daniel d'Andrada (dandrader) wrote :

On 01/06/2016 09:48, Nick Dedekind wrote:
>> +QByteArray UbuntuClientIntegration::generateSessionName(QStringList &args)
>> >+{
> Perhaps use QApplication::applicationName first? I actually had a branch for this about a thousand years ago, but it never went anywhere.
>

QApplication::applicationName might not be set yet when
QPlatformIntegration is created (which is really early). It can be set
or even changed at any time by calling
QCoreApplicaiton::setApplicationName, and we would have not way of
updating your session id to follow those changes. So the only thing sure
to exist at QPlatformIntegration creation is the application arguments.

Revision history for this message
Gerry Boland (gerboland) wrote :

+for (int i = 0; i < args.count(); ++i) {
+ QString arg = args[i];
We have Q_FOREACH

Do you really need to read the FileInfo object? Why not just drop the ".qml" from the file name?

+ u_application_id_new_from_stringn(sessionName.data(), sessionName.count());
Does the api expect sessionName to always exist, or will it make a copy itself?

review: Needs Fixing
Revision history for this message
Daniel d'Andrada (dandrader) wrote :

On 01/06/2016 12:01, Gerry Boland wrote:
> Review: Needs Fixing
>
> +for (int i = 0; i < args.count(); ++i) {
> + QString arg = args[i];
> We have Q_FOREACH

I personally find this macro ugly, but if you fancy it...
But it is less code and thus less error prone. Done.

> Do you really need to read the FileInfo object? Why not just drop the ".qml" from the file name?
Yes. The argument could be a full file path like this:

/foo/bar/whatever/zumba.qml

Which would make for a cumbersome session name. QFileInfo neatly and
safely parses that filepath for me.

I like the ".qml" suffix as it tells us it's a plain qml app run via
qmlscene.

> + u_application_id_new_from_stringn(sessionName.data(), sessionName.count());
> Does the api expect sessionName to always exist, or will it make a copy itself?

It makes a copy. What a horrible API it would be otherwise.

Revision history for this message
Unity8 CI Bot (unity8-ci-bot) wrote :

PASSED: Continuous integration, rev:318
https://unity8-jenkins.ubuntu.com/job/lp-qtubuntu-ci/64/
Executed test runs:
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build/1762
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-0-fetch/1788
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/1735
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial+overlay/1735
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-1-sourcepkg/release=yakkety/1735
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=vivid+overlay/1728
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=vivid+overlay/1728/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=xenial+overlay/1728
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=xenial+overlay/1728/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=yakkety/1728
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=yakkety/1728/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=vivid+overlay/1728
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=vivid+overlay/1728/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=xenial+overlay/1728
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=xenial+overlay/1728/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=yakkety/1728
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=yakkety/1728/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=vivid+overlay/1728
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=vivid+overlay/1728/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=xenial+overlay/1728
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=xenial+overlay/1728/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=yakkety/1728
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=yakkety/1728/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://unity8-jenkins.ubuntu.com/job/lp-qtubuntu-ci/64/rebuild

review: Approve (continuous-integration)
Revision history for this message
Gerry Boland (gerboland) wrote :

> > Do you really need to read the FileInfo object? Why not just drop the ".qml"
> from the file name?
> Yes. The argument could be a full file path like this:
>
> /foo/bar/whatever/zumba.qml
>
> Which would make for a cumbersome session name. QFileInfo neatly and
> safely parses that filepath for me.
>
> I like the ".qml" suffix as it tells us it's a plain qml app run via
> qmlscene.

Yeah, that's ok. I just want to keep app startup light, using QFileInfo to parse a file name just strikes me as heavy for something that only those reading file logs will appreciate. But I won't block on that.

> > + u_application_id_new_from_stringn(sessionName.data(),
> sessionName.count());
> > Does the api expect sessionName to always exist, or will it make a copy
> itself?
>
> It makes a copy. What a horrible API it would be otherwise.

You never know :)

Revision history for this message
Daniel d'Andrada (dandrader) wrote :

On 01/06/2016 12:58, Gerry Boland wrote:
> Yeah, that's ok. I just want to keep app startup light, using QFileInfo to parse a file name just strikes me as heavy for something that only those reading file logs will appreciate. But I won't block on that.

QFileInfo creation looks pretty tame and lightweight. It pretty much
just stores the given filepath in a internal string.

The only real code we execute happens when we call QFileInfo::fileName,
where it essentially finds the last separator char in the string and
then "return m_filePath.mid(m_lastSeparator + 1);".

Revision history for this message
Gerry Boland (gerboland) wrote :

Ok, thanks for checking that. Change looks good to me!

review: Approve
322. By Daniel d'Andrada

Generate better mir session names

Try to come up with some meaningful session name to uniquely identify this session,
helping with shell debugging

Revision history for this message
Unity8 CI Bot (unity8-ci-bot) wrote :

PASSED: Continuous integration, rev:318
https://unity8-jenkins.ubuntu.com/job/lp-qtubuntu-ci/69/
Executed test runs:
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build/1818
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-0-fetch/1843
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/1784
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial+overlay/1784
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-1-sourcepkg/release=yakkety/1784
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=vivid+overlay/1774
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=vivid+overlay/1774/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=xenial+overlay/1774
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=xenial+overlay/1774/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=yakkety/1774
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=yakkety/1774/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=vivid+overlay/1774
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=vivid+overlay/1774/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=xenial+overlay/1774
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=xenial+overlay/1774/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=yakkety/1774
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=yakkety/1774/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=vivid+overlay/1774
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=vivid+overlay/1774/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=xenial+overlay/1774
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=xenial+overlay/1774/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=yakkety/1774
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=yakkety/1774/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://unity8-jenkins.ubuntu.com/job/lp-qtubuntu-ci/69/rebuild

review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/ubuntumirclient/integration.cpp'
--- src/ubuntumirclient/integration.cpp 2016-04-28 14:44:18 +0000
+++ src/ubuntumirclient/integration.cpp 2016-06-03 13:56:35 +0000
@@ -28,6 +28,7 @@
28#include "window.h"28#include "window.h"
2929
30// Qt30// Qt
31#include <QFileInfo>
31#include <QGuiApplication>32#include <QGuiApplication>
32#include <private/qguiapplication_p.h>33#include <private/qguiapplication_p.h>
33#include <qpa/qplatformnativeinterface.h>34#include <qpa/qplatformnativeinterface.h>
@@ -77,8 +78,12 @@
77 , mClipboard(new UbuntuClipboard)78 , mClipboard(new UbuntuClipboard)
78 , mScaleFactor(1.0)79 , mScaleFactor(1.0)
79{80{
80 setupOptions();81 {
81 setupDescription();82 QStringList args = QCoreApplication::arguments();
83 setupOptions(args);
84 QByteArray sessionName = generateSessionName(args);
85 setupDescription(sessionName);
86 }
8287
83 // Create new application instance88 // Create new application instance
84 mInstance = u_application_instance_new_from_description_with_options(mDesc, mOptions);89 mInstance = u_application_instance_new_from_description_with_options(mDesc, mOptions);
@@ -161,9 +166,8 @@
161 return mServices;166 return mServices;
162}167}
163168
164void UbuntuClientIntegration::setupOptions()169void UbuntuClientIntegration::setupOptions(QStringList &args)
165{170{
166 QStringList args = QCoreApplication::arguments();
167 int argc = args.size() + 1;171 int argc = args.size() + 1;
168 char **argv = new char*[argc];172 char **argv = new char*[argc];
169 for (int i = 0; i < argc - 1; i++)173 for (int i = 0; i < argc - 1; i++)
@@ -177,10 +181,11 @@
177 delete [] argv;181 delete [] argv;
178}182}
179183
180void UbuntuClientIntegration::setupDescription()184void UbuntuClientIntegration::setupDescription(QByteArray &sessionName)
181{185{
182 mDesc = u_application_description_new();186 mDesc = u_application_description_new();
183 UApplicationId* id = u_application_id_new_from_stringn("QtUbuntu", 8);187
188 UApplicationId* id = u_application_id_new_from_stringn(sessionName.data(), sessionName.count());
184 u_application_description_set_application_id(mDesc, id);189 u_application_description_set_application_id(mDesc, id);
185190
186 UApplicationLifecycleDelegate* delegate = u_application_lifecycle_delegate_new();191 UApplicationLifecycleDelegate* delegate = u_application_lifecycle_delegate_new();
@@ -190,6 +195,35 @@
190 u_application_description_set_application_lifecycle_delegate(mDesc, delegate);195 u_application_description_set_application_lifecycle_delegate(mDesc, delegate);
191}196}
192197
198QByteArray UbuntuClientIntegration::generateSessionName(QStringList &args)
199{
200 // Try to come up with some meaningful session name to uniquely identify this session,
201 // helping with shell debugging
202
203 if (args.count() == 0) {
204 return QByteArray("QtUbuntu");
205 } if (args[0].contains("qmlscene")) {
206 return generateSessionNameFromQmlFile(args);
207 } else {
208 // use the executable name
209 QFileInfo fileInfo(args[0]);
210 return fileInfo.fileName().toLocal8Bit();
211 }
212}
213
214QByteArray UbuntuClientIntegration::generateSessionNameFromQmlFile(QStringList &args)
215{
216 Q_FOREACH (QString arg, args) {
217 if (arg.endsWith(".qml")) {
218 QFileInfo fileInfo(arg);
219 return fileInfo.fileName().toLocal8Bit();
220 }
221 }
222
223 // give up
224 return "qmlscene";
225}
226
193QPlatformWindow* UbuntuClientIntegration::createPlatformWindow(QWindow* window) const227QPlatformWindow* UbuntuClientIntegration::createPlatformWindow(QWindow* window) const
194{228{
195 return const_cast<UbuntuClientIntegration*>(this)->createPlatformWindow(window);229 return const_cast<UbuntuClientIntegration*>(this)->createPlatformWindow(window);
196230
=== modified file 'src/ubuntumirclient/integration.h'
--- src/ubuntumirclient/integration.h 2016-04-28 14:09:54 +0000
+++ src/ubuntumirclient/integration.h 2016-06-03 13:56:35 +0000
@@ -76,8 +76,10 @@
76 void destroyScreen(UbuntuScreen *screen);76 void destroyScreen(UbuntuScreen *screen);
7777
78private:78private:
79 void setupOptions();79 void setupOptions(QStringList &args);
80 void setupDescription();80 void setupDescription(QByteArray &sessionName);
81 static QByteArray generateSessionName(QStringList &args);
82 static QByteArray generateSessionNameFromQmlFile(QStringList &args);
8183
82 UbuntuNativeInterface* mNativeInterface;84 UbuntuNativeInterface* mNativeInterface;
83 QPlatformFontDatabase* mFontDb;85 QPlatformFontDatabase* mFontDb;

Subscribers

People subscribed via source and target branches