Results 1 to 9 of 9

Thread: 100% CPU load

  1. #1
    Join Date
    Jan 2011
    Posts
    11
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Arrow 100% CPU load

    I started development on Debian 5.0.7, and now switched to Ubuntu 10.10. Qt installed 4.7.1.

    I'm using Qextserialport and after OS switch I found 100% cpu load. I checked with gprof and found this :

    Flat profile:

    Each sample counts as 0.01 seconds.
    % cumulative self self total
    time seconds seconds calls Ts/call Ts/call name
    60.00 0.06 0.06 QextSerialPort::qt_metacall(QMetaObject::Call, int, void**)
    40.00 0.10 0.04 QextSerialPort::qt_metacast(char const*)
    0.00 0.10 0.00 8642 0.00 0.00 QByteArray::size() const
    0.00 0.10 0.00 4850 0.00 0.00 qt_noop()
    0.00 0.10 0.00 4502 0.00 0.00 QByteArray::at(int) const
    0.00 0.10 0.00 1069 0.00 0.00 QBasicAtomicInt::deref()
    0.00 0.10 0.00 885 0.00 0.00 QString::~QString()
    Where to look and how to track the problem ?

  2. #2
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: 100% CPU load

    please, post your code
    A camel can go 14 days without drink,
    I can't!!!

  3. #3
    Join Date
    Jan 2011
    Posts
    11
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: 100% CPU load

    here is the main loop :
    Qt Code:
    1. void PortListener::tryReceive(){
    2. if(this->port->bytesAvailable()>0){
    3. timeout = qMax(100, timeout/2);
    4. // Thread unsafe block. Lock it
    5. qDebug() << "And 1";
    6. lock.lockForWrite();
    7. myRcvBuffer.clear();
    8. myRcvBuffer.append(port->readAll());
    9. qDebug() << "bytes read:" << myRcvBuffer.length();
    10. qDebug() << "bytes:" << myRcvBuffer;
    11. last_packet = Hemofenix_protocol::decode_packet(myRcvBuffer);
    12. lock.unlock();
    13. emit packet_received(last_packet);
    14. } else {
    15. timeout = qMin(1000, timeout*2);
    16. }
    17. QTimer::singleShot(timeout, this, SLOT(tryReceive()));
    18. }
    To copy to clipboard, switch view to plain text mode 
    For some reason this event fires only on mousemove/keypress. Any ideas how to debug that ?

  4. #4
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: 100% CPU load

    I have some observations.

    you should check if there are enough byte to read.

    instead of use QTimer::singleShot, use a QTimer instance and use setInterval and start.
    The static function creates a new connection at each call
    A camel can go 14 days without drink,
    I can't!!!

  5. The following user says thank you to mcosta for this useful post:

    kartun (24th February 2011)

  6. #5
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: 100% CPU load

    Also, you should be sure you actually have a problem in the first place. How are you measuring CPU usage? Are you sure the measurement is accurate? And what does it mean to say that the CPU is 100% active? CPUs only have one speed; they're either working or they're not, and if they are they're 100% busy.

    Are you seeing an actual slowdown in your application or in the system as a whole? If not, what is it youi're trying to improve?

    Note that all CPU measurement tools are inaccurate, and can measure very different things. The Windows performance monitor, for example, is notorious for giving essentially meaningless readings.

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: 100% CPU load

    Quote Originally Posted by SixDegrees View Post
    CPUs only have one speed; they're either working or they're not, and if they are they're 100% busy.
    That's not entirely accurate, they can run at different frequencies. And 100% for each frequency means a different load. So measuring percentages makes no sense. 100% cpu usage means the task is the only one occupying the cpu, it doesn't mean it is "saturating" the CPU as as SixDegrees noted the CPU is always saturated (or idle).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #7
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: 100% CPU load

    The percentage usually means the amount of instructions the processor handles at a given time interval with respect to the maximum it can perform in that time interval.

    Saying that the processor is either 100% idle or 100% busy is like saying that the chance of winning a lottery is 50%, you either win it, or you don't :-)

  9. #8
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: 100% CPU load

    Quote Originally Posted by tbscope View Post
    The percentage usually means the amount of instructions the processor handles at a given time interval with respect to the maximum it can perform in that time interval.

    Saying that the processor is either 100% idle or 100% busy is like saying that the chance of winning a lottery is 50%, you either win it, or you don't :-)
    True, but that's exactly the problem: sampling. How measurements like this are counted makes them vary widely, and without further information they are nearly useless. They certainly don't measure program efficiency in any way; when your process has the CPU, it has 100% of it. It may get switched out by other processes, but that's related to system load, not the performance of the particular program.

  10. #9
    Join Date
    Jan 2011
    Posts
    11
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Lightbulb Re: 100% CPU load

    Quote Originally Posted by SixDegrees View Post
    Also, you should be sure you actually have a problem in the first place. How are you measuring CPU usage?
    Are you seeing an actual slowdown in your application or in the system as a whole? If not, what is it youi're trying to improve?
    yes, I'm 100% sure. I've several keyboard handlers in the app, and without this loop response to keypress is immediate, but when this loop is running I've like 1.5 sec delay.
    I'm using standart gnome system monitor, and when this loop is active CPU load jumps to 100%, and after it stops it comes back to 0%.


    Added after 53 minutes:


    Seems I found a problem, may be it would help someone ...
    I was using
    Qt Code:
    1. this->port = new QextSerialPort(portName, QextSerialPort::EventDriven);
    To copy to clipboard, switch view to plain text mode 
    as it was suggested in included "PortListener" example. I switched to
    Qt Code:
    1. this->port = new QextSerialPort(portName, QextSerialPort::Polling);
    To copy to clipboard, switch view to plain text mode 
    and CPU usage dropped to expected 2-3%.

    I tested it on Ubuntu 10.10 (2.6.35-25-generic #44-Ubuntu SMP) and Debian 5.0.7 (2.6.29 with Vortex86DX patch)

    p.s. Using QTimer member instead of static QTimer::singleShot doesn't give any noticable difference. And thanks to everyone who tried to help
    Last edited by kartun; 24th February 2011 at 07:11.

Similar Threads

  1. DLL won't load
    By waynew in forum Qt Programming
    Replies: 8
    Last Post: 25th October 2010, 01:48
  2. Load QPixmap
    By jano_alex_es in forum Qt for Embedded and Mobile
    Replies: 3
    Last Post: 10th June 2010, 08:44
  3. Load dll on Symbian
    By hubbobubbo in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 9th February 2010, 14:08
  4. Qt4 does not load JPG's.
    By Teuniz in forum Qt Programming
    Replies: 3
    Last Post: 3rd September 2007, 23:06

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.