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

2021-05-19 Thread James Richters via fpc-pascal
> So now I am down to the timers... > I am using TFPTimer timers in the scheduler to handle various things, > some of them are just one-shots to delay an action for some predetarmined > time. I don't know how TFpTimers work either, but when I want a timer in one of my console apps, I just do

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

2021-05-19 Thread Mattias Gaertner via fpc-pascal
On Wed, 19 May 2021 19:46:43 +0100 Martin Wynne via fpc-pascal wrote: >[...] > I found that the problem is in the Lazarus Application.OnIdle event, > which fails to honour the Done parameter and runs continuously: How do you know, it is a bug in OnIdle, and not something continuously emitting

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

2021-05-19 Thread Bo Berglund via fpc-pascal
On Wed, 19 May 2021 19:46:43 +0100, Martin Wynne via fpc-pascal wrote: >On 18/05/2021 20:59, Bo Berglund via fpc-pascal wrote: >> 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. > >I have the

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

2021-05-19 Thread Martin Wynne via fpc-pascal
On 18/05/2021 20:59, Bo Berglund via fpc-pascal wrote: 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. I have the same problem with high CPU usage for a 20-year-old Delphi App compiled in

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

2021-05-19 Thread Bo Berglund via fpc-pascal
On Wed, 19 May 2021 19:42:27 +0200, Florian Klämpfl via fpc-pascal wrote: >Even it’s a service, running it with gprof enabled should be possible, no? I do not know what you mean, but the program is installed as a service but it is essentially a normal console application with no GUI parts. The

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

2021-05-19 Thread Florian Klämpfl via fpc-pascal
> Am 19.05.2021 um 19:00 schrieb Bo Berglund via fpc-pascal > : > > On Wed, 19 May 2021 16:02:00 +0200, Bo Berglund via fpc-pascal > wrote: > >> The "other" items might be hidden inside other used classes such as the >> Indy10 >> components I use to implement the TCP/IP communications. >>

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

2021-05-19 Thread Bo Berglund via fpc-pascal
On Wed, 19 May 2021 16:02:00 +0200, Bo Berglund via fpc-pascal wrote: >The "other" items might be hidden inside other used classes such as the Indy10 >components I use to implement the TCP/IP communications. >But when searching for sleep through the complete project sources I came up

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

2021-05-19 Thread Travis Siegel via fpc-pascal
On 5/19/2021 9:53 AM, Henry Vermaak wrote: On Wed, 19 May 2021 at 14:36, Travis Siegel via fpc-pascal wrote: No doubt your sleep code works just fine. I'm not saying the sleep command doesn't work. I'm saying the sleep command doesn't release unused cpu cycles for other threads/programs to

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

2021-05-19 Thread Bo Berglund via fpc-pascal
On Wed, 19 May 2021 11:45:34 +0200, Marco van de Voort via fpc-pascal wrote: >So my guess something else is spinning (e.g. in a thread). Seems likely based on my test with giving ChecSynchronize an argument 5 and not noticing any difference... So the original conundrum still applies: ** How

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

2021-05-19 Thread Henry Vermaak via fpc-pascal
On Wed, 19 May 2021 at 14:36, Travis Siegel via fpc-pascal wrote: > > No doubt your sleep code works just fine. > > I'm not saying the sleep command doesn't work. > > I'm saying the sleep command doesn't release unused cpu cycles for other > threads/programs to use. No, fpc uses nanosleep()

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

2021-05-19 Thread Travis Siegel via fpc-pascal
No doubt your sleep code works just fine. I'm not saying the sleep command doesn't work. I'm saying the sleep command doesn't release unused cpu cycles for other threads/programs to use. Apparently, if you want that behavior, you need to yield the cpu time your process would otherwise take,

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

2021-05-19 Thread Bo Berglund via fpc-pascal
On Wed, 19 May 2021 00:44:18 +0200, Martin Frb via fpc-pascal wrote: >Also CheckSyncronize afaik takes a timeout. >So if you do not need to check the variables every millisecond, then do > > While not (bSTerm or bSInt or bsHup) do > begin > //Here is where the server runs as

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

2021-05-19 Thread Mattias Gaertner via fpc-pascal
On Tue, 18 May 2021 18:37:38 -0400 Travis Siegel via fpc-pascal wrote: > Apparently, you can release cpu cycles, but it's with the sched_yield > (section 2 in the man pages), not the sleep command on linux. What sleep command are you referring to? What do you mean with cpu cycles? Sleep works

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

2021-05-19 Thread Marco van de Voort via fpc-pascal
Op 2021-05-18 om 23:29 schreef Travis Siegel via fpc-pascal: I'm not positive, but I'm pretty sure the sleep command in linux does not behave the same way it does in windows. As you know, in windows, a sleep command (even if delivered with a parameter of 0) gives up time slices to other

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

2021-05-19 Thread Bo Berglund via fpc-pascal
On Wed, 19 May 2021 00:29:17 +0200, Bo Berglund via fpc-pascal wrote: >Could this tiny loop consume 6-7% CPU cycles? Thanks for all of the responses, I will test tomorrow. I have noted that there are no other service processes that are waiting for some action but show up with CPU cycles above

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

2021-05-18 Thread Martin Frb via fpc-pascal
On 19/05/2021 00:29, Bo Berglund via fpc-pascal wrote: 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;

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

2021-05-18 Thread Alexander Grotewohl via fpc-pascal
-pascal Sent: Tuesday, May 18, 2021 6:29:17 PM To: fpc-pascal@lists.freepascal.org Cc: Bo Berglund Subject: Re: [fpc-pascal] How to find where my app consumes CPU? On Tue, 18 May 2021 21:40:15 +, Alexander Grotewohl via fpc-pascal wrote: >if it's waiting on keyboard input you might be bet

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

2021-05-18 Thread Travis Siegel via fpc-pascal
Apparently, you can release cpu cycles, but it's with the sched_yield (section 2 in the man pages), not the sleep command on linux. So, apparently, the sleep is still using full system recourses, even though it's just waiting.  You apparently have to release cpu time with the sched_yield

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

2021-05-18 Thread Bo Berglund via fpc-pascal
On Tue, 18 May 2021 21:40:15 +, Alexander Grotewohl via fpc-pascal 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

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

2021-05-18 Thread Alexander Grotewohl via fpc-pascal
://dcclost.com From: fpc-pascal on behalf of Travis Siegel via fpc-pascal Sent: Tuesday, May 18, 2021 5:29:10 PM To: bo.bergl...@gmail.com ; FPC-Pascal users discussions Cc: Travis Siegel Subject: Re: [fpc-pascal] How to find where my app consumes CPU? I'm not positive

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

2021-05-18 Thread Travis Siegel via fpc-pascal
I'm not positive, but I'm pretty sure the sleep command in linux does not behave the same way it does in windows. As you know, in windows, a sleep command (even if delivered with a parameter of 0) gives up time slices to other programs on the system.  This does not appear to be the case on

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

2021-05-18 Thread Bo Berglund via fpc-pascal
On Tue, 18 May 2021 21:59:33 +0200, Bo Berglund via fpc-pascal wrote: >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

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

2021-05-18 Thread Bo Berglund via fpc-pascal
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