Results 1 to 4 of 4

Thread: PyQt4 app : high CPU usage from python and Xorg

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2009
    Posts
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question PyQt4 app : high CPU usage from python and Xorg

    Dear QtCentre users,

    I am writing an application to analyze audio data in realtime. The audio data typically comes from a microphone. "Realtime" here means a lantency lower than 20 ms so that the delay between the capture and the display on screen is not humanly noticeable. The display is made of level meter, scope, spectrum and rolling spectrogram widgets.

    I have chosen to use :
    -python as a language,
    -numpy/scipy for the audio processing (mostly FFT currently),
    -pyaudio (portaudio bindings),
    and most importantly for this forum audience :
    -PyQt4 for the GUI,
    -PyQwt for the plot widgets.

    To give you an idea, here is a screen capture of what it gives : capture.jpg

    I think I have managed to get a working prototype which meet the above goals, apart from a problematic detail : the CPU usage.

    The program is written around a QTimer whose period is around 20 ms. Th timer slot computer the FFT when it has enough data, updates the widgets. I profiled the whole thing with cProfile, and worked hard to remove the major hotspots. The rolling spectrogram is made in a manner as clever as possible, and the plot are updated only where they need to. Here is the profile seen by kcachegrind : capture-kcachegrind.jpg
    As you can see, most of the time is spent in exec_, which is the main loop if I understand correcly.

    Still, when I run the program, the fans start to run, and 'top' confirms the high CPU activity :

    Tasks: 170 total, 3 running, 167 sleeping, 0 stopped, 0 zombie
    Cpu(s): 41.5%us, 4.0%sy, 0.0%ni, 54.2%id, 0.0%wa, 0.0%hi, 0.3%si, 0.0%st
    Mem: 2007728k total, 1937212k used, 70516k free, 75384k buffers
    Swap: 0k total, 0k used, 0k free, 1025968k cached

    PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
    4678 tipote 20 0 946m 71m 36m R 42.7 3.6 0:47.81 python
    1876 root 20 0 506m 131m 11m S 40.7 6.7 35:46.64 Xorg
    2119 tipote 20 0 430m 6960 5032 S 3.6 0.3 3:14.54 pulseaudio
    ...

    40% by python and 40% by Xorg is not a satisying result, but I have no idea what to do now to improve that situation since I cannot see anymore hotspots in the profile. So here is my question : what can I do to lower that CPU usage ? Can you see some design flaws in the above description ?

    Thank you for your help,

    Best regards,

    Timothée Lecomte, tipote

    P.S. : this has been done on Fedora Core 11, which use QT 4.5, PyQT 4.4.4, Qwt 5.1.1 (also tested on Ubuntu 9.04)
    Last edited by tipote; 10th June 2009 at 08:23. Reason: Put image as attachments, mention libraries versions

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.