[Mono/Linux] Reduce power consumption
A lightweight and easy-to-use password manager
Brought to you by:
dreichl
Keepass (v2.38) actively using CPU also during idle time and with this it drains laptop battery really fast.
Interestingly, even Vivaldi (a Chromium-based browser) has lower power consumption with this bug report tab open.
Here is the CPU usage of some programs expressed in events/s on Linux x64, in descending order:
Summary: 247,2 wakeups/second, 0,0 GPU ops/seconds, 0,0 VFS ops/sec and 4,5% CPU use
Usage Events/s Category Description
6,2 ms/s 66,0 Process [PID 2525] mono /usr/lib/keepass/KeePass.exe
0,9 ms/s 23,6 Process [PID 1055] [irq/29-iwlwifi]
532,0 µs/s 19,7 Timer tick_sched_timer
3,0 ms/s 17,7 Process [PID 9493] /opt/vivaldi/vivaldi-bin --type=renderer
238,6 µs/s 17,7 Process [PID 788] [xfsaild/dm-1]
182,2 µs/s 15,8 Process [PID 8] [rcu_preempt]
4,8 ms/s 13,8 Process [PID 4758] /opt/vivaldi/vivaldi-bin
14,6 ms/s 7,9 Process [PID 2473] /usr/bin/yakuake
174,1 µs/s 9,9 kWork ieee80211_iface_work
0,9 ms/s 4,9 Process [PID 2370] /usr/bin/kwin_x11
164,6 µs/s 5,9 Process [PID 2395] /usr/bin/kwin_x11
You can re-generate this summary by running PowerTOP.
You could use the mono profiler to find more precicly what is using so much CPU.
http://www.mono-project.com/docs/debug+profile/profile/profiler/
I used the profiler and after starting KeePass and provided the password I let it run for 5 minutes. During that time about 2 MB of data has been collected.
Is it safe to share the mono profiler data publicly?
Open a new database in KeePass, then collect the profile data.
cheers, Paul
I created a test database with defaults left in. Then I restarted the program with profiler. It ran for an hour minimised to tray and an hour being in the foreground.
Possibly worth inspecting the output starting from its end.
How can I convert this to something readable? With Mono 5.10.1.47 (currently the latest stable release),
mprof-report output.mlpdresults in 'Not a log profiler data file (or unsupported version).'.Thanks and best regards,
Dominik
After you extraced with
unxz output.mlpd.xz, usemprof-report --debug output.mlpdfor the detailed trace. I've just tried with the re-downloaded file and it worked fine.My mprof-report version is 2.0.
I can't read your MLPD file;
mprof-report(tried both version 2.0 and 1.0) always says 'Not a log profiler data file (or unsupported version).'. Maybe MLPD files are system-dependent.I've made some own experiments with the Mono profiler now (with own MLPD files
mprof-reportworks fine). Most time apparently is spent in the methods System.IO.InotifyWatcher.ReadFromFD, Mono.Unix.Native.Syscall.sys_poll, System.Threading.Thread.SleepInternal, System.Threading.WaitHandle.WaitOne_internal and System.IO.MonoIO.Read, but these should all be calls that don't actually cause much CPU load. Quite some time is spent in the window message processing, but these are Mono internals and I don't see how they could be optimized or reduced. System.Diagnostics.Process.CreateProcess_internal requires some time; this is caused by the clipboard workaround, but compared to the other calls this is negligible (you can easily test this: the clipboard workaround can be disabled using the-wa-disable:1530command line option, but I cannot observe a reduction of the CPU load).As there doesn't seem to be anything obvious causing the high CPU load, I'm moving this to the open feature requests. If anyone has an idea how to reduce the CPU load, please let me know.
Thanks and best regards,
Dominik
Ticket moved from /p/keepass/bugs/1732/
The problem is not necessarily with the high CPU usage but with it wakes up CPU often. So even if the usage is near 0%, but the program polls 100 times a second for some change then it will drain the battery. If it polls only 10 times, it is much better.
Thus you need to know how many "events" KeePass generate in a period. Apart from (perhaps some Mono-related) profilers, PowerTOP can show it to you, too.
The KeePass main window registers a timer that fires once every second. The clipboard workaround thread wakes up every 250 ms. All other wake-ups seem to be coming from Mono.
Best regards,
Dominik