profiler.inc - plugin-less profiler - Zeex_ - 03.02.2012
Hi,
As you probably know I am the author of the profiler plugin:
https://sampforum.blast.hk/showthread.php?tid=271129
Recently I started experimenting with #emit and made a Pawn-based profiler which does not require any plugins. It is very simple and is only able to profile public functions (in contrast to the plugin). Also it is less accurate than the plugin since it uses GetTickCount() to measure time which is millisecond resolution.
It provides these two functions:
ProfilerInit()
Initialize the profiler. This will redirect all public function calls to profiler's internal helpers by modifying the addresses stored in publics table.
ProfilerWriteData(const filename[])
Output results to a text file. This functions returns false if failed to open the file and true otherwise.
The output file looks like this:
Code:
+----------------------------------+----------------+----------------+----------------+
| Name | Calls | Self Time | Total Time |
+----------------------------------+----------------+----------------+----------------+
| OnGameModeExit | 0 | 0 | 0 |
+----------------------------------+----------------+----------------+----------------+
| OnPlayerConnect | 6 | 2 | 12 |
+----------------------------------+----------------+----------------+----------------+
| OnPlayerDisconnect | 0 | 0 | 0 |
+----------------------------------+----------------+----------------+----------------+
| OnPlayerRequestClass | 6 | 0 | 0 |
+----------------------------------+----------------+----------------+----------------+
| some_function_1 | 6 | 4 | 10 |
+----------------------------------+----------------+----------------+----------------+
| some_function_2 | 6 | 6 | 6 |
+----------------------------------+----------------+----------------+----------------+
Here
Self Time is the overall execution time and
Total Time is equal to Self Time + Total Time of all callees. The times are in milliseconds.
Also there are two definitions which you need to know about
:
PROF_MAX_PUBLICS
The maximum number of public functions. Should be around the number of publics in your script or greater. If it's not large enough you will notice a warning message in the server log.
PROF_MAX_CALL_STACK
The maximum depth of profiler's call stack. This is where information about active public calls is stored. The default value of 10 should be enough but if you have something like recursive CallLocal/RemoteFunction calls you probably want to increase it.
Download
Note: profiler.inc depends on other includes which can be downloaded from the same link (see above).
Re: profiler.inc - plugin-less profiler -
FireCat - 03.02.2012
Still have to read this though, but it looks nice! (:
Edit: So this is to check, how much times does a function take to run?
Re: profiler.inc - plugin-less profiler -
System64 - 03.02.2012
Quote:
Originally Posted by FireCat
Still have to read this though, but it looks nice! (:
Edit: So this is to check, how much times does a function take to run?
|
yes,
Quote:
Profiler plugin
Introduction
This plugin can count how many times each of functions is called and how much time it takes to execute. This information is outputted as a simple HTML table which can be viewed in a web browser.
|
On: god job man
Re: profiler.inc - plugin-less profiler -
kizla - 03.02.2012
Nice pice of code
edit: Whould "#emit SYSREQ" fed in you'r code?
Re: profiler.inc - plugin-less profiler -
RyDeR` - 03.02.2012
This is very nice! Good job.
Re: profiler.inc - plugin-less profiler -
Kaperstone - 03.02.2012
Quote:
Originally Posted by FireCat
Still have to read this though, but it looks nice! (:
|
and intersting

anyway GJ.
Re: profiler.inc - plugin-less profiler - Zeex_ - 04.02.2012
Thank you all!
Btw I've updated it a little:
- made output table less ugly (see first post)
- fixed tick count overflow issue
- it now warns you if PROF_MAX_PUBLICS/PROF_MAX_CALL_STACK not big enough