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.9k 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on 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
    2
    • SGaistS SGaist

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

      H Offline
      H Offline
      Hiloshi
      wrote on 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
      • SGaistS SGaist

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

        H Offline
        H Offline
        Hiloshi
        wrote on 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
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on 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
          2
          • SGaistS SGaist

            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 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
            0
            • H Hiloshi

              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 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
              2
              • K Offline
                K Offline
                kuzulis
                Qt Champions 2020
                wrote on 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
                2
                • jsulmJ jsulm

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

                  H Offline
                  H Offline
                  Hiloshi
                  wrote on 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
                    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 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 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 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 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