Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2010-09

Basics of profiling

15 messages · 7 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Felipe Monteiro de Carvalho

Hello,

Does anyone have a link or some info about basic info for doing profiling in fpc apps?

Basically I would like to know how many miliseconds does my app spend in a couple of drawing routines to calculate the effect of speed optimizations. I know I could just check with a timer in my code, but I suppose that there is a better way.

thanks,

Felipe Monteiro de Carvalho

Reply by email

Sven Barth
to Felipe Monteiro de Carvalho
Felipe Monteiro de Carvalho wrote 11 lines
Hello, Does anyone have a link or some info about basic info for doing profiling in fpc apps? Basically I would like to know how many miliseconds does my app spend in a couple of drawing routines to calculate the effect of speed optimizations. I know I could just check with a timer in my code, but I suppose that there is a better way. thanks,

You might want to take a look at fpprofiler which was revived by Graeme some time ago. It's mentioned in this mail:
http://www.hu.freepascal.org/lists/fpc-devel/2010-August/021716.html

Regards,
Sven

Reply by email

Graeme Geldenhuys
to Felipe Monteiro de Carvalho: Does anyone have a link or some info about basic info for doing profiling in fpc apps?…

On 6 September 2010 10:48, Felipe Monteiro de Carvalho

Does anyone have a link or some info about basic info for doing profiling in fpc apps?

You can try Valgrind. I don't know if it is available under Windows. The other problem is... good luck decyphering the results. Valgrind, Callgrind, Memgrind, Cachegrind, Coffee grinder [whatever :-)] are pretty cryptic to me.

The other problem with Valgrind is that it slowed down our applications so much that it took 5 minutes to get to the main screen. Totally useless to use, as far as I am concerned.

Recently I took a look at Darius's old project 'fpprofiler. Links below. It was over 2 years since anybody worked on it, and riddled with bugs. I fixed all memory leaks, added some improvements, and used the new fcl-passrc code included with FPC Trunk (though it only uses the tokenizer for speed reasons, so FPC 2.4.x should work to - maybe with minor one line code change).

fpprofiler was quick and easy to use, and it have me results that was easier to understand. The callgraph is still work in progress, and the timing results I want to improve too, but that is simply to do with the report generator code. I recently spoke to Darius, and is is going to merge my changes (found in GitHub) into the fpcprojects repository, but he doesn't know when that will be.

We also have some plans for improving parts of fpprofiler, like the line number issues, and the missing function names under 64-bit system (bug/missing feature in FPC).

But for quick and easy profiling, I found fpprofiler to suite my needs just well. Just remember to have your code in some SCM system, because fpprofiler does modify the code and recompiles it. It had some issue where it didn't restore your code, but I think I fixed most of those. Just thought I would mention it - rather be save than sorry, so have a backup.

Obviously, you can go old-school too, and simply use EpikTimer, to time certain functions you know to be slow or prone to "hot spots" in code.

Blog post on using Valgrind:
http://lazarusroad.blogspot.com/2007/09/using-valgrind-to-profile-fpc.html

Original fpprofiler project repository:
http://svn.freepascal.org/cgi-bin/viewvc.cgi/fpprofiler/trunk/?root=fpcprojects

Git repository with all my recent changes to get fpprofile working with latest FPC:
http://github.com/graemeg/fpprofiler

Regards,   - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net/fpgui/

Reply by email

Darius Blaszyk
to Graeme Geldenhuys: On 6 September 2010 10:48, Felipe Monteiro de Carvalho You can try Valgrind. I don't know…
Graeme Geldenhuys wrote 6 lines
Recently I took a look at Darius's old project 'fpprofiler. Links below. It was over 2 years since anybody worked on it, and riddled with bugs. I fixed all memory leaks, added some improvements, and used the new fcl-passrc code included with FPC Trunk (though it only uses the tokenizer for speed reasons, so FPC 2.4.x should work to - maybe with minor one line code change).

I've tested fpprofiler on FPC 2.4 and it works, provided the fcl-passrc is from 2.5.1. I'll add this folder as external to the SVN repository.

Show quoted text 6 lines
fpprofiler was quick and easy to use, and it have me results that was easier to understand. The callgraph is still work in progress, and the timing results I want to improve too, but that is simply to do with the report generator code. I recently spoke to Darius, and is is going to merge my changes (found in GitHub) into the fpcprojects repository, but he doesn't know when that will be.

