fulhax / ncpamixer

ncurses PulseAudio Mixer
MIT License
393 stars 20 forks source link

Option to disable live vu-meter feature #44

Open maxux opened 4 years ago

maxux commented 4 years ago

I really like the vu-meter like pavucontrol does, but I'm that kind of guy who keep that stuff running h24 and it eats ~5% cpu all time. I guess it's related to the runtime sampling for monitoring the volume per source. Original pavucontrol have the same behavior.

I think, if we can disable the vu-meter feature and just listening for event, it could reduce cpu usage to about nothing. I didn't checked the code yet, I'll take a look when I'll have time and prepare a pull request if possible.

c0r73x commented 4 years ago

We do have toggle_static to disable the realtime vu-meter. Not sure if we added a config for it to enable/disable it by default, but I think i did.

Update: Checked it now and we do have it in the theme section in config theme.default.static_bar as boolean value.

maxux commented 4 years ago

I confirm, I switched the setting to true and vu-meter seems disabled and bar is filled up-to-cursor with plain color. But cpu usage doesn't change at all, still ~6-7% all the time. Does this option just disable ui vu-meter or does it stop monitoring pa streams ?

c0r73x commented 4 years ago

I'm quite sure it should stop the monitoring but I might be wrong, it was some times since i implemented it.

maxux commented 4 years ago

From what I saw on the code (quickly on pa.cpp at least), there is always a create_monitor_stream_for_paobject for each stream, whatever is the value of static_bar, so basically there is always a request of a copy of all streams to ncpamixer.

Actually, static_bar is only used on the ui, value of static_bar doesn't have any impact on pa code.

c0r73x commented 4 years ago

Ok, should be easy to destroy the monitor streams when switching to static_bar, i will look into it.

maxux commented 4 years ago

Well I'm actually doing some test locally, commenting monitor doesn't seems to really reduce usage. I'm investigating :)

maxux commented 4 years ago

After some profiling and investigation, here it is: The thread dedicated to pulseaudio drop from ~1.2% cpu usage to 0.0% when commenting create_monitor_stream_for_paobject calls. So there is an improvement by stopping stream.

But major cpu time (of the other thread) is spent on drawing the ui. ~5% cpu usage for redrawing the ui, by growing the usleep in the Ui::run from 20000 to 80000 reduce cpu usage to ~1.5% without (IMO) adding lag on interface usage.

Obviously, when you want the vu-meter, you need to keep 20000 microsec to get a correct refresh rate.

Quick fix would be to disable create_monitor_stream_for_paobject calls when static_bar is enabled and change the refresh rate.

Better improvement would switch refresh to update event only (on key press or pa event fired), this would avoid refreshing continuously and keep same code path for all situation, but this would be a way larger change on the code.

c0r73x commented 4 years ago

I did start on a major rewrite in dev but I havn't gotten to finishing it yet, But that rewrite is about detaching the ui from PA to be able to use diffrent backends like CoreAudio (osx) or even Alsa. During this rewrite would be a nice place to implement this but atm it would be to much of a change.

I guess I will have to take some time and finish the dev branch :P