<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
</head>
<body>
<div>
<meta content="text/html; charset=us-ascii">
</div>
<div dir="auto" style="color: rgb(33, 33, 33); background-color: rgb(255, 255, 255);">
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.</div>
<div dir="auto" style="color: rgb(33, 33, 33); background-color: rgb(255, 255, 255);">
<br>
</div>
<div dir="auto" style="color: rgb(33, 33, 33); background-color: rgb(255, 255, 255);">
sleep() might already do something similar with a zero timeout but even that would probably be insufficient</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 tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size: 11pt;" data-ogsc=""><b>From:</b> fpc-pascal <fpc-pascal-bounces@lists.freepascal.org> on behalf of Travis Siegel via fpc-pascal <fpc-pascal@lists.freepascal.org><br>
<b>Sent:</b> Tuesday, May 18, 2021 5:29:10 PM<br>
<b>To:</b> bo.berglund@gmail.com <bo.berglund@gmail.com>; FPC-Pascal users discussions <fpc-pascal@lists.freepascal.org><br>
<b>Cc:</b> Travis Siegel <tsiegel@softcon.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">I'm not positive, but I'm pretty sure the sleep command in linux does
<br>
not behave the same way it does in windows.<br>
<br>
As you know, in windows, a sleep command (even if delivered with a <br>
parameter of 0) gives up time slices to other programs on the system. <br>
This does not appear to be the case on linux.<br>
<br>
On linux, the sleep command simply suspends the process for the <br>
specified amount of time, but so far as I can tell, does nothing for <br>
unused cpu cycles.<br>
<br>
I've done a little digging, but I can't find any way on linux to give <br>
away unused cpu cycles.<br>
<br>
Perhaps the linux task switcher doesn't allow for this capability?<br>
<br>
<br>
On 5/18/2021 3:59 PM, Bo Berglund via fpc-pascal wrote:<br>
> I have a pretty sizable console app written with Delphi 15 years ago but ported<br>
> to Linux using FreePascal (3.2.0) with Lazarus (2.0.12) as IDE. It runs as a<br>
> systemd service on a Raspberry Pi3.<br>
><br>
> Basically it is a scheduler, which checks every minute if there is a task to<br>
> run, otherwise it waits for the next minute to pass.<br>
><br>
> Meanwhile in another thread there is a TCP/IP socket server active for<br>
> communicating with the app over the network. So it is listening for incoming<br>
> connections.<br>
><br>
> This is working seemingly OK, but today when I checked the RPi I found using top<br>
> that it was running 11% CPU, which is strange because it has nothing to do at<br>
> the moment.<br>
><br>
> I have tried to be as conservative as possible regarding wait loops etc so in<br>
> such loops I always have a sleep() call, which in my Windows experience used to<br>
> stop excessive CPU usage.<br>
><br>
> So I was surprised to find the high CPU usage and now I am at a loss on how to<br>
> find *where* this is happening...<br>
><br>
> Any ideas on how to proceed?<br>
> Is there some Lazarus way to find this?<br>
> (But I cannot really run the application in service mode from within Lazarus...)<br>
><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>