summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/hook/wee-hook-command-run.c5
-rw-r--r--src/core/hook/wee-hook-command.c5
-rw-r--r--src/core/hook/wee-hook-completion.c5
-rw-r--r--src/core/hook/wee-hook-config.c5
-rw-r--r--src/core/hook/wee-hook-fd.c7
-rw-r--r--src/core/hook/wee-hook-focus.c9
-rw-r--r--src/core/hook/wee-hook-hdata.c5
-rw-r--r--src/core/hook/wee-hook-hsignal.c5
-rw-r--r--src/core/hook/wee-hook-info-hashtable.c5
-rw-r--r--src/core/hook/wee-hook-info.c5
-rw-r--r--src/core/hook/wee-hook-infolist.c5
-rw-r--r--src/core/hook/wee-hook-line.c5
-rw-r--r--src/core/hook/wee-hook-modifier.c5
-rw-r--r--src/core/hook/wee-hook-print.c5
-rw-r--r--src/core/hook/wee-hook-process.c5
-rw-r--r--src/core/hook/wee-hook-signal.c5
-rw-r--r--src/core/hook/wee-hook-timer.c7
-rw-r--r--src/core/wee-command.c38
-rw-r--r--src/core/wee-debug.c3
-rw-r--r--src/core/wee-debug.h2
-rw-r--r--src/core/wee-hook.c63
-rw-r--r--src/core/wee-hook.h11
-rw-r--r--src/gui/gui-bar-item.c33
23 files changed, 202 insertions, 41 deletions
diff --git a/src/core/hook/wee-hook-command-run.c b/src/core/hook/wee-hook-command-run.c
index 7d95d8042..6815fb7fd 100644
--- a/src/core/hook/wee-hook-command-run.c
+++ b/src/core/hook/wee-hook-command-run.c
@@ -101,6 +101,7 @@ int
hook_command_run_exec (struct t_gui_buffer *buffer, const char *command)
{
struct t_hook *ptr_hook, *next_hook;
+ struct t_hook_exec_cb hook_exec_cb;
int rc, hook_matching, length;
char *command2;
const char *ptr_string, *ptr_command;
@@ -149,13 +150,13 @@ hook_command_run_exec (struct t_gui_buffer *buffer, const char *command)
if (hook_matching)
{
- ptr_hook->running = 1;
+ hook_callback_start (ptr_hook, &hook_exec_cb);
rc = (HOOK_COMMAND_RUN(ptr_hook, callback)) (
ptr_hook->callback_pointer,
ptr_hook->callback_data,
buffer,
ptr_command);
- ptr_hook->running = 0;
+ hook_callback_end (ptr_hook, &hook_exec_cb);
if (rc == WEECHAT_RC_OK_EAT)
{
if (command2)
diff --git a/src/core/hook/wee-hook-command.c b/src/core/hook/wee-hook-command.c
index 0cdaf202a..355b3c63a 100644
--- a/src/core/hook/wee-hook-command.c
+++ b/src/core/hook/wee-hook-command.c
@@ -364,6 +364,7 @@ hook_command_exec (struct t_gui_buffer *buffer, int any_plugin,
struct t_hook *ptr_hook, *next_hook;
struct t_hook *hook_plugin, *hook_other_plugin, *hook_other_plugin2;
struct t_hook *hook_incomplete_command;
+ struct t_hook_exec_cb hook_exec_cb;
char **argv, **argv_eol;
const char *ptr_command_name;
int argc, rc, length_command_name, allow_incomplete_commands;
@@ -500,7 +501,7 @@ hook_command_exec (struct t_gui_buffer *buffer, int any_plugin,
else
{
/* execute the command! */
- ptr_hook->running++;
+ hook_callback_start (ptr_hook, &hook_exec_cb);
rc = (int) (HOOK_COMMAND(ptr_hook, callback))
(ptr_hook->callback_pointer,
ptr_hook->callback_data,
@@ -508,7 +509,7 @@ hook_command_exec (struct t_gui_buffer *buffer, int any_plugin,
argc,
argv,
argv_eol);
- ptr_hook->running--;
+ hook_callback_end (ptr_hook, &hook_exec_cb);
if (rc == WEECHAT_RC_ERROR)
rc = HOOK_COMMAND_EXEC_ERROR;
else
diff --git a/src/core/hook/wee-hook-completion.c b/src/core/hook/wee-hook-completion.c
index 16b1a566e..6f0eb1d19 100644
--- a/src/core/hook/wee-hook-completion.c
+++ b/src/core/hook/wee-hook-completion.c
@@ -107,6 +107,7 @@ hook_completion_exec (struct t_weechat_plugin *plugin,
struct t_gui_completion *completion)
{
struct t_hook *ptr_hook, *next_hook;
+ struct t_hook_exec_cb hook_exec_cb;
const char *pos;
char *item;
@@ -134,14 +135,14 @@ hook_completion_exec (struct t_weechat_plugin *plugin,
&& !ptr_hook->running
&& (strcmp (HOOK_COMPLETION(ptr_hook, completion_item), item) == 0))
{
- ptr_hook->running = 1;
+ hook_callback_start (ptr_hook, &hook_exec_cb);
(void) (HOOK_COMPLETION(ptr_hook, callback))
(ptr_hook->callback_pointer,
ptr_hook->callback_data,
completion_item,
buffer,
completion);
- ptr_hook->running = 0;
+ hook_callback_end (ptr_hook, &hook_exec_cb);
}
ptr_hook = next_hook;
diff --git a/src/core/hook/wee-hook-config.c b/src/core/hook/wee-hook-config.c
index cacf8f0d5..5a6ec8e91 100644
--- a/src/core/hook/wee-hook-config.c
+++ b/src/core/hook/wee-hook-config.c
@@ -98,6 +98,7 @@ void
hook_config_exec (const char *option, const char *value)
{
struct t_hook *ptr_hook, *next_hook;
+ struct t_hook_exec_cb hook_exec_cb;
hook_exec_start ();
@@ -111,13 +112,13 @@ hook_config_exec (const char *option, const char *value)
&& (!HOOK_CONFIG(ptr_hook, option)
|| (string_match (option, HOOK_CONFIG(ptr_hook, option), 0))))
{
- ptr_hook->running = 1;
+ hook_callback_start (ptr_hook, &hook_exec_cb);
(void) (HOOK_CONFIG(ptr_hook, callback))
(ptr_hook->callback_pointer,
ptr_hook->callback_data,
option,
value);
- ptr_hook->running = 0;
+ hook_callback_end (ptr_hook, &hook_exec_cb);
}
ptr_hook = next_hook;
diff --git a/src/core/hook/wee-hook-fd.c b/src/core/hook/wee-hook-fd.c
index 872e54546..441dd0b8b 100644
--- a/src/core/hook/wee-hook-fd.c
+++ b/src/core/hook/wee-hook-fd.c
@@ -203,8 +203,9 @@ hook_fd (struct t_weechat_plugin *plugin, int fd, int flag_read,
void
hook_fd_exec ()
{
- int i, num_fd, timeout, ready, found;
struct t_hook *ptr_hook, *next_hook;
+ struct t_hook_exec_cb hook_exec_cb;
+ int i, num_fd, timeout, ready, found;
if (!weechat_hooks[HOOK_TYPE_FD])
return;
@@ -279,12 +280,12 @@ hook_fd_exec ()
}
if (found)
{
- ptr_hook->running = 1;
+ hook_callback_start (ptr_hook, &hook_exec_cb);
(void) (HOOK_FD(ptr_hook, callback)) (
ptr_hook->callback_pointer,
ptr_hook->callback_data,
HOOK_FD(ptr_hook, fd));
- ptr_hook->running = 0;
+ hook_callback_end (ptr_hook, &hook_exec_cb);
}
}
diff --git a/src/core/hook/wee-hook-focus.c b/src/core/hook/wee-hook-focus.c
index 744382e44..a015a37f6 100644
--- a/src/core/hook/wee-hook-focus.c
+++ b/src/core/hook/wee-hook-focus.c
@@ -153,6 +153,7 @@ hook_focus_get_data (struct t_hashtable *hashtable_focus1,
struct t_hashtable *hashtable_focus2)
{
struct t_hook *ptr_hook, *next_hook;
+ struct t_hook_exec_cb hook_exec_cb;
struct t_hashtable *hashtable1, *hashtable2, *hashtable_ret;
const char *focus1_chat, *focus1_bar_item_name, *keys;
char **list_keys, *new_key;
@@ -185,12 +186,12 @@ hook_focus_get_data (struct t_hashtable *hashtable_focus1,
&& (strcmp (HOOK_FOCUS(ptr_hook, area), focus1_bar_item_name) == 0))))
{
/* run callback for focus #1 */
- ptr_hook->running = 1;
+ hook_callback_start (ptr_hook, &hook_exec_cb);
hashtable_ret = (HOOK_FOCUS(ptr_hook, callback))
(ptr_hook->callback_pointer,
ptr_hook->callback_data,
hashtable1);
- ptr_hook->running = 0;
+ hook_callback_end (ptr_hook, &hook_exec_cb);
if (hashtable_ret)
{
if (hashtable_ret != hashtable1)
@@ -209,12 +210,12 @@ hook_focus_get_data (struct t_hashtable *hashtable_focus1,
/* run callback for focus #2 */
if (hashtable2)
{
- ptr_hook->running = 1;
+ hook_callback_start (ptr_hook, &hook_exec_cb);
hashtable_ret = (HOOK_FOCUS(ptr_hook, callback))
(ptr_hook->callback_pointer,
ptr_hook->callback_data,
hashtable2);
- ptr_hook->running = 0;
+ hook_callback_end (ptr_hook, &hook_exec_cb);
if (hashtable_ret)
{
if (hashtable_ret != hashtable2)
diff --git a/src/core/hook/wee-hook-hdata.c b/src/core/hook/wee-hook-hdata.c
index 6fefbcd54..2da69a56e 100644
--- a/src/core/hook/wee-hook-hdata.c
+++ b/src/core/hook/wee-hook-hdata.c
@@ -102,6 +102,7 @@ struct t_hdata *
hook_hdata_get (struct t_weechat_plugin *plugin, const char *hdata_name)
{
struct t_hook *ptr_hook, *next_hook;
+ struct t_hook_exec_cb hook_exec_cb;
struct t_hdata *value;
/* make C compiler happy */
@@ -128,12 +129,12 @@ hook_hdata_get (struct t_weechat_plugin *plugin, const char *hdata_name)
&& !ptr_hook->running
&& (strcmp (HOOK_HDATA(ptr_hook, hdata_name), hdata_name) == 0))
{
- ptr_hook->running = 1;
+ hook_callback_start (ptr_hook, &hook_exec_cb);
value = (HOOK_HDATA(ptr_hook, callback))
(ptr_hook->callback_pointer,
ptr_hook->callback_data,
HOOK_HDATA(ptr_hook, hdata_name));
- ptr_hook->running = 0;
+ hook_callback_end (ptr_hook, &hook_exec_cb);
hook_exec_end ();
return value;
diff --git a/src/core/hook/wee-hook-hsignal.c b/src/core/hook/wee-hook-hsignal.c
index 1ed01f8b5..f849e36b4 100644
--- a/src/core/hook/wee-hook-hsignal.c
+++ b/src/core/hook/wee-hook-hsignal.c
@@ -129,6 +129,7 @@ int
hook_hsignal_send (const char *signal, struct t_hashtable *hashtable)
{
struct t_hook *ptr_hook, *next_hook;
+ struct t_hook_exec_cb hook_exec_cb;
int rc;
rc = WEECHAT_RC_OK;
@@ -144,13 +145,13 @@ hook_hsignal_send (const char *signal, struct t_hashtable *hashtable)
&& !ptr_hook->running
&& (hook_hsignal_match (signal, ptr_hook)))
{
- ptr_hook->running = 1;
+ hook_callback_start (ptr_hook, &hook_exec_cb);
rc = (HOOK_HSIGNAL(ptr_hook, callback))
(ptr_hook->callback_pointer,
ptr_hook->callback_data,
signal,
hashtable);
- ptr_hook->running = 0;
+ hook_callback_end (ptr_hook, &hook_exec_cb);
if (rc == WEECHAT_RC_OK_EAT)
break;
diff --git a/src/core/hook/wee-hook-info-hashtable.c b/src/core/hook/wee-hook-info-hashtable.c
index 66b493c79..0a96321fd 100644
--- a/src/core/hook/wee-hook-info-hashtable.c
+++ b/src/core/hook/wee-hook-info-hashtable.c
@@ -106,6 +106,7 @@ hook_info_get_hashtable (struct t_weechat_plugin *plugin, const char *info_name,
struct t_hashtable *hashtable)
{
struct t_hook *ptr_hook, *next_hook;
+ struct t_hook_exec_cb hook_exec_cb;
struct t_hashtable *value;
/* make C compiler happy */
@@ -125,13 +126,13 @@ hook_info_get_hashtable (struct t_weechat_plugin *plugin, const char *info_name,
&& !ptr_hook->running
&& (strcmp (HOOK_INFO_HASHTABLE(ptr_hook, info_name), info_name) == 0))
{
- ptr_hook->running = 1;
+ hook_callback_start (ptr_hook, &hook_exec_cb);
value = (HOOK_INFO_HASHTABLE(ptr_hook, callback))
(ptr_hook->callback_pointer,
ptr_hook->callback_data,
info_name,
hashtable);
- ptr_hook->running = 0;
+ hook_callback_end (ptr_hook, &hook_exec_cb);
hook_exec_end ();
return value;
diff --git a/src/core/hook/wee-hook-info.c b/src/core/hook/wee-hook-info.c
index b66c867eb..e7bae14ec 100644
--- a/src/core/hook/wee-hook-info.c
+++ b/src/core/hook/wee-hook-info.c
@@ -105,6 +105,7 @@ hook_info_get (struct t_weechat_plugin *plugin, const char *info_name,
const char *arguments)
{
struct t_hook *ptr_hook, *next_hook;
+ struct t_hook_exec_cb hook_exec_cb;
char *value;
/* make C compiler happy */
@@ -124,13 +125,13 @@ hook_info_get (struct t_weechat_plugin *plugin, const char *info_name,
&& !ptr_hook->running
&& (strcmp (HOOK_INFO(ptr_hook, info_name), info_name) == 0))
{
- ptr_hook->running = 1;
+ hook_callback_start (ptr_hook, &hook_exec_cb);
value = (HOOK_INFO(ptr_hook, callback))
(ptr_hook->callback_pointer,
ptr_hook->callback_data,
info_name,
arguments);
- ptr_hook->running = 0;
+ hook_callback_end (ptr_hook, &hook_exec_cb);
hook_exec_end ();
return value;
diff --git a/src/core/hook/wee-hook-infolist.c b/src/core/hook/wee-hook-infolist.c
index b75722c11..535d3a54d 100644
--- a/src/core/hook/wee-hook-infolist.c
+++ b/src/core/hook/wee-hook-infolist.c
@@ -106,6 +106,7 @@ hook_infolist_get (struct t_weechat_plugin *plugin, const char *infolist_name,
void *pointer, const char *arguments)
{
struct t_hook *ptr_hook, *next_hook;
+ struct t_hook_exec_cb hook_exec_cb;
struct t_infolist *value;
/* make C compiler happy */
@@ -125,14 +126,14 @@ hook_infolist_get (struct t_weechat_plugin *plugin, const char *infolist_name,
&& !ptr_hook->running
&& (strcmp (HOOK_INFOLIST(ptr_hook, infolist_name), infolist_name) == 0))
{
- ptr_hook->running = 1;
+ hook_callback_start (ptr_hook, &hook_exec_cb);
value = (HOOK_INFOLIST(ptr_hook, callback))
(ptr_hook->callback_pointer,
ptr_hook->callback_data,
infolist_name,
pointer,
arguments);
- ptr_hook->running = 0;
+ hook_callback_end (ptr_hook, &hook_exec_cb);
hook_exec_end ();
return value;
diff --git a/src/core/hook/wee-hook-line.c b/src/core/hook/wee-hook-line.c
index 6b3305fc4..1d29be96a 100644
--- a/src/core/hook/wee-hook-line.c
+++ b/src/core/hook/wee-hook-line.c
@@ -125,6 +125,7 @@ void
hook_line_exec (struct t_gui_line *line)
{
struct t_hook *ptr_hook, *next_hook;
+ struct t_hook_exec_cb hook_exec_cb;
struct t_hashtable *hashtable, *hashtable2;
char str_value[128], *str_tags;
@@ -182,12 +183,12 @@ hook_line_exec (struct t_gui_line *line)
HASHTABLE_SET_STR_NOT_NULL("message", line->data->message);
/* run callback */
- ptr_hook->running = 1;
+ hook_callback_start (ptr_hook, &hook_exec_cb);
hashtable2 = (HOOK_LINE(ptr_hook, callback))
(ptr_hook->callback_pointer,
ptr_hook->callback_data,
hashtable);
- ptr_hook->running = 0;
+ hook_callback_end (ptr_hook, &hook_exec_cb);
if (hashtable2)
{
diff --git a/src/core/hook/wee-hook-modifier.c b/src/core/hook/wee-hook-modifier.c
index ad5e372c6..6c584ed8f 100644
--- a/src/core/hook/wee-hook-modifier.c
+++ b/src/core/hook/wee-hook-modifier.c
@@ -100,6 +100,7 @@ hook_modifier_exec (struct t_weechat_plugin *plugin, const char *modifier,
const char *modifier_data, const char *string)
{
struct t_hook *ptr_hook, *next_hook;
+ struct t_hook_exec_cb hook_exec_cb;
char *new_msg, *message_modified;
/* make C compiler happy */
@@ -125,14 +126,14 @@ hook_modifier_exec (struct t_weechat_plugin *plugin, const char *modifier,
&& (string_strcasecmp (HOOK_MODIFIER(ptr_hook, modifier),
modifier) == 0))
{
- ptr_hook->running = 1;
+ hook_callback_start (ptr_hook, &hook_exec_cb);
new_msg = (HOOK_MODIFIER(ptr_hook, callback))
(ptr_hook->callback_pointer,
ptr_hook->callback_data,
modifier,
modifier_data,
message_modified);
- ptr_hook->running = 0;
+ hook_callback_end (ptr_hook, &hook_exec_cb);
/* empty string returned => message dropped */
if (new_msg && !new_msg[0])
diff --git a/src/core/hook/wee-hook-print.c b/src/core/hook/wee-hook-print.c
index debdc5436..6c95e3e11 100644
--- a/src/core/hook/wee-hook-print.c
+++ b/src/core/hook/wee-hook-print.c
@@ -121,6 +121,7 @@ void
hook_print_exec (struct t_gui_buffer *buffer, struct t_gui_line *line)
{
struct t_hook *ptr_hook, *next_hook;
+ struct t_hook_exec_cb hook_exec_cb;
char *prefix_no_color, *message_no_color;
if (!weechat_hooks[HOOK_TYPE_PRINT])
@@ -161,7 +162,7 @@ hook_print_exec (struct t_gui_buffer *buffer, struct t_gui_line *line)
HOOK_PRINT(ptr_hook, tags_array))))
{
/* run callback */
- ptr_hook->running = 1;
+ hook_callback_start (ptr_hook, &hook_exec_cb);
(void) (HOOK_PRINT(ptr_hook, callback))
(ptr_hook->callback_pointer,
ptr_hook->callback_data,
@@ -172,7 +173,7 @@ hook_print_exec (struct t_gui_buffer *buffer, struct t_gui_line *line)
(int)line->data->displayed, (int)line->data->highlight,
(HOOK_PRINT(ptr_hook, strip_colors)) ? prefix_no_color : line->data->prefix,
(HOOK_PRINT(ptr_hook, strip_colors)) ? message_no_color : line->data->message);
- ptr_hook->running = 0;
+ hook_callback_end (ptr_hook, &hook_exec_cb);
}
ptr_hook = next_hook;
diff --git a/src/core/hook/wee-hook-process.c b/src/core/hook/wee-hook-process.c
index a779f0144..4de66b131 100644
--- a/src/core/hook/wee-hook-process.c
+++ b/src/core/hook/wee-hook-process.c
@@ -792,6 +792,7 @@ void
hook_process_exec ()
{
struct t_hook *ptr_hook, *next_hook;
+ struct t_hook_exec_cb hook_exec_cb;
hook_exec_start ();
@@ -804,9 +805,9 @@ hook_process_exec ()
&& !ptr_hook->running
&& (HOOK_PROCESS(ptr_hook, child_pid) == 0))
{
- ptr_hook->running = 1;
+ hook_callback_start (ptr_hook, &hook_exec_cb);
hook_process_run (ptr_hook);
- ptr_hook->running = 0;
+ hook_callback_end (ptr_hook, &hook_exec_cb);
}
ptr_hook = next_hook;
diff --git a/src/core/hook/wee-hook-signal.c b/src/core/hook/wee-hook-signal.c
index c2d8c15c5..f809e2c18 100644
--- a/src/core/hook/wee-hook-signal.c
+++ b/src/core/hook/wee-hook-signal.c
@@ -129,6 +129,7 @@ int
hook_signal_send (const char *signal, const char *type_data, void *signal_data)
{
struct t_hook *ptr_hook, *next_hook;
+ struct t_hook_exec_cb hook_exec_cb;
int rc;
rc = WEECHAT_RC_OK;
@@ -144,14 +145,14 @@ hook_signal_send (const char *signal, const char *type_data, void *signal_data)
&& !ptr_hook->running
&& hook_signal_match (signal, ptr_hook))
{
- ptr_hook->running = 1;
+ hook_callback_start (ptr_hook, &hook_exec_cb);
rc = (HOOK_SIGNAL(ptr_hook, callback))
(ptr_hook->callback_pointer,
ptr_hook->callback_data,
signal,
type_data,
signal_data);
- ptr_hook->running = 0;
+ hook_callback_end (ptr_hook, &hook_exec_cb);
if (rc == WEECHAT_RC_OK_EAT)
break;
diff --git a/src/core/hook/wee-hook-timer.c b/src/core/hook/wee-hook-timer.c
index 389b6329d..418d22304 100644
--- a/src/core/hook/wee-hook-timer.c
+++ b/src/core/hook/wee-hook-timer.c
@@ -302,8 +302,9 @@ end:
void
hook_timer_exec ()
{
- struct timeval tv_time;
struct t_hook *ptr_hook, *next_hook;
+ struct t_hook_exec_cb hook_exec_cb;
+ struct timeval tv_time;
if (!weechat_hooks[HOOK_TYPE_TIMER])
return;
@@ -324,13 +325,13 @@ hook_timer_exec ()
&& (util_timeval_cmp (&HOOK_TIMER(ptr_hook, next_exec),
&tv_time) <= 0))
{
- ptr_hook->running = 1;
+ hook_callback_start (ptr_hook, &hook_exec_cb);
(void) (HOOK_TIMER(ptr_hook, callback))
(ptr_hook->callback_pointer,
ptr_hook->callback_data,
(HOOK_TIMER(ptr_hook, remaining_calls) > 0) ?
HOOK_TIMER(ptr_hook, remaining_calls) - 1 : -1);
- ptr_hook->running = 0;
+ hook_callback_end (ptr_hook, &hook_exec_cb);
if (!ptr_hook->deleted)
{
HOOK_TIMER(ptr_hook, last_exec).tv_sec = tv_time.tv_sec;
diff --git a/src/core/wee-command.c b/src/core/wee-command.c
index 09e1b0001..58fc83c9d 100644
--- a/src/core/wee-command.c
+++ b/src/core/wee-command.c
@@ -1988,7 +1988,8 @@ COMMAND_CALLBACK(debug)
struct t_config_option *ptr_option;
struct t_weechat_plugin *ptr_plugin;
struct timeval time_start, time_end;
- char *result;
+ char *result, *str_threshold;
+ long long threshold;
int debug;
/* make C compiler happy */
@@ -2023,6 +2024,28 @@ COMMAND_CALLBACK(debug)
return WEECHAT_RC_OK;
}
+ if (string_strcmp (argv[1], "callbacks") == 0)
+ {
+ COMMAND_MIN_ARGS(3, "callbacks");
+ threshold = util_parse_delay (argv[2], 1);
+ if (threshold > 0)
+ {
+ str_threshold = util_get_microseconds_string (threshold);
+ debug_long_callbacks = threshold;
+ gui_chat_printf (NULL,
+ _("Debug enabled for callbacks (threshold: %s)"),
+ (str_threshold) ? str_threshold : "?");
+ if (str_threshold)
+ free (str_threshold);
+ }
+ else
+ {
+ debug_long_callbacks = 0;
+ gui_chat_printf (NULL, _("Debug disabled for callbacks"));
+ }
+ return WEECHAT_RC_OK;
+ }
+
if (string_strcmp (argv[1], "certs") == 0)
{
gui_chat_printf (NULL,
@@ -8024,6 +8047,7 @@ command_init ()
" || dump|hooks [<plugin>]"
" || buffer|certs|color|dirs|infolists|libs|memory|tags|"
"term|windows"
+ " || callbacks <duration>[<unit>]"
" || mouse|cursor [verbose]"
" || hdata [free]"
" || time <command>"
@@ -8036,7 +8060,16 @@ command_init ()
"written when WeeChat crashes)\n"
" hooks: display infos about hooks (with a plugin: display "
"detailed info about hooks created by the plugin)\n"
- " buffer: dump buffer content with hexadecimal values in log file\n"
+ " buffer: dump buffer content with hexadecimal values in WeeChat "
+ "log file\n"
+ "callbacks: write hook and bar item callbacks that took more than "
+ "\"duration\" in the WeeChat log file (0 = disable), where optional "
+ "unit is one of:\n"
+ " us: microseconds (default)\n"
+ " ms: milliseconds\n"
+ " s: seconds\n"
+ " m: minutes\n"
+ " h: hours\n"
" certs: display number of loaded trusted certificate authorities\n"
" color: display infos about current color pairs\n"
" cursor: toggle debug for cursor mode\n"
@@ -8066,6 +8099,7 @@ command_init ()
" || set %(plugins_names)|" PLUGIN_CORE
" || dump %(plugins_names)|" PLUGIN_CORE
" || buffer"
+ " || callbacks"
" || certs"
" || color"
" || cursor verbose"
diff --git a/src/core/wee-debug.c b/src/core/wee-debug.c
index 00655a448..b0bc8a4f1 100644
--- a/src/core/wee-debug.c
+++ b/src/core/wee-debug.c
@@ -67,6 +67,9 @@
int debug_dump_active = 0;
+long long debug_long_callbacks = 0; /* callbacks taking more than */
+ /* N microseconds will be traced */
+
/*
* Writes dump of data to WeeChat log file.
diff --git a/src/core/wee-debug.h b/src/core/wee-debug.h
index a381c2942..fe44c85f9 100644
--- a/src/core/wee-debug.h
+++ b/src/core/wee-debug.h
@@ -24,6 +24,8 @@
struct t_gui_window_tree;
+extern long long debug_long_callbacks;
+
extern void debug_sigsegv_cb ();
extern void debug_windows_tree ();
extern void debug_memory ();
diff --git a/src/core/wee-hook.c b/src/core/wee-hook.c
index 4af120833..b6bf36d96 100644
--- a/src/core/wee-hook.c
+++ b/src/core/wee-hook.c
@@ -31,12 +31,14 @@
#include <errno.h>
#include "weechat.h"
+#include "wee-debug.h"
#include "wee-hook.h"
#include "wee-hashtable.h"
#include "wee-infolist.h"
#include "wee-log.h"
#include "wee-signal.h"
#include "wee-string.h"
+#include "wee-util.h"
#include "../gui/gui-chat.h"
#include "../plugins/plugin.h"
@@ -427,6 +429,67 @@ hook_exec_end ()
}
/*
+ * Starts execution of a hook callback.
+ */
+
+void
+hook_callback_start (struct t_hook *hook, struct t_hook_exec_cb *hook_exec_cb)
+{
+ if (hook->type == HOOK_TYPE_COMMAND)
+ hook->running++;
+ else
+ hook->running = 1;
+
+ if (debug_long_callbacks > 0)
+ {
+ gettimeofday (&hook_exec_cb->start_time, NULL);
+ }
+ else
+ {
+ hook_exec_cb->start_time.tv_sec = 0;
+ hook_exec_cb->start_time.tv_usec = 0;
+ }
+}
+
+/*
+ * Ends execution of a hook callback.
+ */
+
+void
+hook_callback_end (struct t_hook *hook, struct t_hook_exec_cb *hook_exec_cb)
+{
+ struct timeval end_time;
+ long long time_diff;
+ char *str_diff;
+
+ if (hook->type == HOOK_TYPE_COMMAND)
+ hook->running--;
+ else
+ hook->running = 0;
+
+ if ((debug_long_callbacks > 0)
+ && (hook_exec_cb->start_time.tv_sec > 0))
+ {
+ gettimeofday (&end_time, NULL);
+ time_diff = util_timeval_diff (&hook_exec_cb->start_time, &end_time);
+ if (time_diff >= debug_long_callbacks)
+ {
+ str_diff = util_get_microseconds_string (time_diff);
+ log_printf (
+ _("debug: long callback: hook %s (%s), plugin: %s, "
+ "subplugin: %s, time elapsed: %s"),
+ hook_type_string[hook->type],
+ hook_get_description (hook),
+ plugin_get_name (hook->plugin),
+ (hook->subplugin) ? hook->subplugin : "-",
+ str_diff);
+ if (str_diff)
+ free (str_diff);
+ }
+ }
+}
+
+/*
* Returns description of hook.
*
* Note: result must be freed after use.
diff --git a/src/core/wee-hook.h b/src/core/wee-hook.h
index 7d6cf8b05..04b17c921 100644
--- a/src/core/wee-hook.h
+++ b/src/core/wee-hook.h
@@ -110,6 +110,12 @@ struct t_hook
struct t_hook *next_hook; /* link to next hook */
};
+struct t_hook_exec_cb
+{
+ struct timeval start_time; /* callback exec star time (to trace */
+ /* long running callbacks) */
+};
+
/* hook variables */
extern char *hook_type_string[];
@@ -118,6 +124,7 @@ extern struct t_hook *last_weechat_hook[];
extern int hooks_count[];
extern int hooks_count_total;
extern int hook_socketpair_ok;
+extern long long hook_debug_long_callbacks;
/* hook functions */
@@ -130,6 +137,10 @@ extern void hook_init_data (struct t_hook *hook,
extern int hook_valid (struct t_hook *hook);
extern void hook_exec_start ();
extern void hook_exec_end ();
+extern void hook_callback_start (struct t_hook *hook,
+ struct t_hook_exec_cb *hook_exec_cb);
+extern void hook_callback_end (struct t_hook *hook,
+ struct t_hook_exec_cb *hook_exec_cb);
extern char *hook_get_description (struct t_hook *hook);
extern void hook_set (struct t_hook *hook, const char *property,
const char *value);
diff --git a/src/gui/gui-bar-item.c b/src/gui/gui-bar-item.c
index 3dc63d64b..00b1598be 100644
--- a/src/gui/gui-bar-item.c
+++ b/src/gui/gui-bar-item.c
@@ -30,6 +30,7 @@
#include "../core/weechat.h"
#include "../core/wee-arraylist.h"
#include "../core/wee-config.h"
+#include "../core/wee-debug.h"
#include "../core/wee-hashtable.h"
#include "../core/wee-hdata.h"
#include "../core/wee-hook.h"
@@ -37,6 +38,7 @@
#include "../core/wee-log.h"
#include "../core/wee-string.h"
#include "../core/wee-utf8.h"
+#include "../core/wee-util.h"
#include "../plugins/plugin.h"
#include "gui-bar-item.h"
#include "gui-bar.h"
@@ -359,9 +361,11 @@ gui_bar_item_get_value (struct t_gui_bar *bar, struct t_gui_window *window,
int item, int subitem)
{
char *item_value, delimiter_color[32], bar_color[32];
- char **result, str_attr[8];
+ char **result, str_attr[8], *str_diff;
struct t_gui_buffer *buffer;
struct t_gui_bar_item *ptr_item;
+ struct timeval start_time, end_time;
+ long long time_diff;
if (!bar || !bar->items_array[item][subitem])
return NULL;
@@ -383,6 +387,15 @@ gui_bar_item_get_value (struct t_gui_bar *bar, struct t_gui_window *window,
bar->items_name[item][subitem]);
if (ptr_item && ptr_item->build_callback)
{
+ if (debug_long_callbacks > 0)
+ {
+ gettimeofday (&start_time, NULL);
+ }
+ else
+ {
+ start_time.tv_sec = 0;
+ start_time.tv_usec = 0;
+ }
item_value = (ptr_item->build_callback) (
ptr_item->build_callback_pointer,
ptr_item->build_callback_data,
@@ -390,6 +403,24 @@ gui_bar_item_get_value (struct t_gui_bar *bar, struct t_gui_window *window,
window,
buffer,
NULL);
+ if ((debug_long_callbacks > 0) && (start_time.tv_sec > 0))
+ {
+ gettimeofday (&end_time, NULL);
+ time_diff = util_timeval_diff (&start_time, &end_time);
+ if (time_diff >= debug_long_callbacks)
+ {
+ str_diff = util_get_microseconds_string (time_diff);
+ log_printf (
+ _("debug: long callback: bar: %s, item: %s, plugin: %s, "
+ "time elapsed: %s"),
+ bar->name,
+ ptr_item->name,
+ plugin_get_name (ptr_item->plugin),
+ str_diff);
+ if (str_diff)
+ free (str_diff);
+ }
+ }
}
if (item_value && !item_value[0])
{