[fpc-pascal] How to find where my app consumes CPU?

Bo Berglund bo.berglund at gmail.com
Tue May 18 21:59:33 CEST 2021


I have a pretty sizable console app written with Delphi 15 years ago but ported
to Linux using FreePascal (3.2.0) with Lazarus (2.0.12) as IDE. It runs as a
systemd service on a Raspberry Pi3.

Basically it is a scheduler, which checks every minute if there is a task to
run, otherwise it waits for the next minute to pass.

Meanwhile in another thread there is a TCP/IP socket server active for
communicating with the app over the network. So it is listening for incoming
connections.

This is working seemingly OK, but today when I checked the RPi I found using top
that it was running 11% CPU, which is strange because it has nothing to do at
the moment.

I have tried to be as conservative as possible regarding wait loops etc so in
such loops I always have a sleep() call, which in my Windows experience used to
stop excessive CPU usage.

So I was surprised to find the high CPU usage and now I am at a loss on how to
find *where* this is happening...

Any ideas on how to proceed?
Is there some Lazarus way to find this?
(But I cannot really run the application in service mode from within Lazarus...)


-- 
Bo Berglund
Developer in Sweden



More information about the fpc-pascal mailing list