CPU meter for PD usage

Where would I find the code for the CPU meter? I have a PD patch that is definitely maxing the hardware out, but the CPU meter shows very little activity…

Thanks

It is provided by JACK.

1 Like

Called from within zynthian-ui/zynautoconnect/zynthian_autoconnect.py on an instance of the Jack Client object.

1 Like

Jack buffer under runs and cpu utilisation don’t have to be necessarily related. An instruction cycle returning a few milliseconds later than expected can cause havoc to an audio stream in Jack. For instance, if you configure the jack sample size too low then you’ll get Xruns with the cpu just apparently idling and no engines running at all. Just the fact that the cpu can’t process that fast is the issue.

1 Like

As @Baggypants explains, XRuns and CPU usage are not the same. You can have high CPU usage but no XRuns or lower CPU usage with lots of XRuns. However, they are related in most of cases: having high CPU usage normally increase the risk of having XRuns.

Anyway, you can have a true CPU-meter in the Zynthian-UI. Take a look to the webconf’s “UI Options” menu :wink:

Regards,

Thanks. I have the web-conf CPU meter turned on, and that’s what I’m looking at. I’m assuming the widget’s range is set such that it at 100% CPU utilisation, the meter should look like the audio meter, when driven by a loud source?

So if in fact the problem is not high CPU usage - and I was a little surprised to think that was the case because this patch is really just a dozen or so oscillators, and some lookup tables - then the solution would be to change some Jackd settings in the web conf? (I have spent most of my life as a programmer in the area of 3D graphics, so some of this low-level audio programming stuff is new to me.)

Thanks!

Actually, I will try running top whilst running the patch and get back to you.

Edit 2: Also, is there a Unix utility like top that I can use to inspect potential audio under runs a shell?

Edit 3: also, where is the code that calls PD? What command line arguments are used?

1 Like

Try this:

journalctl -u zynthian -f

Take a look to:

Regards,

1 Like

Haha. Someone else that sorts python imports by string length! :grin: Some great code there in general.

Thanks for the tips as well. That will help a lot.

Jaja! I never thought too much about this detail, but i like in that way :sweat_smile:

1 Like

I can now report some numbers regarding the the cpu load on my Zynthian when running my Pure Data patch. (Thanks again for the info above)

I have several versions of this synth on my Zynthian. The last version that worked was v6 - which is mono, and is pretty stripped back. “top” says it’s using 24% of my cpu. No Xruns.

v7 went stereo and uses roughly 55% of my cpu, and makes so sound - but no xruns. By v11, I can hit 100% cpu. I’m seeing lots of these when I run journalctl -u zynthian -f:

Oct 17 14:55:23 zynthian startx[455]: ERROR:root:Jack Audio XRUN!

For all of these synths, the UI cpu meter is totally flat:

For v12, I broke the synth up into 3 subprocesses using [pd~] - so including the parent process, I have 4 pd processes (one for each core). You would think that they distributed cpu load would total 100% with maybe a little overhead, but no:

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
11986 root -7 0 91128 86368 85276 R 96.7 9.1 2:55.96 pd
11993 root -7 0 7748 5384 4672 R 54.5 0.6 1:37.04 pd
11989 root -7 0 7748 5440 4728 S 53.5 0.6 1:35.01 pd
11987 root -7 0 7512 5232 4648 R 16.8 0.6 0:37.49 pd

This version is essentially v11 refactored, so I’m guessing that [pd~] involves a LOT of overhead for the master process? In any case I need a faster cpu!

Finally, I was able to follow these instructions to get the pd UI for v12 running on my Windows machine. That will be amazing useful for debugging stuff. I do not seem to be getting any midi input though. Not sure why that is yet, but open to suggestions. Note: This pd session was created from the bash command prompt using this alias:
alias pdev=‘pd -jack -rt -alsamidi -mididev 1 -open $1’
Which I basically stole from the python code above.

So I guess besides the jack -> Zynthian cpu widget not working for PD, it would be good to hear any strategies to help jack cope with this beast without xruns…

Thanks!

Just noticed the [cputime] node in pd:

image

Code here:

Maybe there’s another way to get pd cpu usage on Zynthian?

Of course, perhaps we should use a more “system-wide” way, instead of the value returned by jackd. You can try by tweaking these lines:

Simply change to:

				self.status_info['cpu_load'] = max(psutil.cpu_percent(None, True))
				#self.status_info['cpu_load'] = zynautoconnect.get_jack_cpu_load()

and test…

Regards,

Ok,

I’m a little unfamiliar with how to apply code changes to the zynthian? Where are the build / release scripts?

Also, having Xming working on Windows allowed me to tweak the PD audio settings and save a better startup config for Pure data. A block size of 256 bytes, and a delay of 100 milliseconds got my version 11 patch close to working on the Zynthian. Since version 11 however, I refactored the patch into various subprocesses, and none of those subprocesses return audio to the parent pure data patch on the zynthian, although they work fine on Windows. The main difference is that the current zynthian image runs pure data 47.1, whereas I’m running 50.0 on Windows. I feel like the first thing to try is to increment the version of pure data running on the Zynthian, and since the buster image has 49 by default, I decided to try to install that without success. (See other thread.)

You should start reading this:

https://wiki.zynthian.org/index.php/Zynthian_Development

Buster should work OK with your v2 kit once it’s been configured from the webconf. Please, try again and remember to update the software from the webconf as first step.

Regards,