diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2016-11-28 21:52:14 +0100 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2016-11-28 21:52:14 +0100 |
commit | 93ef6b0a3e828094cfbb58aeb6cb1be6cee690af (patch) | |
tree | 464a9eeec0b409b26c0b70b86ad0789d4dd7e39c /src/core | |
parent | 9c76d80d4deb8ed6a6da82f957c5ea67c205b73e (diff) | |
download | weechat-93ef6b0a3e828094cfbb58aeb6cb1be6cee690af.zip |
core: add option "time" in command /debug
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/wee-command.c | 23 | ||||
-rw-r--r-- | src/core/wee-debug.c | 38 | ||||
-rw-r--r-- | src/core/wee-debug.h | 6 |
3 files changed, 29 insertions, 38 deletions
diff --git a/src/core/wee-command.c b/src/core/wee-command.c index aa0afc9e7..3d90b2441 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -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", diff --git a/src/core/wee-debug.c b/src/core/wee-debug.c index d6ab2118b..d66d40574 100644 --- a/src/core/wee-debug.c +++ b/src/core/wee-debug.c @@ -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; - } } diff --git a/src/core/wee-debug.h b/src/core/wee-debug.h index ab018aece..8cc4e5ae6 100644 --- a/src/core/wee-debug.h +++ b/src/core/wee-debug.h @@ -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 (); |