Recent

Author Topic: CPU & Memory Profiler  (Read 1252 times)

ALLIGATOR

  • Newbie
  • Posts: 5
CPU & Memory Profiler
« on: September 10, 2024, 06:04:10 am »
Good afternoon, esteemed community of Pascal lovers!
I am a beginner amateur developer.
I would like to introduce you some two tools I made for performance analysis.
The first one is a memory profiler.
https://github.com/Alligator-1/callstack_memprofiler

With its help you can find not quite optimal places in your project that can be improved, unnecessary or non-obvious memory allocations.
This tool should be cross-platform, but I work on Windows and haven't tested it on Linux, I haven't had time for it yet...

The next tool is a CPU profiler. Unfortunately at the moment it can work only with Windows x64, due to the presence of asm-inserts, porting to Linux x64 is in the plans, but again everything is related to free time.... but I welcome forks, I'm not sure about patches and merge requests yet, but forks are welcome.
Also, it also requires FPC to be patched to make it work.
https://github.com/Alligator-1/cpuprofiler

With this tool as well as with the previous one you can evaluate bottlenecks in the code and maybe find ideas for further optimizations!
Here is a short instruction on how to use CPUProfiler:
  • You need to patch FPC and rebuild it
  • Then plug profiler_proxy.pas into your project.
  • Then somewhere at the beginning of your project call profiler_proxy.profiler_init
  • and at the end of the program call profiler_proxy.profiler_reset.
  • Set the environment variable profiler=1
  • Enable generation of debugging information in the project
  • Start compilation of your project via CleanUp & Build
  • Run your project, work in it and then terminate it
  • The file “datetime.cpuprof” will appear next to the project executable file
  • Open it in cpuprofilerviewer, and also in cpuprofilerviewer load the executable itself (to see the symbolic names)
If you have any questions - you can ask here on the forum or on github, I will try to answer them )

Keep in mind, I'm just a beginner, so my code may seem suboptimal or confusing to you ) but I'm open to discussion and always looking for more optimal implementations

I hope you find these tools useful! They have already helped me, let them help you too! )

PS: Sorry, I can't figure out how to insert images into a post, but the links have screenshots, if someone could insert them into the posts below that would be great
« Last Edit: September 10, 2024, 06:14:45 am by ALLIGATOR »

440bx

  • Hero Member
  • *****
  • Posts: 4536
Re: CPU & Memory Profiler
« Reply #1 on: September 10, 2024, 07:01:23 am »
about 40some years ago beginners wrote "hello world" class programs... today they write memory and CPU profilers.

Beginners sure have come a long ways...  :)
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

AlexTP

  • Hero Member
  • *****
  • Posts: 2463
    • UVviewsoft
Re: CPU & Memory Profiler
« Reply #2 on: September 10, 2024, 07:29:58 am »
> profiler_proxy.profiler_init

This is python naming style. Let's use Pascal naming style: ProfilerInit (unit name can be kept as is).

ALLIGATOR

  • Newbie
  • Posts: 5
Re: CPU & Memory Profiler
« Reply #3 on: September 10, 2024, 01:22:14 pm »
> profiler_proxy.profiler_init

This is python naming style. Let's use Pascal naming style: ProfilerInit (unit name can be kept as is).

Thank you! Maybe I'll change it...


about 40some years ago beginners wrote "hello world" class programs... today they write memory and CPU profilers.

Beginners sure have come a long ways...  :)

Well, at least I'm not a professional programmer, I'm just an amateur who, with the help of a lot of other people, was able to write these two tools. I try to learn the right practices and approaches.

440bx

  • Hero Member
  • *****
  • Posts: 4536
Re: CPU & Memory Profiler
« Reply #4 on: September 10, 2024, 06:55:37 pm »
I try to learn the right practices and approaches.
It looks like you're doing very well. :)
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

stoffman

  • Jr. Member
  • **
  • Posts: 68
Re: CPU & Memory Profiler
« Reply #5 on: September 27, 2024, 11:43:56 am »
This looks amazing.

But I would really need help in patching and rebuilding FPC on windows. Google and ChatGPT didn't really help. Do you have instructions?

LBox

  • New Member
  • *
  • Posts: 12
Re: CPU & Memory Profiler
« Reply #6 on: September 28, 2024, 05:35:39 pm »
Cool! 8) 👍

about 40some years ago beginners wrote "hello world" class programs... today they write memory and CPU profilers.

Beginners sure have come a long ways...  :)
:D

VisualLab

  • Sr. Member
  • ****
  • Posts: 450
Re: CPU & Memory Profiler
« Reply #7 on: September 29, 2024, 12:09:33 am »
I have two questions for the profiler creator:
  • Could you add the ability to display the same time units in the entire CPU profiler table? It would be easier to track the results.
  • If the same time units are set in the entire table, could you add the ability to skip time units next to numeric values ​​in the CPU profiler table? Information about the selected time unit could be displayed above the table. This would make it easier to track the results.
It would also be a great convenience to display the results in both profilers not only in a table but also in graphical form, e.g. as a bar chart.

 

TinyPortal © 2005-2018