[Include] profiler.inc - plugin-less profiler
#1

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).
Reply
#2

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?
Reply
#3

Quote:
Originally Posted by FireCat
View Post
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
Reply
#4

Nice pice of code

edit: Whould "#emit SYSREQ" fed in you'r code?
Reply
#5

This is very nice! Good job.
Reply
#6

Quote:
Originally Posted by FireCat
View Post
Still have to read this though, but it looks nice! (:
and intersting
anyway GJ.
Reply
#7

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)