AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   General (https://forums.alliedmods.net/forumdisplay.php?f=7)
-   -   amxmodx profiler (https://forums.alliedmods.net/showthread.php?t=67752)

sawce 03-01-2008 02:17

amxmodx profiler
 
2 Attachment(s)
This is a profiler built into amxmodx's core - it really is only useful to people trying to find bottlenecks in their plugins.

What is a profiler? It basically tells you how long your plugin spends executing stuff.

To install it, just replace the amxmodx_mm_i386.so or amxmodx_mm.dll files (remember to backup your old ones) with the provided binaries. You do not need to recompile any plugins or change any modules.

Then configure plugins to be profiled like you would to get plugins debugged.

There is a new cvar, "amx_profile", its configuration is identical to "amx_debug":
0 = no plugins will be profiled
1 = only specified plugins will be profiled (default)
2 = all plugins will be profiled

To specify a plugin for profiling (for amx_profile mode 1), open up plugins.ini, and after the plugin name, add "profile".

For example, "admin.amxx" would become "admin.amxx profile"

Note: You cannot profile a plugin in debug mode.


When a plugin is being profiled, there is a very slight overhead. It should be unnoticeable, and you should be able to profile plugins on a production environment.

At map change, all plugins that are being profiled will get their profile data appended to amxmodx/data/profiles/<pluginname.amxx>.txt

The profiler will read the time it takes to execute native calls, public function calls (from forwards), and function calls (direct public function / stock function calls).

Additionally, it provides two new natives (they are not available in amxmodx's official core) to allow you to profile special chunks of code yourself. Documentation for these is available in the "profiler.inc" file.

Source is available here

Any issues with this version post here, do not file a bug report for it.

Edit:
New version for 1.8.2 and bugs fixed is available here: https://forums.alliedmods.net/showpo...0&postcount=87

sawce 03-01-2008 02:20

Re: amxmodx profiler
 
Here's an example profile report from admincmd.amxx

Code:

date: Fri Feb 29 01:42:55 2008 map: de_dust
type |                            name |      calls | time / min / max
-------------------------------------------------------------------
  n |                  get_user_flags |        14 | 0.000010 / 0.000000 / 0.000005
  n |              is_dedicated_server |        14 | 0.000011 / 0.000000 / 0.000002
  n |                        read_argc |        14 | 0.000014 / 0.000000 / 0.000005
  n |                get_cvar_pointer |        16 | 0.000207 / 0.000001 / 0.000032
  n |                            equal |        14 | 0.000008 / 0.000000 / 0.000001
  n |                  register_plugin |          1 | 0.000027 / 0.000027 / 0.000027
  n |              register_dictionary |          3 | 0.044636 / 0.001157 / 0.037203
  n |                  register_concmd |        17 | 0.002244 / 0.000088 / 0.000327
  n |                  register_clcmd |          3 | 0.000119 / 0.000034 / 0.000046
  n |                      server_cmd |        14 | 0.000087 / 0.000001 / 0.000032
  n |                        read_argv |        28 | 0.000031 / 0.000000 / 0.000006
  n |                  get_pcvar_flags |        10 | 0.000002 / 0.000000 / 0.000001
  n |                  set_pcvar_flags |        10 | 0.000004 / 0.000000 / 0.000001
  p |                          cmdCvar |        14 | 0.000101 / 0.000001 / 0.000014
  p |                      plugin_cfg |          1 | 0.000020 / 0.000020 / 0.000020
  p |                      plugin_init |          1 | 0.000051 / 0.000051 / 0.000051
  f |                      cmd_access |        14 | 0.000062 / 0.000001 / 0.000015
50 natives, 21 public callbacks, 33 function calls were not executed.

Type "n" is native call, type "p" is public function call from a forward, and type "f" is direct function call.

Note that it doesn't add up recursive calls.

For example: If function a() calls function b(), for the duration that b() is executing, the profiler for function a() is not keeping track of time. As soon as b() stops executing, a() will continue tallying up time.

Exolent[jNr] 03-01-2008 02:41

Re: amxmodx profiler
 
neat!

pRED* 03-01-2008 04:11

Re: amxmodx profiler
 
sawce if I could steal that trophy of yours and re-award it to you - I would.

It's that amazing.

Arkshine 03-01-2008 04:29

Re: amxmodx profiler
 
Quote:

It's that amazing.

Xanimos 03-01-2008 04:47

Re: amxmodx profiler
 
Your karma status could not be more accurate.

BAILOPAN 03-01-2008 11:37

Re: amxmodx profiler
 
Irrefutable proof that there is nothing that sawce cannot do!

I need to steal this for SourceMod.

Styles 03-01-2008 20:18

Re: amxmodx profiler
 
wow this is awsome

hoboman 03-13-2008 01:08

Re: amxmodx profiler
 
would it be possible for you to make something that logs at which function ( or maybe even the certain portion of the function ) a certain plugin is when the server crashes or reboots

sawce 03-13-2008 01:49

Re: amxmodx profiler
 
use binlogging

spiderbites 03-25-2008 05:07

Re: amxmodx profiler
 
from the data gathered, how do i tell if particular plugins causing lagness etc on my server?

sawce 03-25-2008 21:34

Re: amxmodx profiler
 
Really this is only meant for plugin developers finding bottlenecks, however if you must, then you could try to add up all the time, and whichever plugin takes the longest to execute would likely be it. However, take these values with a grain of salt; of course something like admincmd would take very little CPU compared to a plugin like gungame.

GrimReaperCdn 03-27-2008 21:35

Re: amxmodx profiler
 
Bow to the almighty sawce.

vittu 04-14-2008 15:07

Re: amxmodx profiler
 
Is there a 1.8.1.3679 build of this?

Note: I'm not entirely sure but this seems to crash when csx loads, can anyone else verify this?

sawce 04-14-2008 18:02

Re: amxmodx profiler
 
it might be related to the absolutely retarded thing csx does with csstats.amxx, I'll look into it sometime soon

Lee 06-04-2008 07:56

Re: amxmodx profiler
 
I'd appreciate it if someone who isn't lazy would make a comparison of get_players() and looping over each slot, but I'll understand if I get ignored.

BAILOPAN 06-04-2008 22:06

Re: amxmodx profiler
 
Someone who isn't lazy? Huh? I'm lazy, so I guess I shouldn't reply.

sawce 06-05-2008 02:18

Re: amxmodx profiler
 
It would depend on what checks are done. I'm fairly certain get_players would technically be faster, but the difference should be negligible so it should come down to preference. I still would use the separate checks because I hate get_player's syntax.

Also, I'm too lazy to actually check, be glad you got theory out of me.

Lee 06-05-2008 05:27

Re: amxmodx profiler
 
sawce: http://forums.alliedmods.net/showthread.php?t=57560

I'm lazy, not stupid or forgetful. Thanks anyway. I'm with you, I'm never going to use get_players() regardless of the results. This post sparked my curiosity. What's your take on get_players() vs. incrementing a variable? (rhetorical question)

BAILOPAN, I can say with complete certainty that you're not lazy. All you have to do is look at what you've accomplished, both with this project and (from what very little I know about it) at school. If you're asking why I requested the help of someone who isn't lazy; I recognise that I should do it myself, but I can't be bothered.

I did search Google for existing benchmarks of get_players(), but it only found two benchmarks on the entire site - and not this one.

Of course, I've now spent more time making this post (23 minutes) than it would have taken to install the new binary and write the benchmark script.

Drak 08-16-2008 21:22

Re: amxmodx profiler
 
I can't seem to narrow this down, but it seems ether when the TS Module is enabled, or the ArrayX is enabled. The server crashes upon start up.

sawce 08-16-2008 22:44

Re: amxmodx profiler
 
My money would be on the TS stats garbage doing it, especially if it uses the zombie plugin to calculate ranking like CSX does.

edit: ArrayX is terribad, don't use anything associated with rukia.

Drak 08-16-2008 23:36

Re: amxmodx profiler
 
Quote:

Originally Posted by sawce (Post 670828)
My money would be on the TS stats garbage doing it, especially if it uses the zombie plugin to calculate ranking like CSX does.

edit: ArrayX is terribad, don't use anything associated with rukia.

But there's nothing else, module wise, that I could use to accomplish storing large amounts of data.

sawce 09-06-2008 04:55

Re: amxmodx profiler
 
Merged in changes from 1.8.1, haven't had a chance to test so the old binaries are still there if needed.

stupok 10-07-2008 01:55

Re: amxmodx profiler
 
I want to give this a spin, but it just crashes immediately. I tested both binaries, same result. I run the server and it crashes as soon as the program launches.

When I switch back to the original binary, works fine.

Also note: I disabled all 3rd party plugins.

Informations:
Code:

Metamod version 1.19
AMX Mod X version 1.8.1.3746
WinXP

sawce, I :crab: you for taking the time to make this splendid contraption

danielkza 12-10-2008 19:43

Re: amxmodx profiler
 
Quote:

Originally Posted by stupok (Post 696241)
I want to give this a spin, but it just crashes immediately. I tested both binaries, same result. I run the server and it crashes as soon as the program launches.

When I switch back to the original binary, works fine.

Also note: I disabled all 3rd party plugins.

Informations:
Code:

Metamod version 1.19
AMX Mod X version 1.8.1.3746
WinXP

sawce, I :crab: you for taking the time to make this splendid contraption

Same here. Did you find a fix for it?

stupok 12-10-2008 22:38

Re: amxmodx profiler
 
Nope. I imagine running AMXX 1.7.x would work, but... I'm lazy.

TeddyDesTodes 12-16-2008 14:01

Re: amxmodx profiler
 
nice work

ehha 02-02-2009 16:47

Re: amxmodx profiler
 
Thanks sawce, exactly what i needed to see if lame plugins result from my n00b coding skills.

danielkza 02-28-2009 13:42

Re: amxmodx profiler
 
Was anyone able to use it? I still get instant crashes on both versions, on MM 1.19 and MM 1.19p32, in 2 different system (Windows XP and Windows 7).

joaquimandrade 03-02-2009 21:48

Re: amxmodx profiler
 
Quote:

Originally Posted by danielkza (Post 771073)
Was anyone able to use it? I still get instant crashes on both versions, on MM 1.19 and MM 1.19p32, in 2 different system (Windows XP and Windows 7).

I use it. The recent dll didn't work but, the previous one did. (1.8.0)

danielkza 03-03-2009 12:05

Re: amxmodx profiler
 
Quote:

Originally Posted by joaquimandrade (Post 772780)
I use it. The recent dll didn't work but, the previous one did. (1.8.0)

I found out what the problem is. 1.8.1 doesn't work at all, and 1.8.0 only works if you don't try to use the profiling natives.

Arkshine 03-03-2009 18:23

Re: amxmodx profiler
 
It works fine for me. Both. ( Tested under windows xp, mm1.19p32 )

danielkza 03-03-2009 18:40

Re: amxmodx profiler
 
Quote:

Originally Posted by arkshine (Post 773352)
It works fine for me. Both. ( Tested under windows xp, mm1.19p32 )

Did you try running a plugin that actually uses the profiler natives?

Arkshine 03-03-2009 18:59

Re: amxmodx profiler
 
Ah using the natives. You're right it crashes my server too. Just after StopProfile() call. Most likely it crashes when the profiler object is destroyed because value is well given.

vittu 03-18-2009 23:57

Re: amxmodx profiler
 
Sawce, any chance on updating this to not crash with csx (or any other module that uses a <mod>stats.amxx plugin)?

diamond-optic 03-26-2009 01:53

Re: amxmodx profiler
 
linux binary is crashing for me on startup too...


Quote:

./hlds_run: line 342: 15203 Segmentation fault $HL_CMD

stupok 04-17-2009 01:08

Re: amxmodx profiler
 
Quote:

Originally Posted by Lee (Post 634406)
I'd appreciate it if someone who isn't lazy would make a comparison of get_players() and looping over each slot, but I'll understand if I get ignored.

Ok.

Quote:

Originally Posted by sawce (Post 634782)
I'm fairly certain get_players would technically be faster

You are correct, sir.


Here's an example, but your mileage may vary depending on your specific applications. If you give me some ideas, then I might test them. According to the results of this test, get_players() is one order of magnitude faster than iterating through each client.

I had 32 bots connected to my server at the time of this test.

Code:

date: Thu Apr 16 23:59:26 2009 map: de_dust
type |                            name |      calls | time / min / max
-------------------------------------------------------------------
  n |                  register_plugin |          1 | 0.000001 / 0.000001 / 0.000001
  n |                  get_maxplayers |          1 | 0.000000 / 0.000000 / 0.000000
  n |                  register_srvcmd |          1 | 0.000066 / 0.000066 / 0.000066
  n |                      server_cmd |          1 | 0.000003 / 0.000003 / 0.000003
  n |                is_user_connected |    320000 | 0.096525 / 0.000000 / 0.000064
  n |                      get_players |      10000 | 0.006736 / 0.000001 / 0.000042
  p |                          cmd_go |          1 | 0.006293 / 0.006293 / 0.006293
  p |                      plugin_init |          1 | 0.000002 / 0.000002 / 0.000002
  f |        IterateThroughAllPlayers |      10000 | 0.108971 / 0.000010 / 0.000211
  f |                    UseGetPlayers |      10000 | 0.009358 / 0.000001 / 0.000042
0 natives, 0 public callbacks, 2 function calls were not executed.

TOTAL TIME FOR:
        IterateThroughAllPlayers
                0.205496
        UseGetPlayers
                0.016094

PHP Code:

#include <amxmodx>
#include <amxmisc>

#define PLUGIN    "Get Players"
#define AUTHOR    "stupok"
#define VERSION    "1.0"

new g_iMaxPlayers

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
g_iMaxPlayers get_maxplayers()
    
    
register_srvcmd"go""cmd_go" )
}

public 
cmd_go()
{
    for( new 
010000i++ )
    {
        
IterateThroughAllPlayers()
    }
    
    for( new 
010000i++ )
    {
        
UseGetPlayers()
    }
    
    
server_cmd"quit" )
}

