SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts > Includes

Reply
 
Thread Tools Display Modes
Old 03/02/2012, 10:30 PM   #1
Zeex_
Guest
 
Posts: n/a
Default profiler.inc - plugin-less profiler

Hi,

As you probably know I am the author of the profiler plugin:

http://forum.sa-mp.com/showthread.php?t=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).

Last edited by Zeex_; 04/02/2012 at 12:04 PM.
  Reply With Quote
Old 03/02/2012, 10:31 PM   #2
FireCat
High-roller
 
FireCat's Avatar
 
Join Date: Jul 2010
Posts: 2,403
Reputation: 596
Default Re: profiler.inc - plugin-less profiler

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?
FireCat is offline   Reply With Quote
Old 03/02/2012, 10:37 PM   #3
System64
Gangsta
 
System64's Avatar
 
Join Date: May 2011
Location: Zadar, Croatia
Posts: 940
Reputation: 143
Default Re: profiler.inc - plugin-less profiler

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
__________________
All my works
I left SA:MP! Maybe once I start scripting again but now I'm based on web programming
Soon, I'll buy domain system32.com.hr but for now you can contact me on LogoOff or on my ******* channel!
System64 is offline   Reply With Quote
Old 03/02/2012, 10:39 PM   #4
kizla
Big Clucker
 
kizla's Avatar
 
Join Date: Dec 2009
Posts: 180
Reputation: 50
Default Re: profiler.inc - plugin-less profiler

Nice pice of code

edit: Whould "#emit SYSREQ" fed in you'r code?
__________________
Tutorials
Abstract Machine eXecutor / emits
kizla is offline   Reply With Quote
Old 03/02/2012, 10:40 PM   #5
RyDeR`
High-roller
 
RyDeR`'s Avatar
 
Join Date: Feb 2009
Location: Belgium
Posts: 3,052
Reputation: 696
Default Re: profiler.inc - plugin-less profiler

This is very nice! Good job.
__________________

Sup?
RyDeR` is offline   Reply With Quote
Old 03/02/2012, 10:46 PM   #6
Kaperstone
Banned
 
Join Date: May 2011
Location: Russia
Posts: 3,338
Reputation: 824
Default Re: profiler.inc - plugin-less profiler

Quote:
Originally Posted by FireCat View Post
Still have to read this though, but it looks nice! (:
and intersting
anyway GJ.
Kaperstone is offline   Reply With Quote
Old 04/02/2012, 12:14 AM   #7
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 15,223
Reputation: 3183
Default Re: profiler.inc - plugin-less profiler

I've been debating something like your PEC code for y_hooks for a while to allow hooking of arbitrary functions like timers, will have to try get round to it now that you've done this. Nice work (though as you say the plugin is likely to be more useful).
Y_Less is offline   Reply With Quote
Old 04/02/2012, 07:16 AM   #8
Zeex_
Guest
 
Posts: n/a
Default Re: profiler.inc - plugin-less profiler

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 With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Plugin] Performance profiler 0x5A656578 Plugin Development 267 06/09/2018 07:45 PM
profiler plugin?[+reps] PawnoQ Scripting Help 2 03/01/2012 01:43 AM
mysql plugin. loading plugin failed ikkentim Help Archive 2 10/02/2011 03:32 PM


All times are GMT. The time now is 08:26 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.