Almost unusuable while non-Ubuntu device connected through adb

Bug #1456627 reported by Florian W.
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
qtcreator-plugin-ubuntu (Ubuntu)
Fix Released
Medium
Benjamin Zeller

Bug Description

I'm using qtcreator-plugin-ubuntu 3.1.1+15.10.20150508-0ubuntu1i~0trusty1 from the Trusty PPA.

I'm currently porting my Ubuntu App to Android, so I have my android phone connected to my computer using USB.

A few days ago I noticed that qtcreator started using a complete CPU core soon after startup, which makes working with qtcreator quite unpleasant (sluggish interface, and CPU fan noise). After some time (30 minutes?), it is then no longer possible to start a build process in qtcreator for what appears to be a strange reason. I no longer have the error message. I guess this is because of some kind of ressource leak.

Now I noticed these popping up in ps aux quite frequently while it happens:
> x 10209 8.0 0.0 19696 2972 ? S 14:57 0:00 /bin/bash /usr/share/qtcreator/ubuntu/scripts/device_version 007692f760d6239b
> x 10233 0.0 0.0 19696 304 ? S 14:57 0:00 /bin/bash /usr/share/qtcreator/ubuntu/scripts/device_version 007692f760d6239b
> x 10234 0.0 0.0 19696 1888 ? S 14:57 0:00 /bin/bash /usr/share/qtcreator/ubuntu/scripts/device_version 007692f760d6239b

And this test shows that something, probably qtcreator, is forking almost 30 times per second:
$ while true; do ps aux | grep OnlyFindGrepItself; sleep 10; done
> x 10841 0.0 0.0 18980 2152 pts/0 S+ 14:58 0:00 grep --color=auto OnlyFindGrepItself
> x 11132 0.0 0.0 18980 2152 pts/0 S+ 14:58 0:00 grep --color=auto OnlyFindGrepItself
> x 11406 0.0 0.0 18980 2152 pts/0 R+ 14:58 0:00 grep --color=auto OnlyFindGrepItself

As soon as I disconnect my android device from the USB port, the CPU fan goes silent and there's no significant CPU usage any more.

So I guess that something in the qt creator Ubuntu plugin tries to detect my android phone as an Ubuntu device, fails, and then instantly tries again.

This is from qtcreator strace and repeats quite often as well: read(36, "/system/bin/sh: chroot: not found\r\n", 35) = 35
Looks like something is trying to use chroot on my phone, and my Android lollipop can't do that. So the device_version script might not be the only thing that keeps my system busy.

Related branches

Revision history for this message
Florian W. (florian-will) wrote :

While this happened all the time in the last few days, I now did something that apparently made it stop (temporarily?).

Maybe deleting the device from the Devices view in Ubuntu SDK? It re-appeared quickly, but maybe that stopped it. Maybe it's important that the same device (Nexus 4) has been used with the Ubuntu OS instead of Android before, using the Dual-Boot mechanism.

Revision history for this message
Zoltan Balogh (bzoltan) wrote :

First of all, thanks for this report.

I try to corner all the issues you mention, butr first let's sort out few things:

1) "qtcreator started using a complete CPU core soon after startup"

What CPU and how much memory do you have on that device? Were you monitoring during that "hanging" period what else was going on in your system? Anyhow, QtCreator is a big and heavy application, it is not free from bugs. If we find a resource leak, we will follow it up with the upstream developer. Please note that QtCreator is downstreamed product of the QtCompany

2) about the device_version
If you check the /usr/share/qtcreator/ubuntu/scripts/device_version script it does very little. It barely executes more than 6 simple commands to figure out about the attached device. It does not use much CPU or any system resources. In your case it got confused because your android device had the same ID as the earlier registered Ubuntu device (due to the dual boot). Anyhow the SDK tries three times to discover the attached device and then it gives up.

