[fpc-pascal] How to find where my app consumes CPU?
Alexander Grotewohl
alex at dcclost.com
Wed May 19 00:39:18 CEST 2021
https://www.freepascal.org/docs-html/rtl/baseunix/fpsigtimedwait.html
there we go :) i think this should do the trick. might need to rearrange some things though..
--
Alexander Grotewohl
https://dcclost.com
________________________________
From: fpc-pascal <fpc-pascal-bounces at lists.freepascal.org> on behalf of Bo Berglund via fpc-pascal <fpc-pascal at lists.freepascal.org>
Sent: Tuesday, May 18, 2021 6:29:17 PM
To: fpc-pascal at lists.freepascal.org <fpc-pascal at lists.freepascal.org>
Cc: Bo Berglund <bo.berglund at gmail.com>
Subject: Re: [fpc-pascal] How to find where my app consumes CPU?
On Tue, 18 May 2021 21:40:15 +0000, Alexander Grotewohl via fpc-pascal
<fpc-pascal at lists.freepascal.org> wrote:
>if it's waiting on keyboard input you might be better off using select() for
>that instead of looping and checking for keyboard input each go around.
>
>sleep() might already do something similar with a zero timeout but even that
>would probably be insufficient
As I tried to explain at the start of this thread my application runs as a
*systemd service* on Linux, so there is absolutely no keyboard input.
The main program looks like this after initializations etc:
try
try
bSTerm := False;
bSInt := False;
bsHup := False;
{$IFDEF UNIX}
fpSignal(SigTerm, SignalHandler(@handleSignal));
fpSignal(SigInt, SignalHandler(@handleSignal));
fpSignal(SigHup, SignalHandler(@handleSignal));
{$ENDIF}
Debug_Writeln('Enter eternal loop');
FLogServ.StdLog('Enter eternal loop');
While not (bSTerm or bSInt or bsHup) do
begin
//Here is where the server runs as defined elsewhere
//Eternal loop to wait for system messages
Sleep(1); //To not hog the CPU
CheckSynchronize; //To get thread comm working
end;
Debug_Writeln('Exit eternal loop');
FLogServ.StdLog('Exit eternal loop');
except
on E: Exception do
begin
FLogServ.ExceptionLog('Unhandled exception: ' + E.Message);
end;
end;
finally
ShutdownServer;
end;
As you can see it sits in the eternal loop until the system sends a "signal" to
it to stop. So systemd does that if I issue a sudo systemctl stop myservice and
this works fine.
Could this tiny loop consume 6-7% CPU cycles?
--
Bo Berglund
Developer in Sweden
_______________________________________________
fpc-pascal maillist - fpc-pascal at lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20210518/109712de/attachment.htm>
More information about the fpc-pascal
mailing list