IterateThroughAllPlayers()
{
    for( new 
1<= g_iMaxPlayersi++ )
    {
        if( 
is_user_connected) )
        {
            
//
        
}
    }
}

UseGetPlayers()
{
    static 
aPlayers[32], iPlayersNumid
    
    get_players
aPlayersiPlayersNum"" )
    
    for( new 
0iPlayersNumi++ )
    {
        
id aPlayers[i]
    }



Emp` 04-17-2009 16:12

Re: amxmodx profiler
 
Quote:

Originally Posted by stupok (Post 807263)
Here's an example, but your mileage may vary depending on your specific applications. If you give me some ideas, then I might test them.

Try saving whether a player is connected into a global during client_authorized and client_disconnect.

Michael_Jim 04-17-2009 18:23

Re: amxmodx profiler
 
Quote:

Originally Posted by diamond-optic (Post 789281)
linux binary is crashing for me on startup too...

same here. no chance to run it :cry:

stupok 04-18-2009 12:55

Re: amxmodx profiler
 
Quote:

Originally Posted by Emp` (Post 807847)
Try saving whether a player is connected into a global during client_authorized and client_disconnect.

Ok.

Caching the results of cient_authorized() and client_disconnect() increases the speed of IterateThroughAllPlayers() tremendously. Now, the get_players() method is one order of magnitude slower than iterating through each player.

