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 #ifdef WIN32
12 #  include "missing\stdint.h"
13 #endif
14 
15 /* hist.h
16 
17    Given a time difference in microseconds, increment one of 61
18    different buckets:
19 
20    0 - 9 in increments of 1 usec
21    0 - 9 in increments of 10 usecs
22    0 - 9 in increments of 100 usecs
23    0 - 9 in increments of 1 msec
24    0 - 9 in increments of 10 msecs
25    0 - 9 in increments of 100 msecs
26    0 - 9 in increments of 1 sec
27    0 - 9 in increments of 10 sec
28    > 100 secs
29 
30    This will allow any time to be recorded to within an accuracy of
31    10%, and provides a compact representation for capturing the
32    distribution of a large number of time differences (e.g.
33    request-response latencies).
34 
35    Colin Low  10/6/93
36    Rick Jones 2004-06-15 - extend to 1 and 10 usec
37 */
38 #ifndef _HIST_INCLUDED
39 #define _HIST_INCLUDED
40 
41 #if defined(HAVE_GET_HRT)
42 #include "hrt.h"
43 #endif
44 
45 #ifndef HIST_NUM_OF_BUCKET
46 #define HIST_NUM_OF_BUCKET 100
47 #endif
48 
49 struct histogram_struct {
50   int unit_usec[HIST_NUM_OF_BUCKET];
51   int ten_usec[HIST_NUM_OF_BUCKET];
52   int hundred_usec[HIST_NUM_OF_BUCKET];
53   int unit_msec[HIST_NUM_OF_BUCKET];
54   int ten_msec[HIST_NUM_OF_BUCKET];
55   int hundred_msec[HIST_NUM_OF_BUCKET];
56   int unit_sec[HIST_NUM_OF_BUCKET];
57   int ten_sec[HIST_NUM_OF_BUCKET];
58   int ridiculous;
59   int total;
60   int64_t sum;
61   double sumsquare;
62   int hmin;
63   int hmax;
64   int limit;
65   int count;
66   int producer;
67   int consumer;
68 #ifdef HAVE_GETHRTIME
69   hrtime_t *time_ones;
70   hrtime_t time_two;
71 #elif HAVE_GET_HRT
72   hrt_t *time_ones;
73   hrt_t time_two;
74 #elif defined(WIN32)
75   LARGE_INTEGER *time_ones;
76   LARGE_INTEGER time_two;
77 #else
78   struct timeval *time_ones;
79   struct timeval time_two;
80 #endif /* HAVE_GETHRTIME */
81 
82 };
83 
84 typedef struct histogram_struct *HIST;
85 
86 /*
87    HIST_new - return a new, cleared histogram data type
88 */
89 
90 HIST HIST_new(void);
91 
92 /*
93    HIST_new_n - return a new, cleard histogram data type able to track
94    at least max_outstanding timestamps
95 */
96 
97 HIST HIST_new_n(int max_outstanding);
98 
99 /*
100    HIST_clear - reset a histogram by clearing all totals to zero
101 */
102 
103 
104 void HIST_clear(HIST h);
105 
106 /*
107    HIST_purge - forget about any remaining outstanding timestamps
108    being tracked
109 */
110 
111 void HIST_purge(HIST h);
112 
113 /*
114    HIST_add - add a time difference to a histogram. Time should be in
115    microseconds.
116 */
117 
118 void HIST_add(register HIST h, int time_delta);
119 
120 /*
121   HIST_report - create an ASCII report on the contents of a histogram.
122   Currently printsto standard out
123 */
124 
125 void HIST_report(HIST h);
126 
127 /*
128   HIST_timestamp - take a timestamp suitable for use in a histogram.
129 */
130 
131 #ifdef HAVE_GETHRTIME
132 void HIST_timestamp(hrtime_t *timestamp);
133 #elif defined(HAVE_GET_HRT)
134 void HIST_timestamp(hrt_t *timestamp);
135 #elif defined(WIN32)
136 void HIST_timestamp(LARGE_INTEGER *timestamp);
137 #else
138 void HIST_timestamp(struct timeval *timestamp);
139 #endif
140 
141 /*
142   HIST_timestamp_start - start a new timestamp
143 */
144 
145 void HIST_timestamp_start(HIST h);
146 
147 /*
148   HIST_timestamp_stop_add - complete the oldest outstanding timestamp
149   and add it to the histogram
150 */
151 
152 void HIST_timestamp_stop_add(HIST h);
153 
154 /*
155   delta_micro - calculate the difference in microseconds between two
156   timestamps
157 */
158 #ifdef HAVE_GETHRTIME
159 int delta_micro(hrtime_t *begin, hrtime_t *end);
160 #elif defined(HAVE_GET_HRT)
161 int delta_micro(hrt_t *begin, hrt_t *end);
162 #elif defined(WIN32)
163 int delta_micro(LARGE_INTEGER *begin, LARGE_INTEGER *end);
164 #else
165 int delta_micro(struct timeval *begin, struct timeval *end);
166 #endif
167 
168 #endif
169 
170