[INC] Debug Utility
#1
Un include que arme hace años cuanto no podía encontrar el problema en un zp de mas de 20k de lineas xd

Código PHP:
/*********************************
  *** Debug Utility By Destro ***

- Activar:
#define DEBUG_ENABLE

- Configuración opcional:

#define DEBUG_LEVEL 3 // default: 3

// Números de registros que se muestran al usar debug_end()
#define DEBUG_MAX_RECORDS // default: 20

#define DEBUG_ENABLE_GAMETIME // Agrega el gametime al mensaje
#define DEBUG_ENABLE_CLIENT // Los mensajes también se muestran a todos los jugadores
#define DEBUG_ONLY_CONSOLE // debug_log() y debug_hidden() funcionan como debug_console()
#define DEBUG_ONLY_LOGS // debug_console() y debug_hidden() funcionan como debug_log()
#define DEBUG_HIDDEN_ALL // debug_log() y debug_console() funcionan como debug_hidden()
#define DEBUG_LOGFILE "debug.log" // Define el nombre del archivo, si no se define el nombre se establece como "debug_%PLUGIN%.log"


- Funciones:
# Inicializa las variables, usar en plugin_init() o plugin_precache()
@ debug_init()

# Guarda los últimos registros en el log
@ debug_end()

# Muestra mensaje en la consola del servidor
@ debug_console1(info[], any:...)
@ debug_console2(info[], any:...)
@ debug_console3(info[], any:...)

# Muestra mensaje en la consola del servidor y en el log
@ debug_log1(info[], any:...)
@ debug_log2(info[], any:...)
@ debug_log3(info[], any:...)
 
# No muestra mensaje, solo se puede ver al utilizar debug_end()
@ debug_hidden(info[], any:...)

# Calcula los milisegundos entre Start y End (el resultado se registra en el log)
@ debug_performance_start(keyname)
@ debug_performance_end(keyname, info[], any:...)

**********************************************************************/ 

Ejemplo:
Código PHP:
#include <amxmodx>
#include <fuzzywords>

#define DEBUG_ENABLE
#include <debug>


#define PLUGIN "Basic SpellChecker"
#define VERSION "1.0"
#define AUTHOR "Destro"


new Trie:g_TrieDict

enum _
:_EntryStruct
{
 
Entry_Original[32],
 
Entry_Normalize[32], // Second Search
 
Entry_Soundex[32], // First Search
 
Entry_Freq // Frequency
}


public 
plugin_init()
{
 
// Para encontrar el error de un crash, lo mejor es tener control sobre el inicio y la finalización de las funciones publicas
 // Una vez que detectas en cual public esta el problema, lo demás es mas fácil
 
debug_hidden("plugin_init() PRE")

 
register_plugin(PLUGINVERSIONAUTHOR)
 
 
register_srvcmd("sc""svcmd_spellcheck")

 
set_task(2.0"task_delay")

 
debug_hidden("plugin_init() POST")
}

public 
plugin_end()
{
 
debug_hidden("plugin_end() PRE")

 
TrieDestroy(g_TrieDict)

 
debug_hidden("plugin_end() POST")

 
// Depende del tipo de crash, puede o no llamarse a plugin_end()
 // Si no se llama, vas a tener que considerar en usar #define DEBUG_ONLY_LOGS
 // Pero trata de no loggear funciones que se llamen decenas de veces por segundo, sino matas al disco
 
debug_end()
}

public 
task_delay()
{
 
debug_hidden("task_delay() PRE")


 
// Veamos cuanto tiempo tarda en cargar el diccionario...
 
debug_performance_start(hola)
 
load_dictionary()
 
debug_performance_end(hola"load_dictionary()")


 
debug_hidden("task_delay() POST")
}