3) About OnlyFindGrepItself
Sorry my ignorance, but I am not a kernel guru. How does that script proves that the qtcreator is forking 30 times a second? I would ps the qtcreator process and follow if the PID is changing. The fact that the grep gets higher PID number at each run is the business of the kernel. I doubt that it indicates any problem with the QtCreator. But I would be happy to learn about this case more if you would give some details.

One thing is for sure, that the SDK gets confused with that dual bootable Ubuntu/Android device and we will invstigate this use case and push out a fix very soon. But we need mpore information about the CPU load issue as with the given information I can only see it as a momentary stability issue of a tool what our SDK uses. It is very unlikely that this problem was caused by the qtcreator-plugin-ubuntu plugin.

Changed in qtcreator-plugin-ubuntu (Ubuntu):
status: New → Incomplete
importance: Undecided → Medium
assignee: nobody → Zoltan Balogh (bzoltan)
Revision history for this message
Florian W. (florian-will) wrote :
Download full text (4.5 KiB)

Thanks for your important questions, Zoltan!

> What CPU and how much memory do you have on that device?

It's an old AMD Phenom II X4 955 BE. Still, qt creator usually needs much less than one full core when just editing code files and generally works quite well. I have 8GB of memory.

> Were you monitoring during that "hanging" period what else was going on in your system?

I looked at "top" and found that qtcreator uses 99% (out of 400% theoretically possible with my 4 core CPU).

No monitoring other than that, but I reproduced the issue again. There are two different /usr/share/qtcreator/ubuntu/scripts/device_version processes running right now, and in total I counted more than 3 of them since I started ubuntu-sdk. At least that's what I assume, I've repeatedly called ps aux | grep script and each time, there are a few of them active and they have new PIDs each time.

> Anyhow, QtCreator is a big and heavy application, it is not free from bugs. If we find a resource leak, we will follow it up with the upstream developer.

It's working quite nicely when I don't have my Android phone attached via USB, so I don't think it's an upstream bug. Also worked fine when I attached my phone with Ubuntu booted on it.

> [The device_version script] does not use much CPU or any system resources. In your case it got confused because your android device had the same ID as the earlier registered Ubuntu device (due to the dual boot). Anyhow the SDK tries three times to discover the attached device and then it gives up.

Yeah, the script itself seems to be relatively lightweight. However it's executed in what appears to be an infinite loop on my system. So the "three attempts" limit might not work correctly?

> Sorry my ignorance, but I am not a kernel guru. How does that script proves that the qtcreator is forking 30 times a second?

Sorry, my post was not even close to clear enough about that. AFAIK the shell command shows that there were ~300 new processes spawned within the 10 seconds sleep period, because the PID of each grep call was incremented by ~300 compared to the last grep. AFAIK, PIDs are chosen incrementally, so each new process gets a PID of $lastPID+1, unless that PID is already in use. So a "grep, wait 10 seconds, grep" sequence should show that both grep PIDs are pretty similar on my relatively calm desktop system. A difference of 300 between both PIDs tells me that my system spawned 300 processes in 10 seconds. Since top shows nothing unusual other than 99% qtcreator CPU usage, I assumed that most of the 300 processes were spawned by qtcreator (I suspect: by the qtcreator ubuntu plugin).

I have now disconnected my phone from USB. top shows that qtcreator is now down to 0.0%, but takes up 30% of my memory (ps shows RSS 2468524 – 2.4G, this might indicate a leak? Can't remember what qtcreator memory usage is normal after 30 mins of idling in the background.).

Now let me repeat that command:
$ while true; do ps aux | grep OnlyFindGrepItself; sleep 10; done
x 6171 0.0 0.0 18980 2136 pts/0 S+ 21:23 0:00 grep --color=auto OnlyFindGrepItself
x 6174 0.0 0.0 18980 2192 pts/0 S+ 21:23 0:00 grep --color=auto OnlyF...

Read more...

Revision history for this message
Florian W. (florian-will) wrote :

Well, sorry for the long post. %) I think I found the bug.

