I make this code:
PHP Code:
#define DEBUG_DRAW_NONE 0
#define DEBUG_DRAW_CONSOLE 1
#define DEBUG_DRAW_LOG 2
#define _DEBUG_BUFF 512
#define _DEBUG_CALLS 25
#define _DEBUG_MAXLINES 300
new _debug_buff[_DEBUG_CALLS][_DEBUG_BUFF], Float:_debug_time[_DEBUG_CALLS]
new _debug_start, _debug_size, Float:_gametime
new const debug_file[] = "debug.log"
stock _debug(draw, const func[], any:...)
{
new slot
if(_debug_size == _DEBUG_CALLS)
{
slot = _debug_start++
_debug_start = _debug_start%_DEBUG_CALLS
}
else slot = _debug_size++
vformat(_debug_buff[slot], _DEBUG_BUFF-1, func, 3)
_debug_time[slot] = _gametime = get_gametime()
if(draw == DEBUG_DRAW_NONE)
return
if(draw == DEBUG_DRAW_CONSOLE)
server_print("*DEBUG: -gametime: (%.3f) | -info[%s]", _gametime, _debug_buff[slot])
else /*if(draw == DEBUG_DRAW_LOG) */
{
static lines
if(++lines > _DEBUG_MAXLINES)
{
lines = 0
delete_file(debug_file)
log_to_file(debug_file, "==== Empty debug file =============")
}
log_to_file(debug_file, "*DEBUG: -gametime: (%.3f) | -info[%s]", _gametime, _debug_buff[slot])
}
}
stock _debug_draw(max_calls=_DEBUG_CALLS, same_frames=true)
{
_gametime = get_gametime()
new map[32], amxx_file[32]
get_mapname(map, 31)
get_plugin(-1, amxx_file, 31)
log_to_file(debug_file, "# DEBUG END: plugin: [%s] - gametime: (%.3f) - map: [%s] ---", amxx_file, _gametime, map)
if(_debug_size == 0)
{
log_to_file(debug_file, "No call log")
log_to_file(debug_file, "----------------------------------------------------------------------^n")
return
}
new _max, Float:_lastcall_time, slot
_max = clamp(max_calls, 1, _debug_size)
slot = _debug_start - 1
if(slot < 0) slot += _debug_size
_lastcall_time = _debug_time[slot]
if(same_frames)
log_to_file(debug_file, "# Time Difference: (%dms)", floatround((_gametime - _lastcall_time) * 1000.0))
for(new count=1; count <= _max; count++)
{
slot = _debug_start - count
if(slot < 0) slot += _debug_size
if(same_frames)
{
if(_lastcall_time != _debug_time[slot])
break
log_to_file(debug_file, "#%2d: -info:[%s]", count, _debug_buff[slot])
}
else {
log_to_file(debug_file, "#%2d: -difference: (%dms) | -info: [%s]", count, floatround((_gametime - _debug_time[slot]) * 1000.0), _debug_buff[slot])
}
}
log_to_file(debug_file, "----------------------------------------------------------------------^n")
}
Use:
PHP Code:
public fw_PlayerPreThink(id)
{
_debug(DEBUG_DRAW_NONE, "fw_PlayerPreThink Pre")
// code...
_debug(DEBUG_DRAW_NONE, "fw_PlayerPreThink Post")
}
public plugin_end()
{
_debug_draw()
}
Usually, the output is something like this:
Code:
L 06/10/2015 - 11:49:46: # DEBUG END: plugin: [file.amxx] - gametime: (784.340) - map: [de_dust2] ---
L 06/10/2015 - 11:49:46: # Time Difference: (10ms) // Positive number
L 06/10/2015 - 11:49:46: # 1: -info:[fw_PlayerPreThink Post2]
L 06/10/2015 - 11:49:46: # 2: -info:[fw_PlayerPreThink Pre]
L 06/10/2015 - 11:49:46: # 3: -info:[fw_PlayerPreThink Post2]
L 06/10/2015 - 11:49:46: # 4: -info:[fw_PlayerPreThink Pre]
L 06/10/2015 - 11:49:46: ----------------------------------------------------------------------
Rare times i get this:
Code:
L 06/10/2015 - 11:49:46: # DEBUG END: plugin: [file.amxx] - gametime: (983.158) - map: [de_dust2] ---
L 06/10/2015 - 11:49:46: # Time Difference: (-10ms) // negative number
L 06/10/2015 - 11:49:46: # 1: -info:[fw_PlayerPreThink Post2]
L 06/10/2015 - 11:49:46: # 2: -info:[fw_PlayerPreThink Pre]
L 06/10/2015 - 11:49:46: # 3: -info:[fw_PlayerPreThink Post2]
L 06/10/2015 - 11:49:46: # 4: -info:[fw_PlayerPreThink Pre]
L 06/10/2015 - 11:49:46: ----------------------------------------------------------------------
What is the cause of a negative value?
__________________