diff options
author | ajs <ajs> | 2005-04-28 01:31:13 +0000 |
---|---|---|
committer | ajs <ajs> | 2005-04-28 01:31:13 +0000 |
commit | 8b70d0b04f6bba2f30827d71084dd74fd00808b3 (patch) | |
tree | 245969be7b29246bcb5ca39fc6661f0aeea7dd75 /lib/thread.h | |
parent | 3df537822f594ffefe4d5e121c0b2430c9c12806 (diff) |
2005-04-27 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
Add wall-clock timing statistics to 'show thread cpu' output.
* thread.h: Define struct rusage_t to contain wall-clock time
and cpu time. Change GETRUSAGE macro to collect both pieces
of data. Make appropriate changes to struct cpu_thread_history
to track CPU time and real time. Change proto for
thread_consumed_time to return real and cpu time elapsed.
And declare a new global variable 'struct timeval recent_time'.
* thread.c (struct timeval recent_time): New global timestamp variable.
(timeval_adjust): If timeout is negative, set to 0 (not 10
microseconds). And remove upper bound of 1,000,000 seconds, since
this does not seem to make any sense (and it breaks
funcname_thread_add_timer_timeval).
(timeval_cmp): Should return long, not int.
(vty_out_cpu_thread_history): Show CPU time and real time.
(cpu_record_hash_print): Calculate totals for CPU and real time.
(cpu_record_print): Change 'show thread cpu' title to show CPU and
real time.
(thread_timer_remain_second): Put current time in global recent_time.
(funcname_thread_add_timer_timeval): Fix assert. Replace 2-case
switch assignment with a ternary expression. Use global recent_time
variable. Fix use of timeval_adjust (previously, the value was not
actually being adjusted).
(thread_cancel): Add missing "break" statement in case
THREAD_BACKGROUND.
(thread_timer_wait): Use global recent_time value instead of calling
gettimeofday. And there's no need to check for negative timeouts,
since timeval_subtract already sets these to zero.
(thread_timer_process): Timers are sorted, so bail out once we
encounter a timer that has not yet popped. And remove some
extraneous asserts.
(thread_fetch): Do not process foreground timers before calling
select. Instead, add them to the ready list just after the select.
Also, no need to maintain a count of the number of ready threads,
since we don't care how many there are, just whether there's
one at the head of the ready list (which is easily checked).
Stick current time in global variable recent_time to reduce
the number of calls to gettimeofday. Tighten logic for
calculating the select timeout.
(thread_consumed_time): Now returns real time and puts the elapsed
cpu time in an additional argument.
(thread_should_yield): Use real (wall-clock) time to decide whether
to yield.
(thread_call): Maintain CPU and real time statistics.
* vty.c (vty_command): For slow commands, show real and cpu time.
Diffstat (limited to 'lib/thread.h')
-rw-r--r-- | lib/thread.h | 38 |
1 files changed, 31 insertions, 7 deletions
diff --git a/lib/thread.h b/lib/thread.h index aef9df79..0d84cfc5 100644 --- a/lib/thread.h +++ b/lib/thread.h @@ -22,12 +22,22 @@ #ifndef _ZEBRA_THREAD_H #define _ZEBRA_THREAD_H +struct rusage_t +{ +#ifdef HAVE_RUSAGE + struct rusage cpu; +#endif + struct timeval real; +}; +#define RUSAGE_T struct rusage_t + #ifdef HAVE_RUSAGE -#define RUSAGE_T struct rusage -#define GETRUSAGE(X) getrusage (RUSAGE_SELF, X); +#define GETRUSAGE(X) \ + getrusage(RUSAGE_SELF, &((X)->cpu)); \ + gettimeofday(&recent_time, NULL); (X)->real = recent_time #else -#define RUSAGE_T struct timeval -#define GETRUSAGE(X) gettimeofday (X, NULL); +#define GETRUSAGE(X) \ + gettimeofday(&recent_time, NULL); (X)->real = recent_time #endif /* HAVE_RUSAGE */ /* Linked list of thread. */ @@ -73,11 +83,18 @@ struct thread char* funcname; }; -struct cpu_thread_history { +struct cpu_thread_history +{ int (*func)(struct thread *); const char *funcname; unsigned int total_calls; - unsigned long total, max; + struct time_stats + { + unsigned long total, max; + } real; +#ifdef HAVE_RUSAGE + struct time_stats cpu; +#endif unsigned char types; }; @@ -170,6 +187,13 @@ int thread_should_yield (struct thread *); extern struct cmd_element show_thread_cpu_cmd; -extern unsigned long thread_consumed_time(RUSAGE_T *after, RUSAGE_T *before); +/* Returns elapsed real (wall clock) time. */ +extern unsigned long thread_consumed_time(RUSAGE_T *after, RUSAGE_T *before, + unsigned long *cpu_time_elapsed); + +/* Global variable containing a recent result from gettimeofday. This can + be used instead of calling gettimeofday if a recent value is sufficient. + This is guaranteed to be refreshed before a thread is called. */ +extern struct timeval recent_time; #endif /* _ZEBRA_THREAD_H */ |