Anyway, is it possible that…
http://bazaar.launchpad.net/~ubuntu-branches/ubuntu/wily/qtcreator-plugin-ubuntu/wily/view/head:/src/ubuntu/ubuntudevice.cpp

In line 209 or 216, the condition is true because my device is not an Ubuntu device. So m_errorCount is incremented and detect() is called. detect() is an alias for detectDeviceVersion().

So detectDeviceVersion() calls startProcess() again, i.e. the script is instantly invoked again after a failure.

processFinished() then has the check for "maximum of 3 attempts" (line 165), but if the exit code of the process is 0, the m_errorCount is reset to 0. (BTW, there's also a Q_UNUSED macro in processFinished() that can probably be removed?) And…

$ /usr/share/qtcreator/ubuntu/scripts/device_version 007692f760d6239b
/system/bin/sh: chroot: not found
/system/bin/sh: chroot: not found
/system/bin/sh: chroot: not found
/system/bin/sh: chroot: not found
$ echo $?
0

So in my case, the m_errorCount is probably set to 0 after each device_version execution. And that probably explains the "infinite loop"-style behaviour I observed.

It's interesting to see that my system hardly manages to execute the script more than once per second. I added
echo $(date) >> /tmp/log
to see how often it's called. I guess that spawning a new shell process (bash in my case) is rather slow. :-)

Revision history for this message
Benjamin Zeller (zeller-benjamin) wrote :

That was a nice find.
Can you check the device log output on the devices page and paste the contents?

Revision history for this message
Zoltan Balogh (bzoltan) wrote :

Floran, that is a brilliant catch! Thank you a bunch. We push out a quick update to fix this bug.

Changed in qtcreator-plugin-ubuntu (Ubuntu):
status: Incomplete → Triaged
Revision history for this message
Florian W. (florian-will) wrote :

> Can you check the device log output on the devices page and paste the contents?

Here's the log after a minute or so (protocol fault at the bottom => I disconnected the device to copy the log):
http://paste.ubuntu.com/11242404/

I didn't think of checking the log earlier. Probably the first thing I should have checked!

> We push out a quick update to fix this bug.

Thanks a lot :-)

Revision history for this message
Florian W. (florian-will) wrote :

Ah, if the log steadily grows and is never truncated, that might have caused the increasing CPU usage for rendering the log, and increasing memory usage as well. I still wonder why the spawning of new processes fails after some time though.

Changed in qtcreator-plugin-ubuntu (Ubuntu):
assignee: Zoltan Balogh (bzoltan) → Benjamin Zeller (zeller-benjamin)
status: Triaged → In Progress
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package qtcreator-plugin-ubuntu - 3.1.1+15.10.20150616-0ubuntu1

---------------
qtcreator-plugin-ubuntu (3.1.1+15.10.20150616-0ubuntu1) wily; urgency=medium

  [ Benjamin Zeller ]
  * Fix Bug lp:1362028 "SDK not able to provide further hint about
    missing apparmor policy" (LP: #1362028)
  * Fix Bug lp:1455566 "ubuntu sdk references obsolete system-image
    channel names" (LP: #1455566)
  * Fix bug lp:1456627 "Almost unusuable while non-Ubuntu device
    connected through adb" (LP: #1456627)

  [ Marcus Tomlinson ]
  * Split scope template into "14.10" and "Current" variations (LP:
    #1464108)

  [ Nicholas Skaggs ]
  * Update qml based templates to best practicies

  [ Niklas Wenzel ]
  * Allow parallel builds using "dpkg-buildpackage -jN", reducing build
    time on multi-core CPUs (LP: #1465018)
  * Fix building translations (LP: #1257313)

  [ nskaggs ]
  * Update qml based templates to best practicies

 -- CI Train Bot <email address hidden> Tue, 16 Jun 2015 14:48:19 +0000

Changed in qtcreator-plugin-ubuntu (Ubuntu):
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.