Here are the results: (NOTE: the previous post had 10,000 iterations, this had 1,000,000 iterations)

Code:

32 BOTS, CACHED CONNECT/DISCONNECT

date: Sat Apr 18 11:46:00 2009 map: de_dust
type |                            name |      calls | time / min / max
-------------------------------------------------------------------
  n |                  register_plugin |          1 | 0.000001 / 0.000001 / 0.000001
  n |                  get_maxplayers |          1 | 0.000000 / 0.000000 / 0.000000
  n |                  register_srvcmd |          1 | 0.000059 / 0.000059 / 0.000059
  n |                      server_cmd |          1 | 0.000003 / 0.000003 / 0.000003
  n |                      get_players |    1000000 | 0.660214 / 0.000001 / 0.001794
  p |                client_authorized |        32 | 0.000019 / 0.000001 / 0.000001
  p |                client_disconnect |        32 | 0.000010 / 0.000000 / 0.000000

  p |                          cmd_go |          1 | 0.623259 / 0.623259 / 0.623259
  p |                      plugin_init |          1 | 0.000002 / 0.000002 / 0.000002
  f |        IterateThroughAllPlayers |    1000000 | 0.604227 / 0.000001 / 0.001491
  f |                    UseGetPlayers |    1000000 | 0.934782 / 0.000001 / 0.001892
