Recent

Author Topic: Autostart Lazarus program causes high CPU usage  (Read 3088 times)

bartdereu

  • New Member
  • *
  • Posts: 17
Autostart Lazarus program causes high CPU usage
« on: August 17, 2013, 11:52:49 am »
Hi all,

i have a rather strange problem. I am writing a program under Lazarus, the program will need to be started when the raspberry boots.  When i compile my program and run it, the CPU usage is about 50%, which is acceptable . There is a clock on the screen and it shows the seconds nicely. However, when i try to autostart the same program it gets a very high CPU usage, around 90-100% constantly which makes it laggy.

I have tried different approaches to autostart the program :
1) I created a file in the .config/autostart directory with the needed startup information. Doesnt work

2) I tried to write another small program that autostarts, with a TTimer set to 15 seconds and then execute the main program with a fpsystem('....'); command. That worked, the cpu usage dropped again to 50% during those 15 seconds, but as soon as my program started the CPU usage hit the ceiling again.

3) Then i tried to 'sudo nano .bashr' and added the line to open a script that contained my program executable and also the small boot program . No luck.

I have no clue why autostarting my program would cause it have a high CPU usage, Since when i open the task manager i see that it only uses about 4%. When i boot normally  and execute the program from the command line, CPU usage is normal.

Also, the CPU usage i see in task manager is not correct. When i get the 100% usage i only see that my prog uses about 4-5% and task manager 10%, and a very few small ones that use less then 1% each. All in total not even 20% load. How do i get to a full load ?

Anyone has any ideas ? It would be highly appreciated  ;D

MassAI

  • Newbie
  • Posts: 3
  • MassAI - Analytical tools for Mass spectrometry
    • MassAI Bioinformatics
Re: Autostart Lazarus program causes high CPU usage
« Reply #1 on: August 17, 2013, 01:14:32 pm »
Hi Bartdereu,

I would not put too much emphasis on the readings of the on-screen CPU meter, if that is what you are referring to.
I find that it hits the 100% mark with the most trivial of efforts, while the task manager lists a more moderate CPU% usage.
E.G when I compile and run a blank form, clicking the mouse button repeatedly on the form makes the on-screen CPU meter hit ca. 90%,
while the task manager reports 20%

Have you tried to implement a simple "TimeElapsed := Timestart - now;" somewhere in your source code for a defined task, and
then comparing the timing of the two runs under the two different circimstances: manual start vs autostart.

   

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Autostart Lazarus program causes high CPU usage
« Reply #2 on: August 17, 2013, 01:39:15 pm »
There's profilers you may be able to use to figure out any difference:
http://wiki.lazarus.freepascal.org/Profiling
... but first I'd try and make sure you're measuring the same definition of cpu time for both situations (e.g. using a wrapper script that measures cpu time taken)
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

 

TinyPortal © 2005-2018