mirror of
https://github.com/weechat/weechat.git
synced 2026-07-01 07:16:37 +02:00
core: add option "time" in command /debug
This commit is contained in:
+19
-4
@@ -1688,6 +1688,7 @@ COMMAND_CALLBACK(debug)
|
||||
{
|
||||
struct t_config_option *ptr_option;
|
||||
struct t_weechat_plugin *ptr_plugin;
|
||||
struct timeval time_start, time_end;
|
||||
int debug;
|
||||
|
||||
/* make C compiler happy */
|
||||
@@ -1861,6 +1862,16 @@ COMMAND_CALLBACK(debug)
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
if (string_strcasecmp (argv[1], "time") == 0)
|
||||
{
|
||||
COMMAND_MIN_ARGS(3, "time");
|
||||
gettimeofday (&time_start, NULL);
|
||||
(void) input_data (buffer, argv_eol[2]);
|
||||
gettimeofday (&time_end, NULL);
|
||||
debug_display_time_elapsed (&time_start, &time_end, argv_eol[2], 1);
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
COMMAND_ERROR;
|
||||
}
|
||||
|
||||
@@ -7127,13 +7138,14 @@ command_init ()
|
||||
&command_cursor, NULL, NULL);
|
||||
hook_command (
|
||||
NULL, "debug",
|
||||
N_("control debug for core/plugins"),
|
||||
N_("debug functions"),
|
||||
N_("list"
|
||||
" || set <plugin> <level>"
|
||||
" || dump [<plugin>]"
|
||||
" || buffer|color|infolists|memory|tags|term|windows"
|
||||
" || mouse|cursor [verbose]"
|
||||
" || hdata [free]"),
|
||||
" || hdata [free]"
|
||||
" || time <command>"),
|
||||
N_(" list: list plugins with debug levels\n"
|
||||
" set: set debug level for plugin\n"
|
||||
" plugin: name of plugin (\"core\" for WeeChat core)\n"
|
||||
@@ -7153,7 +7165,9 @@ command_init ()
|
||||
" mouse: toggle debug for mouse\n"
|
||||
" tags: display tags for lines\n"
|
||||
" term: display infos about terminal\n"
|
||||
" windows: display windows tree"),
|
||||
" windows: display windows tree\n"
|
||||
" time: measure time to execute a command or to send text to "
|
||||
"the current buffer"),
|
||||
"list"
|
||||
" || set %(plugins_names)|core"
|
||||
" || dump %(plugins_names)|core"
|
||||
@@ -7169,7 +7183,8 @@ command_init ()
|
||||
" || mouse verbose"
|
||||
" || tags"
|
||||
" || term"
|
||||
" || windows",
|
||||
" || windows"
|
||||
" || time %(commands)",
|
||||
&command_debug, NULL, NULL);
|
||||
hook_command (
|
||||
NULL, "eval",
|
||||
|
||||
+6
-32
@@ -65,9 +65,6 @@
|
||||
|
||||
int debug_dump_active = 0;
|
||||
|
||||
char *debug_time_name = NULL;
|
||||
struct timeval debug_timeval_start = { 0, 0 };
|
||||
|
||||
|
||||
/*
|
||||
* Writes dump of data to WeeChat log file.
|
||||
@@ -584,39 +581,21 @@ debug_directories ()
|
||||
}
|
||||
|
||||
/*
|
||||
* Starts time measure.
|
||||
*/
|
||||
|
||||
void
|
||||
debug_time_start (const char *name)
|
||||
{
|
||||
if (debug_time_name)
|
||||
{
|
||||
free (debug_time_name);
|
||||
debug_time_name = NULL;
|
||||
}
|
||||
if (name)
|
||||
debug_time_name = strdup (name);
|
||||
|
||||
gettimeofday (&debug_timeval_start, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Ends time measure and display elapsed time.
|
||||
* Display time elapsed between two times.
|
||||
*
|
||||
* If display is 1, the message is displayed in core buffer, otherwise it's
|
||||
* written in log file.
|
||||
*/
|
||||
|
||||
void
|
||||
debug_time_end (int display)
|
||||
debug_display_time_elapsed (struct timeval *time1, struct timeval *time2,
|
||||
const char *message, int display)
|
||||
{
|
||||
struct timeval debug_timeval_end;
|
||||
long long diff, diff_hour, diff_min, diff_sec, diff_usec;
|
||||
|
||||
gettimeofday (&debug_timeval_end, NULL);
|
||||
diff = util_timeval_diff (&debug_timeval_start,
|
||||
&debug_timeval_end);
|
||||
diff = util_timeval_diff (time1, time2);
|
||||
|
||||
diff_usec = diff % 1000000;
|
||||
diff_sec = (diff / 1000000) % 60;
|
||||
@@ -627,13 +606,13 @@ debug_time_end (int display)
|
||||
{
|
||||
gui_chat_printf (NULL,
|
||||
"debug: time[%s] -> %lld:%02lld:%02lld.%06d",
|
||||
(debug_time_name) ? debug_time_name : "?",
|
||||
(message) ? message : "?",
|
||||
diff_hour, diff_min, diff_sec, diff_usec);
|
||||
}
|
||||
else
|
||||
{
|
||||
log_printf ("debug: time[%s] -> %lld:%02lld:%02lld.%06d",
|
||||
(debug_time_name) ? debug_time_name : "?",
|
||||
(message) ? message : "?",
|
||||
diff_hour, diff_min, diff_sec, diff_usec);
|
||||
}
|
||||
}
|
||||
@@ -661,9 +640,4 @@ debug_init ()
|
||||
void
|
||||
debug_end ()
|
||||
{
|
||||
if (debug_time_name)
|
||||
{
|
||||
free (debug_time_name);
|
||||
debug_time_name = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,8 +29,10 @@ extern void debug_hdata ();
|
||||
extern void debug_hooks ();
|
||||
extern void debug_infolists ();
|
||||
extern void debug_directories ();
|
||||
extern void debug_time_start (const char *name);
|
||||
extern void debug_time_end (int display);
|
||||
extern void debug_display_time_elapsed (struct timeval *time1,
|
||||
struct timeval *time2,
|
||||
const char *message,
|
||||
int display);
|
||||
extern void debug_init ();
|
||||
extern void debug_end ();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user