07 March 2013

Debugging a slow KDE session.

KDE (from the Kubuntu repo) and all QT applications were slow as hell after an update so I set out to investigate:

The most obvious one to start with was kopete (sloooooooooooooow), so I straced (strace -s 500 -f kopete) and it hung on this:


11574 recvmsg(6, 0x7fffb90ddde0, MSG_CMSG_CLOEXEC) = -1 EAGAIN (Resource temporarily unavailable)
11574 sendmsg(6, {msg_name(0)=NULL, msg_iov(2)=[{"l\1\0\1\0\0\0\0\t\0\0\0o\0\0\0\1\1o\0\26\0\0\0/modules/networkstatus\0\0\6\1s\0\f\0\0\0org.kde.kded\0\0\0\0\2\1s\0\37\0\0\0org.kde.Solid.Networking.Client\0\3\1s\0\6\0\0\0status\0\0", 128}, {"", 0}], msg_controllen=0, msg_flags=0}, MSG_NOSIGNAL) = 128
11574 poll([{fd=6, events=POLLIN}], 1, 25000

It's hanging on handler 6, going up in the output I found what 6 is:

11368 socket(PF_FILE, SOCK_STREAM|SOCK_CLOEXEC, 0) = 6
11368 connect(6, {sa_family=AF_FILE, path=@"/tmp/dbus-TNffZVatPK"}, 23) = 0
11368 fcntl(6, F_GETFL)                 = 0x2 (flags O_RDWR)
11368 fcntl(6, F_SETFL, O_RDWR|O_NONBLOCK) = 0
11368 geteuid()                         = 1000
11368 getsockname(6, {sa_family=AF_FILE, NULL}, [2]) = 0

Right, so kopete is slow because it's waiting to receive something sent through dbus to kded.
Let's try to use dbus to contact kopete manually:


timothy@xps:~$ time qdbus org.kde.kopete                                         Error: org.freedesktop.DBus.Error.NoReply
Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.
real    0m25.018s
user    0m0.004s
sys     0m0.008s


It timed out, let's try it again:


timothy@xps:~$ time qdbus org.kde.kopete
/
/KDebug
/KIO
/KIO/Scheduler
/Kopete
/MainApplication
/ManagerIface_contact
/Statistics
/kopete
/kopete/MainWindow_1
/kopete/MainWindow_1/actions
/kopete/MainWindow_1/actions/settings_prefs
/kopete/MainWindow_1/actions/file_quit
/kopete/MainWindow_1/actions/settings_showmenubar
/kopete/MainWindow_1/actions/settings_showstatusbar
/kopete/MainWindow_1/actions/settings_keys
/kopete/MainWindow_1/actions/options_configure_toolbars
/kopete/MainWindow_1/actions/settings_notifications
/kopete/MainWindow_1/actions/AddGroup
/kopete/MainWindow_1/actions/contactSendMessage
/kopete/MainWindow_1/actions/contactStartChat
/kopete/MainWindow_1/actions/contactMove
/kopete/MainWindow_1/actions/contactCopy
/kopete/MainWindow_1/actions/makeMetaContact
/kopete/MainWindow_1/actions/contactRemove
/kopete/MainWindow_1/actions/contactSendEmail
/kopete/MainWindow_1/actions/contactSendFile
/kopete/MainWindow_1/actions/contactAddContact
/kopete/MainWindow_1/actions/contactAddTemporaryContact
/kopete/MainWindow_1/actions/contactProperties

real    0m3.720s
user    0m0.028s
sys     0m0.004s


So now it works. Consistent with what I'm experiencing in the KDE session right now.
Everything works, more or less, but it's all extremely slow.
Let's have a look at kded:


timothy@xps:~$ qdbus org.kde.kded
Error: org.freedesktop.DBus.Error.NoReply                                        Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.                         


I want to see what's kded's problem, let's look at it's status:


timothy@xps:~$ ps aux | grep kded
timothy  10298  0.0  0.3 793672 29280 ?        Sl   10:06   0:00 kdeinit4: kded4 [kdeinit]                     
timothy  10455  0.0  0.1 414756 11236 ?        Sl   10:06   0:00 kdeinit4: kio_trash [kdeinit] trash local:/tmp/ksocket-timothy/klauncherT10296.slave-socket local:/tmp/ksocket-timothy/kdeda10298.slave-socket
Sleeping eh, could be worse. Let's see what's it actually is doing/hanging on:
timothy@xps:~$ gdb kdeinit `pidof kded4`
[... lots of stuff...]
(gdb) bt
#0  0x00007f6aa1952023 in select () at ../sysdeps/unix/syscall-template.S:82
#1  0x00007f6aa2d99366 in qt_safe_select(int, fd_set*, fd_set*, fd_set*, timeval const*) () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#2  0x00007f6aa2d466da in ?? () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#3  0x00007f6aa2d47fab in ?? () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#4  0x00007f6aa2d0248e in QProcess::waitForFinished(int) () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#5  0x00007f6aa31def32 in KProcess::execute(int) () from /usr/lib/libkdecore.so.5
#6  0x00007f6a80f3f1a5 in ?? () from /usr/lib/kde4/kded_notificationhelper.so
#7  0x00007f6a80f3bca5 in ?? () from /usr/lib/kde4/kded_notificationhelper.so
#8  0x00007f6a80f39ad4 in ?? () from /usr/lib/kde4/kded_notificationhelper.so
#9  0x00007f6a80f39d24 in ?? () from /usr/lib/kde4/kded_notificationhelper.so
#10 0x00007f6aa2d86446 in QObject::event(QEvent*) () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#11 0x00007f6aa20ef894 in QApplicationPrivate::notify_helper(QObject*, QEvent*) () from /usr/lib/x86_64-linux-gnu/libQtGui.so.4
#12 0x00007f6aa20f4713 in QApplication::notify(QObject*, QEvent*) () from /usr/lib/x86_64-linux-gnu/libQtGui.so.4
#13 0x00007f6aa3b063f6 in KApplication::notify(QObject*, QEvent*) () from /usr/lib/libkdeui.so.5
#14 0x00007f6aa2d6ce9c in QCoreApplication::notifyInternal(QObject*, QEvent*) () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#15 0x00007f6aa2d70c6a in QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#16 0x00007f6aa2d9bf93 in ?? () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#17 0x00007f6a9ea5fd53 in g_main_context_dispatch () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#18 0x00007f6a9ea600a0 in ?? () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#19 0x00007f6a9ea60164 in g_main_context_iteration () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#20 0x00007f6aa2d9c3bf in QEventDispatcherGlib::processEvents(QFlags) ()
   from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#21 0x00007f6aa2197d5e in ?? () from /usr/lib/x86_64-linux-gnu/libQtGui.so.4
#22 0x00007f6aa2d6bc82 in QEventLoop::processEvents(QFlags) () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#23 0x00007f6aa2d6bed7 in QEventLoop::exec(QFlags) () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#24 0x00007f6aa2d70f67 in QCoreApplication::exec() () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#25 0x00007f6a8f4fde55 in kdemain () from /usr/lib/kde4/libkdeinit/libkdeinit4_kded4.so
#26 0x00000000004086a4 in _start ()
So we're in the kded_notificationhelper.so module. Let's see what I've got on my system mathing that name:

timothy@xps:~$ dpkg -l | grep "notification-helper"
ii  kubuntu-notification-helper            11.10ubuntu1                            Kubuntu system notification helper

Seems fishy.

timothy@xps:~$ apt-cache show kubuntu-notification-helper
Package: kubuntu-notification-helper
Priority: optional
Section: kde
Installed-Size: 212
Maintainer: Kubuntu Developers
Original-Maintainer: Jonathan Thomas
Architecture: amd64
Version: 11.10ubuntu1
Depends: libc6 (>= 2.4), libkdecore5 (>= 4:4.4.95), libkdeui5 (>= 4:4.4.0), libqt4-dbus (>= 4:4.5.3), libqtcore4 (>= 4:4.7.0~beta1), libqtgui4 (>= 4:4.5.3), libstdc++6 (>= 4.1.1), konsole | x-terminal-emulator, qapt-batch
Recommends: apport-kde | apport-gtk
Filename: pool/main/k/kubuntu-notification-helper/kubuntu-notification-helper_11.10ubuntu1_amd64.deb
Size: 38114
MD5sum: 0c6b775a0f78cbdb138149ea0e32b60b
SHA1: 2f2c37f9d16a094ac6f215c22c6cb558f6e5eada
SHA256: 8a96a2b822e825d3d56d7dcba732061576b690077bd73ff5ddcfd896192399bf
Description-en: Kubuntu system notification helper
 Kubuntu Notification Helper is a daemon that presents various notifications
 to the user. It uses the KDE Daemon system as a base and presents the
 notifications using the KDE Notification system. It also includes a
 System Settings module for configuring the daemon. Kubuntu Notification
 Helper is lightweight and fully integrated with KDE.
 .
 Current features include:
  - Notifications for Apport crashes.
  - Notifications for upgrade information, when available.
- Notifications for the availability restrictively-licensed packages.
  - Notifications for when upgrades require a reboot to complete.
  - All notifications can be hidden temporarily or permanently.
Homepage: https://launchpad.net/kubuntu-notification-helper
Description-md5: cfe41fe07651879c49f8ca54be0c1170
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Origin: Ubuntu
Supported: 5y
Task: kubuntu-desktop, kubuntu-full, kubuntu-active-desktop, kubuntu-active-full, kubuntu-active, edubuntu-desktop-kde

Ubuntu bloatware I can perfectly do without, check.

timothy@xps:~$ sudo apt-get remove --purge kubuntu-notification-helper
Reading package lists... Done
Building dependency tree     
Reading state information... Done
The following packages will be REMOVED:
  kubuntu-notification-helper*
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 217 kB disk space will be freed.
Do you want to continue [Y/n]?
(Reading database ... 296995 files and directories currently installed.)
Removing kubuntu-notification-helper ...

After a KDM restart everything is back to normal AND that annoying pop up 'there's are X software updates' thing is gone...