1#if TIME_WITH_SYS_TIME 2# include <sys/time.h> 3# include <time.h> 4#else 5# if HAVE_SYS_TIME_H 6# include <sys/time.h> 7# else 8# include <time.h> 9# endif 10#endif 11 12/* hist.h 13 14 Given a time difference in microseconds, increment one of 61 15 different buckets: 16 17 0 - 9 in increments of 1 usec 18 0 - 9 in increments of 10 usecs 19 0 - 9 in increments of 100 usecs 20 0 - 9 in increments of 1 msec 21 0 - 9 in increments of 10 msecs 22 0 - 9 in increments of 100 msecs 23 0 - 9 in increments of 1 sec 24 0 - 9 in increments of 10 sec 25 > 100 secs 26 27 This will allow any time to be recorded to within an accuracy of 28 10%, and provides a compact representation for capturing the 29 distribution of a large number of time differences (e.g. 30 request-response latencies). 31 32 Colin Low 10/6/93 33 Rick Jones 2004-06-15 - extend to 1 and 10 usec 34*/ 35#ifndef _HIST_INCLUDED 36#define _HIST_INCLUDED 37 38#ifdef IRIX 39#include <sys/time.h> 40#endif /* IRIX */ 41 42#if defined(HAVE_GET_HRT) 43#include "hrt.h" 44#endif 45 46struct histogram_struct { 47 int unit_usec[10]; 48 int ten_usec[10]; 49 int hundred_usec[10]; 50 int unit_msec[10]; 51 int ten_msec[10]; 52 int hundred_msec[10]; 53 int unit_sec[10]; 54 int ten_sec[10]; 55 int ridiculous; 56 int total; 57}; 58 59typedef struct histogram_struct *HIST; 60 61/* 62 HIST_new - return a new, cleared histogram data type 63*/ 64 65HIST HIST_new(void); 66 67/* 68 HIST_clear - reset a histogram by clearing all totals to zero 69*/ 70 71void HIST_clear(HIST h); 72 73/* 74 HIST_add - add a time difference to a histogram. Time should be in 75 microseconds. 76*/ 77 78void HIST_add(register HIST h, int time_delta); 79 80/* 81 HIST_report - create an ASCII report on the contents of a histogram. 82 Currently printsto standard out 83*/ 84 85void HIST_report(HIST h); 86 87/* 88 HIST_timestamp - take a timestamp suitable for use in a histogram. 89*/ 90 91#ifdef HAVE_GETHRTIME 92void HIST_timestamp(hrtime_t *timestamp); 93#elif defined(HAVE_GET_HRT) 94void HIST_timestamp(hrt_t *timestamp); 95#elif defined(WIN32) 96void HIST_timestamp(LARGE_INTEGER *timestamp); 97#else 98void HIST_timestamp(struct timeval *timestamp); 99#endif 100 101/* 102 delta_micro - calculate the difference in microseconds between two 103 timestamps 104*/ 105#ifdef HAVE_GETHRTIME 106int delta_micro(hrtime_t *begin, hrtime_t *end); 107#elif defined(HAVE_GET_HRT) 108int delta_micro(hrt_t *begin, hrt_t *end); 109#elif defined(WIN32) 110int delta_micro(LARGE_INTEGER *begin, LARGE_INTEGER *end); 111#else 112int delta_micro(struct timeval *begin, struct timeval *end); 113#endif 114 115#endif 116 117