[Plugin] Performance profiler
#1

Performance profiler

This plugin can count how many times each of functions is called and how much time it takes to execute. This information is outputted in one of the currently supported formats: HTML , XML or and plain text.

Profiling begins right after a script gets loaded and stops when you unload it (i.e. when you close the server or do gmx/fsunload/fsreload). At unloading time, all statistical data is saved to a file called <script_name>-profile.<format> in .amx directory. The <format> part depends on your output format choice (see below).

Profiler adds a few extra server.cfg variables:
  • profile_gamemode <0|1>

    If set to 1, profiler will profile currently running game mode. Default value is 0.

  • profile_filterscripts <fs1> <fs2> ...

    A list of filter scripts to be profiled. Can be empty.

  • profile_format <xml|html|txt>

    Set statistics output format. Default is html. Note for HTML: it is possible to sort stats by clicking on column names!!

  • call_graph <0|1>

    Set this option to 1 if you want profiler to generate a call graph. The graph is generated as a GraphViz dot file.

  • call_graph_format <format>

    If specified, profiler will try to convert the .gv file into one of the formats supported by dot.

    The dot program is invoked as follows:

    Code:
     <install_path>/dot -T<format> <some_script-calls.gv> -O
    On Windows, install_path is looked up in registry first, then in GV_HOME environment variable (as on *nix). If GraphViz install path is not found it is assumed to be already in PATH.
Download

https://github.com/Zeex/samp-plugin-profiler/releases

Source code

https://github.com/Zeex/samp-plugin-profiler
Reply
#2

This is sweet, I'll be trying this out now, thanks mate
Reply
#3

This is pretty neat, thanks for releasing it (gonna dive into the source *drool*).
Reply
#4

Awesome plugin. Will take a better look when I get home.
Reply
#5

Very nice and advanced plugins you release in here. I really like it, good job.
Reply
#6

When I do this in OnGameModeExit the server crashes when I close the server/ change the gamemode:
pawn Code:
Profiler_Stop();
Profiler_PrintStats("scriptfiles/test.html");
crashdetect says that it is crashed by Profiler_PrintStats.
It is still crashing without the crashdetect plugin.

I put
pawn Code:
Profiler_Init("gamemodes/scfri.amx");
Profiler_Start();
in OnGameModeInit.

I'm not sure if I used it wrongly...
Reply
#7

Brilliant, thank you. I'll certainly make good use of this in the near future.
Reply
#8

Dont work in my gamemode its crashing server... ;/
Reply
#9

Sounds nice, but also doesnt work for me. When stopping and saving on gamemode exit, nothing happens. If I stop and save with a command only the file with the header is created, but it shows no functions, and the server crashes. (windows version, R1 server)
Would be great if this really works, as i am doing a lot of optimizing work atm, so this would be really handy.
Reply
#10

Ah! I haven't mention anywhere: the script you're profiling must have debug symbols in it i.e. compiled with either -d3 or -d2 flag.

Sorry I should have said this in the first post. I will upload an update soon to fix that.
Reply
#11

When I turn on the -d3 flag I get this:

Header size: 9140 bytes
Code size: 2099416 bytes
Data size: 2306236 bytes
Stack/heap size: 16384 bytes; estimated max. usage: unknown, due to recursion
Total requirements: 4431176 bytes

The server starts but it seems to be just half working it seems like the server can't change/access some variables. So how to fix this. Also the debug info I get from this plugin seems wired look at this:

Function Calls Time per call Overall time Overall time, %
operator<=(Float:,Float 11 44926983329134 494196816620469 100.39
operator!=(Float:,Float 4 6349021761 25396087044 0.01
mysql_query 355 21821 7746483 0.00
Reply
#12

You may have stack overflow in your script due to resursion(s).
Check which part of your script uses recursion and fix it.
It could be caused by faulty script causing a function calling itself at some circumstances.
Reply
#13

Quote:
Originally Posted by leong124
View Post
You may have stack overflow in your script due to resursion(s).
Check which part of your script uses recursion and fix it.
It could be caused by faulty script causing a function calling itself at some circumstances.
But I doesn't get that massage without the d3 flag o.0
Reply
#14

The debug label acts like that. IMHO it will do more checking to ensure your script is safe.
Even you don't have a stack overflow, it will still show the message.

Again, nice plugin Zeex
You are swesome
Reply
#15

robanswe: in your compiler command line options, add the -S8192 or maybe -S65536
Code:
"%in%" -o"%out%" -d2 -O0 -S65536 -w203 -w204
this is my command line parameter, using PawnStudio. debugmode 2, no optimizing, stack/heapsize set to 64kB, and some warnings to supress (warning 203 and 204, they are annoying for me lol).
pay attention to the -S65536, its setting the stack/heap size, as mentioned.
if you got long if{}else if{}... or switch(){case{}case{}... then a too-low set -S can cause yor problem aswell, and the -S setting to a higher size will solve it
@1516594552: thank you for sharing this, i always wanted to check out how efficient my method in getting closest players is. now i can test it. TY! rep+++
edit: lol @ this
Code:
Function		Calls		Time per call	Overall time	Overall time, %
ShowTDStatus		7		13338		93364		82.22
i guess i got something to optimize... well, that was a profiling for 20 seconds gameplay only, but it points to the right direction where to optimize the unbelievable waste of CPU time in the textdraw routine.
it took me like 10 minutes to get the profiler.html output! thanks again :P
Reply
#16

IMO the unit of time should be shown.
I guess this should be us (micro second), because it is impossible to be ms or s.
Reply
#17

Quote:
Originally Posted by Babul
View Post
robanswe: in your compiler command line options, add the -S8192 or maybe -S65536
Code:
"%in%" -o"%out%" -d2 -O0 -S65536 -w203 -w204
this is my command line parameter, using PawnStudio. debugmode 2, no optimizing, stack/heapsize set to 64kB, and some warnings to supress (warning 203 and 204, they are annoying for me lol).
pay attention to the -S65536, its setting the stack/heap size, as mentioned.
if you got long if{}else if{}... or switch(){case{}case{}... then a too-low set -S can cause yor problem aswell, and the -S setting to a higher size will solve it
I tested this but it didn't help I think I have some big problem somewhere like:

public test()
{
test();
}

Is there anyway to find things like this? I mean my gm is over 40k lines o.0
Reply
#18

Very nice. Useful plugin!
Reply
#19

A minor update (v1.5):

- Stats not reset in Profiler_Start anymore, you now have Profiler_ResetStats for this
- Profiler_PrintStats now takes an extra parameter which specifies output data sorting mode (by calls, time, times per call or not sorted)
- Time units appear in output table column names (microseconds)
Reply
#20

robanswe: Try to use the binary search method to comment out parts of your script, and see which part of it does the recursion.

Zeex: I got a problem. When I check the output of this plugin, I found that there are 19 Itter_OnGameModeInit there while there's about 4-5 hooked OnGameModeInit only in my gamemode.
Also, all of them are Itter_OnGameModeInit, while they should have different names IMO (since they are hooked with different names and get called like a chain).
Finally thanks for taking my suggestion
Reply


Forum Jump:


Users browsing this thread: 7 Guest(s)