From 924b9229717b749e303f3fb161616bebf53b5cdc Mon Sep 17 00:00:00 2001 From: ajs Date: Sat, 16 Apr 2005 17:11:24 +0000 Subject: 2005-04-16 Andrew J. Schorr * configure.ac: Added AC_ARG_ENABLE(time-check). By default, warning messages will now be printed for threads or commands that take longer than 5 seconds, but this configure argument can be used to disable the checks or change the threshold. * thread.h (thread_consumed_time): Declare new function to calculate elapsed microseconds. * thread.c (thread_consumed_time): Must be global not static so we can call it from lib/vty.c:vty_command. (thread_should_yield): Surround with `#if 0' to make clear that this function is not currently being used anywhere. (thread_call): If CONSUMED_TIME_CHECK is defined, print a CPU HOG warning message if the thread takes more than CONSUMED_TIME_CHECK microseconds. * vty.c (vty_command): If CONSUMED_TIME_CHECK is defined, print a CPU HOG warning message if the command takes more than CONSUMED_TIME_CHECK microseconds. --- lib/vty.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'lib/vty.c') diff --git a/lib/vty.c b/lib/vty.c index 600c9fd8..ea74172c 100644 --- a/lib/vty.c +++ b/lib/vty.c @@ -395,8 +395,25 @@ vty_command (struct vty *vty, char *buf) if (vline == NULL) return CMD_SUCCESS; +#ifdef CONSUMED_TIME_CHECK + { + RUSAGE_T before; + RUSAGE_T after; + unsigned long cmdtime; + + GETRUSAGE(&before); +#endif /* CONSUMED_TIME_CHECK */ + ret = cmd_execute_command (vline, vty, NULL, 0); +#ifdef CONSUMED_TIME_CHECK + GETRUSAGE(&after); + if ((cmdtime = thread_consumed_time(&after, &before)) > CONSUMED_TIME_CHECK) + /* Warn about CPU hog that must be fixed. */ + zlog_warn("CPU HOG: command took %lums: %s", cmdtime/1000, buf); + } +#endif /* CONSUMED_TIME_CHECK */ + if (ret != CMD_SUCCESS) switch (ret) { -- cgit v1.2.1