Merging will start as soon as Florian will provide access for me again to the fpprofiler repository.

Darius

Reply by email

Žilvinas Ledas
to Darius Blaszyk
Darius Blaszyk wrote 9 lines
On Mon, 2010-09-06 at 13:01 +0200, Graeme Geldenhuys wrote: > Recently I took a look at Darius's old project 'fpprofiler. Links > below. It was over 2 years since anybody worked on it, and riddled > with bugs. I fixed all memory leaks, added some improvements, and used > the new fcl-passrc code included with FPC Trunk (though it only uses > the tokenizer for speed reasons, so FPC 2.4.x should work to - maybe > with minor one line code change). I've tested fpprofiler on FPC 2.4 and it works, provided the fcl-passrc is from 2.5.1. I'll add this folder as external to the SVN repository.

Few notes (parts that need some improvement):
1) fpp.pp needs at least tkAsm in "case tokenlist[i].token of" in "procedure ModifyCode(AFileName: string; tokenlist: TPasTokenList);"
2) it works wrong with ifdef's (it leaves only ELSE code) -- (I modified my copy to output comments as well and had to "modify" pscanner.pp to have directives as simple comments);
3) in "procedure TPasTokenList.SaveToFile(const AFileName: string);" no need for writeLN's - writes are enough;
4) Asm procedures are handeled wrong (fpprof_exit_profile; is inserted before end;)
function IsCPUID_Available : Boolean; register; assembler; asm
...
end;
5) records with cases (or some other type) is handeled wrong (fpprof_exit_profile; is inserted before end;) -- I don't remember what type it was exactly.

In my opinion 2) is the biggest problem now :)

P. S. These comments are with Graemes changes.
P. P. S. Good luck with improvements and updates!

Regards
Žilvinas

Reply by email

Felipe Monteiro de Carvalho
to Graeme Geldenhuys: On 6 September 2010 10:48, Felipe Monteiro de Carvalho You can try Valgrind. I don't know…

Thanks a lot all for the tips =)

Graeme Geldenhuys wrote
fpprofiler was quick and easy to use, and it have me results that was But for quick and easy profiling, I found fpprofiler to suite my needs just well. Just remember to have your code in some SCM system, because fpprofiler does modify the code and recompiles it

Good to know that there is a pascal profiling solution, but somewhat nasty that it changes the code, but thinking about it I couldn't think of a better alternative. Maybe only by copying the source tree to a temp dir.

Obviously, you can go old-school too, and simply use EpikTimer, to time certain functions you know to be slow or prone to "hot spots" in code.

In my case I only wanted to profile 5 painting routines, so I just went for EpikTimer with a PROFILING ifdef and it worked well =)

Felipe Monteiro de Carvalho

Reply by email

Darius Blaszyk
to Žilvinas Ledas: Few notes (parts that need some improvement): 1) fpp.pp needs at least tkAsm in "case…
Žilvinas Ledas wrote 32 lines
On 2010-09-06 15:48, Darius Blaszyk wrote: > On Mon, 2010-09-06 at 13:01 +0200, Graeme Geldenhuys wrote: >> Recently I took a look at Darius's old project 'fpprofiler. Links >> below. It was over 2 years since anybody worked on it, and riddled >> with bugs. I fixed all memory leaks, added some improvements, and used >> the new fcl-passrc code included with FPC Trunk (though it only uses >> the tokenizer for speed reasons, so FPC 2.4.x should work to - maybe >> with minor one line code change). > I've tested fpprofiler on FPC 2.4 and it works, provided the fcl-passrc > is from 2.5.1. I'll add this folder as external to the SVN repository. Few notes (parts that need some improvement): 1) fpp.pp needs at least tkAsm in "case tokenlist[i].token of" in "procedure ModifyCode(AFileName: string; tokenlist: TPasTokenList);" 2) it works wrong with ifdef's (it leaves only ELSE code) -- (I modified my copy to output comments as well and had to "modify" pscanner.pp to have directives as simple comments); 3) in "procedure TPasTokenList.SaveToFile(const AFileName: string);" no need for writeLN's - writes are enough; 4) Asm procedures are handeled wrong (fpprof_exit_profile; is inserted before end;) function IsCPUID_Available : Boolean; register; assembler; asm ... end; 5) records with cases (or some other type) is handeled wrong (fpprof_exit_profile; is inserted before end;) -- I don't remember what type it was exactly. In my opinion 2) is the biggest problem now :) P. S. These comments are with Graemes changes. P. P. S. Good luck with improvements and updates!

