input-remapper icon indicating copy to clipboard operation
input-remapper copied to clipboard

High CPU use on idle

Open whudson opened this issue 3 years ago • 4 comments

While doing nothing on my PC the program sits around 4% CPU use. It seems a bit high for a basic utility service that has to run always.

whudson avatar Apr 19 '22 22:04 whudson

Can't reproduce

sezanzeb avatar Apr 21 '22 10:04 sezanzeb

The specific script is one of the input-remapper-service processes. (There are 3 running, interesting to note here these kernel workers are the only ones on my system that say events_unbound)

root       12527  0.1  0.2 2132092 34588 ?       Sl   09:50   0:00 /usr/bin/python3 /usr/bin/input-remapper-service --hide-info
root       12528  0.0  0.1  50264 21644 ?        S    09:50   0:00 /usr/bin/python3 /usr/bin/input-remapper-service --hide-info
root       12536  2.8  0.0      0     0 ?        I    09:50   0:07 [kworker/u8:2-events_unbound]
root       12612  1.4  0.0      0     0 ?        I    09:50   0:03 [kworker/u8:4-events_unbound]
root       13042  2.9  0.1 2132092 26064 ?       S    09:51   0:05 /usr/bin/python3 /usr/bin/input-remapper-service --hide-info

Version Info:

> python --version
Python 3.9.7
> uname -srvmo
Linux 5.10.0-13-amd64 #1 SMP Debian 5.10.106-1 (2022-03-17) x86_64 GNU/Linux
> lsb_release -d
Description:	Debian GNU/Linux 11 (bullseye)

whudson avatar Apr 23 '22 14:04 whudson

I'd like to try and figure out how to get the python debugger attached to the service so I can see what code we seem to be constantly hitting. I'll see how that goes.

whudson avatar Apr 23 '22 14:04 whudson

I guess it might matter, I am only remapping one device- a Logitech M570

whudson avatar Apr 23 '22 15:04 whudson

20221021-221021

I have CPU usage 1-2% on my Intel i7-9850H (12) @ 4.600GHz

Seems like a lot, right? Any idea how to reduce this? I am ready to help with debugging.

coffebar avatar Oct 21 '22 19:10 coffebar

There are apparently ways to profile python applications. I haven't done it myself yet though, so I don't know how it works.

If you research into it, make sure to profile the beta branch, not main

sezanzeb avatar Oct 21 '22 19:10 sezanzeb

If anyone can come up with a small guide on how to get profiling data for input-remapper-service it would also be of help already, even if the cause is not found yet

sezanzeb avatar Oct 21 '22 19:10 sezanzeb

Restarted service and problem gone. Can't reproduce for now. I did not switched to beta. I will let you know if find out something new

coffebar avatar Oct 21 '22 19:10 coffebar

Allright, thanks.

Profiling might have to work across multiple processes.

In the case of coverage this is just a matter of configuration, so maybe some profiling tool has some tricks as well to get it to work with the multiprocessing module.

sezanzeb avatar Oct 21 '22 19:10 sezanzeb

By the way, for me "Idle" would be defined as "no injection started, no autoload, no apply-button-click, no input-remapper-gtk running"

sezanzeb avatar Oct 21 '22 19:10 sezanzeb

I have mappings for 2 keyboards and also I had a mouse button mapping. Now mouse was unplugged. When i connect it, CPU goes from 0% to 0.7%, and when i moving cursor with exactly this mouse (not a touch-pad) - it goes up to 4% (depending how intensive i moving)

UPD: same thing on Beta branch

coffebar avatar Oct 21 '22 20:10 coffebar

I get ~100% CPU load when I unplug the device with the GUI open. Fedora 36, input-remapper 1.5.0, python-evdev 1.6.0

grafik

As for profiling, I've never done it myself but it could be as easy as calling the module/app through cProfile: python -m cProfile script.py

Should I open another issue? My problem only occurs if there is an active injection.

TacticalCode avatar Nov 01 '22 13:11 TacticalCode

This is a different problem, yeah, please open a separate issue

sezanzeb avatar Nov 01 '22 13:11 sezanzeb

@TacticalCode has provided an example on how python can be profiled: https://github.com/sezanzeb/input-remapper/issues/527

In this case, cProfile.run needs to be added to the bin/input-remappser-service file, possibly wrapping daemon.run()

sezanzeb avatar Nov 05 '22 12:11 sezanzeb