0 natives, 0 public callbacks, 4 function calls were not executed.

TOTAL TIME FOR:
        IterateThroughAllPlayers
                0.604227
        UseGetPlayers
                1.594996

Here's the plugin:

PHP Code:

#include <amxmodx>
#include <amxmisc>

#define PLUGIN    "Get Players"
#define AUTHOR    "stupok"
#define VERSION    "1.0"

new g_iMaxPlayers
new g_bClientConnected[33]

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
g_iMaxPlayers get_maxplayers()
    
    
register_srvcmd"go""cmd_go" )
}

public 
cmd_go()
{
    for( new 
01000000i++ )
    {
        
IterateThroughAllPlayers()
    }
    
    for( new 
01000000i++ )
    {
        
UseGetPlayers()
    }
    
    
server_cmd"quit" )
}

public 
client_authorizedid )
    
g_bClientConnected[id] = true

public client_disconnectid )
    
g_bClientConnected[id] = false

IterateThroughAllPlayers
()
{
    for( new 
1<= g_iMaxPlayersi++ )
    {
        if( 
g_bClientConnected[i] )
        {
            
//
        
}
    }
}

UseGetPlayers()
{
    static 
aPlayers[32], iPlayersNumid
    
    get_players
aPlayersiPlayersNum"" )
    
    for( new 
0iPlayersNumi++ )
    {
        
id aPlayers[i]
    }




All times are GMT -4. The time now is 21:56.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.