Could you please create patches or at least some simple testcases for each described issue? I will add them to SVN to prevent regressions in the future. Please post them on mantis.

Darius

Reply by email

Darius Blaszyk
to Žilvinas Ledas: Few notes (parts that need some improvement): 1) fpp.pp needs at least tkAsm in "case…
Žilvinas Ledas wrote 29 lines
On 2010-09-06 15:48, Darius Blaszyk wrote: > On Mon, 2010-09-06 at 13:01 +0200, Graeme Geldenhuys wrote: >> Recently I took a look at Darius's old project 'fpprofiler. Links >> below. It was over 2 years since anybody worked on it, and riddled >> with bugs. I fixed all memory leaks, added some improvements, and used >> the new fcl-passrc code included with FPC Trunk (though it only uses >> the tokenizer for speed reasons, so FPC 2.4.x should work to - maybe >> with minor one line code change). > I've tested fpprofiler on FPC 2.4 and it works, provided the fcl-passrc > is from 2.5.1. I'll add this folder as external to the SVN repository. Few notes (parts that need some improvement): 1) fpp.pp needs at least tkAsm in "case tokenlist[i].token of" in "procedure ModifyCode(AFileName: string; tokenlist: TPasTokenList);" 2) it works wrong with ifdef's (it leaves only ELSE code) -- (I modified my copy to output comments as well and had to "modify" pscanner.pp to have directives as simple comments); 3) in "procedure TPasTokenList.SaveToFile(const AFileName: string);" no need for writeLN's - writes are enough; 4) Asm procedures are handeled wrong (fpprof_exit_profile; is inserted before end;) function IsCPUID_Available : Boolean; register; assembler; asm ... end; 5) records with cases (or some other type) is handeled wrong (fpprof_exit_profile; is inserted before end;) -- I don't remember what type it was exactly. In my opinion 2) is the biggest problem now :)

I have added some tests for all the issues you describe above (asm / ifdef and case). According to me only asm seems to be not working correctly. Could you have a look and run the tests to see if you get the same issue? If confirmed I will work on fixing asm (and any other issue that pops up).

Regards, Darius

Reply by email

Žilvinas Ledas
to Darius Blaszyk
Darius Blaszyk wrote 28 lines
On Mon, 2010-09-06 at 16:58 +0300, Žilvinas Ledas wrote: > > Few notes (parts that need some improvement): > 1) fpp.pp needs at least tkAsm in "case tokenlist[i].token of" in > "procedure ModifyCode(AFileName: string; tokenlist: TPasTokenList);" > 2) it works wrong with ifdef's (it leaves only ELSE code) -- (I modified > my copy to output comments as well and had to "modify" pscanner.pp to > have directives as simple comments); > 3) in "procedure TPasTokenList.SaveToFile(const AFileName: string);" no > need for writeLN's - writes are enough; > 4) Asm procedures are handeled wrong (fpprof_exit_profile; is inserted > before end;) > function IsCPUID_Available : Boolean; register; assembler; > asm > ... > end; > 5) records with cases (or some other type) is handeled wrong > (fpprof_exit_profile; is inserted before end;) -- I don't remember what > type it was exactly. > > In my opinion 2) is the biggest problem now :) I have added some tests for all the issues you describe above (asm / ifdef and case). According to me only asm seems to be not working correctly. Could you have a look and run the tests to see if you get the same issue? If confirmed I will work on fixing asm (and any other issue that pops up). Regards, Darius

Sorry for the delay - I have very little time now... Notes about issues (I will use numbering from my previous message):
1) I think fixing asm is enougt to add tkAsm as I wrote previously.
4) Can't reproduce it now.
5) I'm attaching zip with testcase for this one (test_007.pp).
2) I'm sending test_005__as outputed_by_fpp.pp. You can see that only {$ELSE} branch is left, BUT I am using Windows ;) This is actually not a bug of fpprofiler (AS I UNDERSTAND IT), but a feature of fcl-passrc, as it "processes" IFDEF's, includes .inc files and so on (look at: pscanner.pp from 985 to 1161 lines)... I think the source code should be left as it is: no IFDEF's removed and no .inc files included - this could solve a lot of other potential bugs.

And another "bug" because of processing and removing directives is shown in attached test_006.pp file ;)

\fcl-passrc - at revision: 16002
At revision: 2501

Regards
Žilvinas Ledas

Reply by email