<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
</head>
<body>
<div style="color: rgb(33, 33, 33); background-color: rgb(255, 255, 255);" dir="auto">
<a href="https://www.freepascal.org/docs-html/rtl/baseunix/fpsigtimedwait.html">https://www.freepascal.org/docs-html/rtl/baseunix/fpsigtimedwait.html</a><br>
</div>
<div style="color: rgb(33, 33, 33); background-color: rgb(255, 255, 255);" dir="auto">
<br>
</div>
<div style="color: rgb(33, 33, 33); background-color: rgb(255, 255, 255);" dir="auto">
there we go :) i think this should do the trick. might need to rearrange some things though..</div>
<div id="ms-outlook-mobile-signature">
<div><br>
</div>
--<br>
Alexander Grotewohl<br>
<a href="https://dcclost.com" target="_blank">https://dcclost.com</a></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> fpc-pascal <fpc-pascal-bounces@lists.freepascal.org> on behalf of Bo Berglund via fpc-pascal <fpc-pascal@lists.freepascal.org><br>
<b>Sent:</b> Tuesday, May 18, 2021 6:29:17 PM<br>
<b>To:</b> fpc-pascal@lists.freepascal.org <fpc-pascal@lists.freepascal.org><br>
<b>Cc:</b> Bo Berglund <bo.berglund@gmail.com><br>
<b>Subject:</b> Re: [fpc-pascal] How to find where my app consumes CPU?</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">On Tue, 18 May 2021 21:40:15 +0000, Alexander Grotewohl via fpc-pascal<br>
<fpc-pascal@lists.freepascal.org> wrote:<br>
<br>
>if it's waiting on keyboard input you might be better off using select() for <br>
>that instead of looping and checking for keyboard input each go around.<br>
><br>
>sleep() might already do something similar with a zero timeout but even that <br>
>would probably be insufficient<br>
<br>
As I tried to explain at the start of this thread my application runs as a<br>
*systemd service* on Linux, so there is absolutely no keyboard input.<br>
<br>
The main program looks like this after initializations etc:<br>
<br>
try<br>
try<br>
bSTerm := False;<br>
bSInt := False;<br>
bsHup := False;<br>
{$IFDEF UNIX}<br>
fpSignal(SigTerm, SignalHandler(@handleSignal));<br>
fpSignal(SigInt, SignalHandler(@handleSignal));<br>
fpSignal(SigHup, SignalHandler(@handleSignal));<br>
{$ENDIF}<br>
<br>
Debug_Writeln('Enter eternal loop');<br>
FLogServ.StdLog('Enter eternal loop');<br>
<br>
While not (bSTerm or bSInt or bsHup) do<br>
begin<br>
//Here is where the server runs as defined elsewhere<br>
//Eternal loop to wait for system messages<br>
Sleep(1); //To not hog the CPU<br>
CheckSynchronize; //To get thread comm working<br>
end;<br>
<br>
Debug_Writeln('Exit eternal loop');<br>
FLogServ.StdLog('Exit eternal loop');<br>
except<br>
on E: Exception do<br>
begin<br>
FLogServ.ExceptionLog('Unhandled exception: ' + E.Message);<br>
end;<br>
end;<br>
finally<br>
ShutdownServer;<br>
end;<br>
<br>
As you can see it sits in the eternal loop until the system sends a "signal" to<br>
it to stop. So systemd does that if I issue a sudo systemctl stop myservice and<br>
this works fine.<br>
Could this tiny loop consume 6-7% CPU cycles?<br>
<br>
<br>
-- <br>
Bo Berglund<br>
Developer in Sweden<br>
<br>
_______________________________________________<br>
fpc-pascal maillist - fpc-pascal@lists.freepascal.org<br>
<a href="https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal">https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal</a><br>
</div>
</span></font></div>
</body>
</html>