Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Why CPU usage increase to 100% ?
Forum Updated to NodeBB v4.3 + New Features

Why CPU usage increase to 100% ?

Scheduled Pinned Locked Moved Mobile and Embedded
15 Posts 4 Posters 5.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Hiloshi
    wrote on 17 Jun 2017, 14:26 last edited by
    #1

    Dear Sirs,

    I use RPi3 to run a qt project, basically use UART to collect data as below:

    void MainWindow::UART_Receiver2()
    {
    
        UART_Read_Buffer = UART_Read_Buffer + serial->readAll().toHex();  //QByteArray
    
        if(UART_Read_Buffer.count()>63)
        {
        //--------------------------------------------    
            elapse_time++;
            QString s = QString::number(elapse_time);  
            Mychart->axisX()->setTitleText(s);
        //-------------------------------------------
            UART_Read_Buffer.clear();
        }
    }
    

    At beginning I also use QChar,QChartView and QSplineSeries to draw diagram, however I found that the CPU usage too high, so I remove almost everything just leave UART as above.
    However, CPU usage still increase from 6% to 100% in 20 minutes.

    Any idea what cause this situation ?

    PS. I use pidstat to monitor the CPU usage, everyone can download the log file from:https://www.dropbox.com/s/r7t0256jm4vfe4j/cpustat.txt?dl=0

    Any suggestion will very appreciate~

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 17 Jun 2017, 23:10 last edited by
      #2

      Hi,

      How fast are you getting these data ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      H 1 Reply Last reply 18 Jun 2017, 09:37
      2
      • S SGaist
        17 Jun 2017, 23:10

        Hi,

        How fast are you getting these data ?

        H Offline
        H Offline
        Hiloshi
        wrote on 18 Jun 2017, 09:37 last edited by Hiloshi
        #3

        Dear @SGaist ,

        Baud rate is 115200, the sensor will send 32bytes data to RPi3 for every 800ms automatically.

        Thanks,

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 18 Jun 2017, 20:33 last edited by
          #4

          Doesn't looks like that's the culprit then. What else are you doing with that application ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          H 2 Replies Last reply 19 Jun 2017, 01:04
          2
          • S SGaist
            18 Jun 2017, 20:33

            Doesn't looks like that's the culprit then. What else are you doing with that application ?

            H Offline
            H Offline
            Hiloshi
            wrote on 19 Jun 2017, 01:04 last edited by
            #5

            Dear @SGaist ,

            It should be nothing else in the application. But in order to make sure everything is under control, I will make a new project and put UART communication only then test again.

            Thanks,

            1 Reply Last reply
            1
            • S SGaist
              18 Jun 2017, 20:33

              Doesn't looks like that's the culprit then. What else are you doing with that application ?

              H Offline
              H Offline
              Hiloshi
              wrote on 19 Jun 2017, 15:55 last edited by
              #6

              Dear @SGaist ,

              I create a new project for the test: https://github.com/hiloshi/CPUTest , I still see the CPU usage increase to 100%.
              The CPU usage is https://www.dropbox.com/s/ki42n1ee32vi7r5/UARTCPU.txt?dl=0

              If I only add UART, the CPU usage will not exceed 1%, however, after I add QChart,QSplineSeries,etc.
              (Line 38-63: CPUTest/mainwindow.cpp )
              The CPU usage start increase, even I only do axisX()->setTitleText(s), not really draw curve.

              Is there something wrong with "Mychart->axisX()->setTitleText(s);" ?
              or shouldn't draw "QChart" inside the UART slot ?

              Any suggestions would be very appreciate~

              1 Reply Last reply
              1
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 19 Jun 2017, 22:33 last edited by
                #7

                You should try to profile your application in order to determine where the hop spots are in your application.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                H 1 Reply Last reply 20 Jun 2017, 02:31
                2
                • S SGaist
                  19 Jun 2017, 22:33

                  You should try to profile your application in order to determine where the hop spots are in your application.

                  H Offline
                  H Offline
                  Hiloshi
                  wrote on 20 Jun 2017, 02:31 last edited by
                  #8

                  Dear @SGaist ,

                  When MainWindow create, system will also new a serialport instance and connect to UART receiver:

                  serial = new QSerialPort(this);
                  connect(serial, &QSerialPort::readyRead, this, &MainWindow::UART_Receiver2);
                  

                  Then I put two widget on the mainwindow by QTCreater, one is pushbutton, another is tabWidget.
                  Inside the pushbutton, two major task will be done:

                  1. UART initialize (ttyUSB0, 115200/8N1N)
                  2. QSplineSeries, QSplineSeries and QChartView initialize. then put this QChartView to a new tab,
                   MyvLayout->addWidget(MychartView);
                   Mywidget->setLayout(MyvLayout);
                  ui->tabWidget->addTab(Mywidget,"Chart");
                  

                  In the meanwhile, tab3 will be generated and show a blank diagram.
                  System waiting UART input, sensor will output 32byes data to RPi3 every 800ms.

                  Inside the UART Receive slot is:

                  
                      UART_Read_Buffer = UART_Read_Buffer + serial->readAll().toHex();
                  
                      if(UART_Read_Buffer.count()>63)
                      {
                  
                      //--------------------------------------------   
                          elapse_time++;
                          QString s = QString::number(elapse_time);        
                          Mychart->axisX()->setTitleText(s);    
                      //-------------------------------------------
                          UART_Read_Buffer.clear();
                  }
                  

                  System will keep receive data, I will show numbers of received data and display on axisX().
                  Therefore, this value will increase by 1 after every 32bytes.

                  Then I can monitor the CPU usage increase to 100%.

                  If comment out Mychart->axisX()->setTitleText(s); , the CPU usage will not keep increase.
                  So I think maybe there are something wrong with the way I use QChartView.

                  Any help will be appreciate,

                  jsulmJ 1 Reply Last reply 20 Jun 2017, 04:56
                  0
                  • H Hiloshi
                    20 Jun 2017, 02:31

                    Dear @SGaist ,

                    When MainWindow create, system will also new a serialport instance and connect to UART receiver:

                    serial = new QSerialPort(this);
                    connect(serial, &QSerialPort::readyRead, this, &MainWindow::UART_Receiver2);
                    

                    Then I put two widget on the mainwindow by QTCreater, one is pushbutton, another is tabWidget.
                    Inside the pushbutton, two major task will be done:

                    1. UART initialize (ttyUSB0, 115200/8N1N)
                    2. QSplineSeries, QSplineSeries and QChartView initialize. then put this QChartView to a new tab,
                     MyvLayout->addWidget(MychartView);
                     Mywidget->setLayout(MyvLayout);
                    ui->tabWidget->addTab(Mywidget,"Chart");
                    

                    In the meanwhile, tab3 will be generated and show a blank diagram.
                    System waiting UART input, sensor will output 32byes data to RPi3 every 800ms.

                    Inside the UART Receive slot is:

                    
                        UART_Read_Buffer = UART_Read_Buffer + serial->readAll().toHex();
                    
                        if(UART_Read_Buffer.count()>63)
                        {
                    
                        //--------------------------------------------   
                            elapse_time++;
                            QString s = QString::number(elapse_time);        
                            Mychart->axisX()->setTitleText(s);    
                        //-------------------------------------------
                            UART_Read_Buffer.clear();
                    }
                    

                    System will keep receive data, I will show numbers of received data and display on axisX().
                    Therefore, this value will increase by 1 after every 32bytes.

                    Then I can monitor the CPU usage increase to 100%.

                    If comment out Mychart->axisX()->setTitleText(s); , the CPU usage will not keep increase.
                    So I think maybe there are something wrong with the way I use QChartView.

                    Any help will be appreciate,

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on 20 Jun 2017, 04:56 last edited by
                    #9

                    @Hiloshi You could try to increase less often - for example after every 128 bytes.

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    H 1 Reply Last reply 20 Jun 2017, 15:21
                    2
                    • K Offline
                      K Offline
                      kuzulis
                      Qt Champions 2020
                      wrote on 20 Jun 2017, 08:06 last edited by
                      #10
                      1. Just do not use QtCharts, use Qwt instead and you will be surprised with performance changing.
                      2. Do not use UART_Read_Buffer, because data already buffered inside of QSP (just use serial->bytesAvailable() to know how much data ready for read).

                      PS: You can simplify the MainWindow::UART_Receiver2 slot:

                      void MainWindow::UART_Receiver2()
                      {
                          QByteArray dummy = serial->readAll();
                      }
                      

                      to check, how much CPU usage will be in this case..

                      H 1 Reply Last reply 20 Jun 2017, 15:25
                      2
                      • jsulmJ jsulm
                        20 Jun 2017, 04:56

                        @Hiloshi You could try to increase less often - for example after every 128 bytes.

                        H Offline
                        H Offline
                        Hiloshi
                        wrote on 20 Jun 2017, 15:21 last edited by
                        #11

                        Dear @jsulm ,

                        Thank you very much.

                        I change 128 to decrease draw speed of the QChart. The result is become 65minutes to 100%.
                        https://www.dropbox.com/s/dmi8d84p48qjug1/UARTCPU2.txt?dl=0

                        Hmmm....

                        1 Reply Last reply
                        0
                        • K kuzulis
                          20 Jun 2017, 08:06
                          1. Just do not use QtCharts, use Qwt instead and you will be surprised with performance changing.
                          2. Do not use UART_Read_Buffer, because data already buffered inside of QSP (just use serial->bytesAvailable() to know how much data ready for read).

                          PS: You can simplify the MainWindow::UART_Receiver2 slot:

                          void MainWindow::UART_Receiver2()
                          {
                              QByteArray dummy = serial->readAll();
                          }
                          

                          to check, how much CPU usage will be in this case..

                          H Offline
                          H Offline
                          Hiloshi
                          wrote on 20 Jun 2017, 15:25 last edited by
                          #12

                          Dear @kuzulis ,

                          Thanks for the suggestions, I will test Qwt and change uart read method.

                          I was wondering why CPU usage keep increase. Even if QChart spend 60% CPU power, it should not keep increase to 100%, isn't it ?

                          1 Reply Last reply
                          0
                          • K Offline
                            K Offline
                            kuzulis
                            Qt Champions 2020
                            wrote on 21 Jun 2017, 05:16 last edited by kuzulis
                            #13

                            Even if QChart spend 60% CPU power, it should not keep increase to 100%, isn't it ?

                            Try to do tests without of QtCharts, just with pure UART_Receiver2 slot(), as I wrote before, to look on CPU loading. And then, try to add something other code...

                            PS: QtCharts - is a bad choose, as it is too slow and also consume many CPU resources. F.e. from my experience, with Qwt I have ~4-5% CPU loading, but with QtCharts I have ~20-50% CPU loading. And I have similar proportions in RAM consuming - QtCharts eat a RAM in ~5-10 times more than Qwt. Besides, has a memory leaks...

                            1 Reply Last reply
                            1
                            • H Offline
                              H Offline
                              Hiloshi
                              wrote on 21 Jun 2017, 15:08 last edited by
                              #14

                              Dear @kuzulis ,

                              I make some test as below:

                              1. RPi3+Debian+QSerialPort(800ms)+QTabWidget+QChart-->20mins to 100%
                              2. RPi3+Debian+QSerialPort(800ms)+QChart -->about 20mins to 100%
                              3. RPi3+Debian+QTimer(1000ms)+QChart --> 35ms to 100%
                              4. Corei5+WIN8+QTimer(1000ms)+QChart--> test over 1hr under 20%

                              My conclusion in the rough is QChart maybe has something wrong on Armv7 or debian....

                              I will continue to test Qwt.

                              1 Reply Last reply
                              0
                              • H Offline
                                H Offline
                                Hiloshi
                                wrote on 15 Jul 2017, 15:24 last edited by
                                #15

                                Dear @kuzulis ,

                                After testing Qwt for the same project, the CPU usage stable under 3%.
                                It is huge difference compare to the QChart performance.

                                Thanks for the suggestion.

                                1 Reply Last reply
                                0

                                • Login

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • Users
                                • Groups
                                • Search
                                • Get Qt Extensions
                                • Unsolved