Important: Please read the Qt Code of Conduct -

CPU usage is too high with update()

  • Hi Friends

    I'm working on an embedded linux QT 4.7.3 video application.

    I have a video widget which is nothing but a pixmap holder and it paints the continuous feed of images which looks like a video widget to user. I'm painting my video widget @30 fps (in approx 33 msec) with a call to QWidget::update() method.

    Everything is working fine as I want. But the CPU usage is tooooo high for my QT application. I ran the 'very sleepy' tool and "here is the output of a sample" []

    ! sleepy sample)!

    From the sample its obvious that Qt4 libraries uses 80% of CPU time.

    Can you please suggest me to reduce the CPU usage ?

  • what images are you painting
    what is the format and pixel density

  • Thank you for your reply.

    I'm creating a QImage->QPixmap from the image data I got from my cam
    I'm not sure about the image format and density but I get the feed from the camera using the h263/h264 codec

    And from the very sleepy data I'm not sure why QGraphicsView::QGraphicsView:() and QFutureInterfaceBase::isRunning() is taking so much time, where I'm not calling them explicitly.

  • JPEG is a compressed image format
    if you are handling conversion of high pixel density to/from raw
    processor load is implicit

  • ^I have updated the previous post with image format. And note that the image creation and processing it from the camera feed does not take too much CPU but the paint takes huge chunk of it.

    If I only comment the line with [QWidget::]update(), the CPU usage drops drastically. So its the paint only taking too much CPu cycles.

  • do you have a GPU on board

  • No GPU on board on my device, but the USB camera has which captures the feed and broadcast it.

  • OpenCV libraries are optimized to do such tasks
    you have direct support to capture and show videos
    you can integrate OpenCV with QT

  • I really appreciate your suggestion.
    But I'm not able to understand, how OpenCV will solve my problem ?

    My problem is not in CPU cycles consumed for image capturing/creating rather the problem is in painting the captured images with QT and QtGui libraries takes huge amount of CPU cycles to paint the images.

  • On devices with no hardware acceleration, Qt will use QRasterPaintEngine, which handles the acceleration using software. On devices supporting OpenGL ES, OpenVG or DirectFB(not supported by Windows CE), Qt will use the respective paint engines to accelerate painting. However, hardware configurations that only support a limited set of hardware acceleration features, might slow the application graphics down rather than speeding it up when using unsupported operations that must fall back to the raster engine.

    check this for more info

  • Thank you for the link.

    But unfortunately my target h/w does not have an dedicated GPU and I can't use other paint engines.

    I'm still not convinced why the QtGui library takes so much time to paint. Is there any other way around to reduce the CPU usage for continuously painting the images for a video widget ?

Log in to reply