load_dictionary()
{
 new 
entry[_EntryStruct], Array:af
 g_TrieDict 
TrieCreate()

 
fopen("es-AR.dic""r")
 if(!
f)
 {
 
debug_log1("Error al cargar el diccionario")
 return
 }

 new 
maxrepeatmaxrepeatKey[32

 while(!
feof(f))
 {
 
fgets(fentry[Entry_Original], 31)

 
trim(entry[Entry_Original])

 
word_normalize(entry[Entry_Original], entry[Entry_Normalize], 31)
 
metaphoneES(entry[Entry_Original], entry[Entry_Soundex], 31)


 if(
TrieKeyExists(g_TrieDictentry[Entry_Soundex]))
 {
 
TrieGetCell(g_TrieDictentry[Entry_Soundex], a)
 
ArrayPushArray(aentry)

 if(
ArraySize(a) > maxrepeat)
 {
 
copy(maxrepeatKey31entry[Entry_Soundex])
 
maxrepeat ArraySize(a)
 }
 }
 else {
 
ArrayCreate(_EntryStruct1)

 
ArrayPushArray(aentry)
 
TrieSetCell(g_TrieDictentry[Entry_Soundex], a)
 }

 }

 
fclose(f)

 
debug_log1("dictionary max repeat metaphone: %d - %d"maxrepeatmaxrepeatKey)
}

public 
svcmd_spellcheck()
{
 
debug_hidden("svcmd_spellcheck() PRE")

 new 
input[32], soundkey[32], normalize[32]

 
read_argv(1input31)

 
word_normalize(inputnormalize41)
 
metaphoneES(normalizesoundkey31)


 if(
TrieKeyExists(g_TrieDictsoundkey))
 {
 
server_print("Sugerencias para: ^"%s^" (%s) -> [%s] :"inputnormalizesoundkey)

 new 
entry[_EntryStruct], Array:a

 TrieGetCell
(g_TrieDictsoundkeya)

 new 
size ArraySize(a)

 
debug_performance_start(sort)
 
ArraySort(a"ArraySortResult"normalize31)
 
debug_performance_end(sort,"ArraySortResult")

 for(new 
isizei++)
 {
 
ArrayGetArray(aientry)

 new 
soundes[36]
 
metaphoneES(entry[Entry_Original], soundes35false)

 
server_print("- %s ^t%s  ^t->  [%s]"entry[Entry_Original], entry[Entry_Normalize], entry[Entry_Soundex])
 }

 
server_print("^n")
 
debug_hidden("svcmd_spellcheck() POST")
 return
 }

 
server_print("No se encontro  [%s]^n"soundkey)
 
debug_hidden("svcmd_spellcheck() POST")
}

public 
ArraySortResult(Array:aitem1item2, const normalize[])
{
 static 
data1[_EntryStruct], data2[_EntryStruct]

 
ArrayGetArray(aitem1data1)
 
ArrayGetArray(aitem2data2)

 new 
distance1 damerau_levenshtein(data1[Entry_Normalize], normalize)
 new 
distance2 damerau_levenshtein(data2[Entry_Normalize], normalize)

 if(
distance1 distance2)
 return -
1
 
if(distance1 distance2)
 return 
1

 
if(data1[Entry_Freq] < data2[Entry_Freq])
 return -
1
 
if(data1[Entry_Freq] > data2[Entry_Freq])
 return 
1

 
return 0


Log:
Código:
[DEBUG START: 23/09/2018 - 00:50:59] - Map: "de_dust"  |  Plugin: "soundex_metaphone"
[DEBUG] dictionary max repeat metaphone: 68 - 83
[DEBUG Performance] "load_dictionary()" -> (1318ms)
[DEBUG END:  23/09/2018 - 00:51:01] - Map: "de_dust"  |  Plugin: "soundex_metaphone"
# - GameTime: (4.9261)  |  Last: (4.9261)  |  Difference: (0ms)
# - Records List:
# 7:  (3926ms) - [plugin_init() PRE]
# 6:  (3926ms) - [plugin_init() POST]
# 5:  (1852ms) - [task_delay() PRE]
# 4:  (1852ms) - [dictionary max repeat metaphone: 68 - 83]
# 3:  (1852ms) - [task_delay() POST]
# 2:  (curframe) - [plugin_end() PRE]
# 1:  (curframe) - [plugin_end() POST]
----------------------------------------------------------------------
Nota: El gametime es el tiempo desde el inicio del frame (serverframe).
Nota2: En la lista de registros 'Records List', los milisegundos es la diferencia del gametime actual y el que tenían cuando fueron registrados.


.inc   debug.inc (Tamaño: 9.16 KB / Descargas: 29)
Responder
#2
Brutal, bonitos aportes.
Responder
#3
(22/09/2018, 11:44 PM)metita escribió: Brutal, bonitos aportes.
[Imagen: 76561198350936449.png]

Cita:Los precios en la moneda venezolana se fijarán a partir de la reconversión monetaria y valdrá mucho menos de lo que cuesta una Cachapa con queso.
Responder
#4
(23/09/2018, 01:15 AM)KrR10VnZl escribió:
(22/09/2018, 11:44 PM)metita escribió: Brutal, bonitos aportes.

Responder
#5
(23/09/2018, 01:58 PM)Skylar escribió:
(23/09/2018, 01:15 AM)KrR10VnZl escribió:
(22/09/2018, 11:44 PM)metita escribió: Brutal, bonitos aportes.
Responder
#6
Disculpen, tengo una duda, aveces cuando un servidor cae por un bug de un plugin y no sale el log, con esto saldria la linea del posible bug??
Responder
#7
(23/09/2018, 04:42 PM)Spirit escribió: Disculpen, tengo una duda, aveces cuando un servidor cae por un bug de un plugin y no sale el log, con esto saldria la linea del posible bug??

si lo implementas en el plugin donde posiblemente crees que hara caer tu servidor si, luego te fijas el pre y post si lo imprime
[Imagen: b_350_20_323957_202743_f19a15_111111.png]

(18/11/2014, 05:47 PM)Neeeeeeeeeel.- escribió: Por qué necesitan una guía para todo? Meté mano y que salga lo que salga... es la mejor forma de aprender.

(16/05/2016, 11:08 PM)kikizon2 escribió: No cabe duda que tienen mierda en vez de cerebro, par de pendejos v:
Responder
#8
Vale, y supongo que lo tengo que hacer tal cual el ejemplo que lo paso el?, gracias y excelente plugin!!
Responder


Salto de foro:


Usuarios navegando en este tema: 1 invitado(s)