summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2011-06-01 09:07:17 +0200
committerSebastien Helleu <flashcode@flashtux.org>2011-06-01 09:07:17 +0200
commit35120b633c5a7dd01ea73d8073d3a1d7da63bd84 (patch)
tree3c053c282677884cae07179942832e977c13df21 /src/core
parent60bba82150debdeea71f92376c0ba25133150b2f (diff)
downloadweechat-35120b633c5a7dd01ea73d8073d3a1d7da63bd84.zip
core: add option "infolists" for command /debug
Diffstat (limited to 'src/core')
-rw-r--r--src/core/wee-command.c28
-rw-r--r--src/core/wee-debug.c91
-rw-r--r--src/core/wee-debug.h1
3 files changed, 109 insertions, 11 deletions
diff --git a/src/core/wee-command.c b/src/core/wee-command.c
index 64463c4d4..35dadf953 100644
--- a/src/core/wee-command.c
+++ b/src/core/wee-command.c
@@ -1152,6 +1152,10 @@ COMMAND_CALLBACK(debug)
{
gui_color_dump (buffer);
}
+ else if (string_strcasecmp (argv[1], "infolists") == 0)
+ {
+ debug_infolists ();
+ }
else if (string_strcasecmp (argv[1], "memory") == 0)
{
debug_memory ();
@@ -4833,24 +4837,26 @@ command_init ()
N_("list"
" || set <plugin> <level>"
" || dump [<plugin>]"
- " || buffer|color|memory|term|windows"),
- N_(" list: list plugins with debug levels\n"
- " set: set debug level for plugin\n"
- " plugin: name of plugin (\"core\" for WeeChat core)\n"
- " level: debug level for plugin (0 = disable debug)\n"
- " dump: save memory dump in WeeChat log file (same "
+ " || buffer|color|infolists|memory|term|windows"),
+ N_(" list: list plugins with debug levels\n"
+ " set: set debug level for plugin\n"
+ " plugin: name of plugin (\"core\" for WeeChat core)\n"
+ " level: debug level for plugin (0 = disable debug)\n"
+ " dump: save memory dump in WeeChat log file (same "
"dump is written when WeeChat crashes)\n"
- " buffer: dump buffer content with hexadecimal values "
+ " buffer: dump buffer content with hexadecimal values "
"in log file\n"
- " color: display infos about current color pairs\n"
- " memory: display infos about memory usage\n"
- " term: display infos about terminal\n"
- "windows: display windows tree"),
+ " color: display infos about current color pairs\n"
+ "infolists: display infos about infolists\n"
+ " memory: display infos about memory usage\n"
+ " term: display infos about terminal\n"
+ " windows: display windows tree"),
"list"
" || set %(plugins_names)|core"
" || dump %(plugins_names)|core"
" || buffer"
" || color"
+ " || infolists"
" || memory"
" || term"
" || windows",
diff --git a/src/core/wee-debug.c b/src/core/wee-debug.c
index 009349b74..8b3458c11 100644
--- a/src/core/wee-debug.c
+++ b/src/core/wee-debug.c
@@ -29,6 +29,8 @@
#ifdef HAVE_MALLINFO
#include <malloc.h>
#endif
+#include <string.h>
+#include <time.h>
#include "weechat.h"
#include "wee-backtrace.h"
@@ -293,6 +295,95 @@ debug_memory ()
}
/*
+ * debug_infolists: display list of infolists in memory
+ */
+
+void
+debug_infolists ()
+{
+ struct t_infolist *ptr_infolist;
+ struct t_infolist_item *ptr_item;
+ struct t_infolist_var *ptr_var;
+ int i, count, count_items, count_vars, size_structs, size_data;
+ int total_items, total_vars, total_size;
+
+ count = 0;
+ for (ptr_infolist = weechat_infolists; ptr_infolist;
+ ptr_infolist = ptr_infolist->next_infolist)
+ {
+ count++;
+ }
+
+ gui_chat_printf (NULL, "");
+ gui_chat_printf (NULL, "%d infolists in memory (%s)", count,
+ (count == 0) ?
+ "this is ok!" :
+ "WARNING: this is probably a memory leak in WeeChat or "
+ "plugins/scripts!");
+
+ if (count > 0)
+ {
+ i = 0;
+ total_items = 0;
+ total_vars = 0;
+ total_size = 0;
+ for (ptr_infolist = weechat_infolists; ptr_infolist;
+ ptr_infolist = ptr_infolist->next_infolist)
+ {
+ count_items = 0;
+ count_vars = 0;
+ size_structs = sizeof (*ptr_infolist);
+ size_data = 0;
+ for (ptr_item = ptr_infolist->items; ptr_item;
+ ptr_item = ptr_item->next_item)
+ {
+ count_items++;
+ total_items++;
+ size_structs += sizeof (*ptr_item);
+ for (ptr_var = ptr_item->vars; ptr_var;
+ ptr_var = ptr_var->next_var)
+ {
+ count_vars++;
+ total_vars++;
+ size_structs += sizeof (*ptr_var);
+ if (ptr_var->value)
+ {
+ switch (ptr_var->type)
+ {
+ case INFOLIST_INTEGER:
+ size_data += sizeof (int);
+ break;
+ case INFOLIST_STRING:
+ size_data += strlen ((char *)(ptr_var->value));
+ break;
+ case INFOLIST_POINTER:
+ size_data += sizeof (void *);
+ break;
+ case INFOLIST_BUFFER:
+ size_data += ptr_var->size;
+ break;
+ case INFOLIST_TIME:
+ size_data += sizeof (time_t);
+ break;
+ }
+ }
+ }
+ }
+ gui_chat_printf (NULL,
+ " %d: infolist 0x%lx: %d items, %d vars - "
+ "structs: %d, data: %d (total: %d bytes)",
+ i + 1, ptr_infolist, count_items, count_vars,
+ size_structs, size_data, size_structs + size_data);
+ total_size += size_structs + size_data;
+ i++;
+ }
+ gui_chat_printf (NULL,
+ " Total: %d items, %d vars - %d bytes",
+ total_items, total_vars, total_size);
+ }
+}
+
+/*
* debug_init: hook signals for debug
*/
diff --git a/src/core/wee-debug.h b/src/core/wee-debug.h
index 652ede38b..94256d206 100644
--- a/src/core/wee-debug.h
+++ b/src/core/wee-debug.h
@@ -25,6 +25,7 @@ struct t_gui_window_tree;
extern void debug_sigsegv ();
extern void debug_windows_tree ();
extern void debug_memory ();
+extern void debug_infolists ();
extern void debug_init ();
#endif /* __WEECHAT_DEBUG_H */