Lines Matching defs:hist

70 dosetup(struct timehist* hist)
75 for(i=0; i<hist->num; i++) {
76 hist->buckets[i].lower = last;
78 hist->buckets[i].upper = last;
79 hist->buckets[i].count = 0;
85 struct timehist* hist = (struct timehist*)calloc(1,
87 if(!hist)
89 hist->num = NUM_BUCKETS_HIST;
90 hist->buckets = (struct th_buck*)calloc(hist->num,
92 if(!hist->buckets) {
93 free(hist);
97 dosetup(hist);
98 return hist;
101 void timehist_delete(struct timehist* hist)
103 if(!hist)
105 free(hist->buckets);
106 free(hist);
109 void timehist_clear(struct timehist* hist)
112 for(i=0; i<hist->num; i++)
113 hist->buckets[i].count = 0;
133 void timehist_insert(struct timehist* hist, struct timeval* tv)
136 for(i=0; i<hist->num; i++) {
137 if(timeval_smaller(tv, &hist->buckets[i].upper)) {
138 hist->buckets[i].count++;
143 hist->buckets[hist->num-1].count++;
146 void timehist_print(struct timehist* hist)
150 for(i=0; i<hist->num; i++) {
151 if(hist->buckets[i].count != 0) {
153 (int)hist->buckets[i].lower.tv_sec,
154 (int)hist->buckets[i].lower.tv_usec,
155 (int)hist->buckets[i].upper.tv_sec,
156 (int)hist->buckets[i].upper.tv_usec,
157 (unsigned)hist->buckets[i].count);
163 void timehist_log(struct timehist* hist, const char* name)
168 timehist_quartile(hist, 0.25),
169 timehist_quartile(hist, 0.50),
170 timehist_quartile(hist, 0.75));
173 for(i=0; i<hist->num; i++) {
174 if(hist->buckets[i].count != 0) {
176 (int)hist->buckets[i].lower.tv_sec,
177 (int)hist->buckets[i].lower.tv_usec,
178 (int)hist->buckets[i].upper.tv_sec,
179 (int)hist->buckets[i].upper.tv_usec,
180 (unsigned)hist->buckets[i].count);
188 timehist_count(struct timehist* hist)
191 for(i=0; i<hist->num; i++)
192 res += hist->buckets[i].count;
197 timehist_quartile(struct timehist* hist, double q)
202 if(!hist || hist->num == 0)
205 lookfor = (double)timehist_count(hist);
211 while(i+1 < hist->num &&
212 passed+(double)hist->buckets[i].count < lookfor) {
213 passed += (double)hist->buckets[i++].count;
217 low = (double)hist->buckets[i].lower.tv_sec +
218 (double)hist->buckets[i].lower.tv_usec/1000000.;
219 up = (double)hist->buckets[i].upper.tv_sec +
220 (double)hist->buckets[i].upper.tv_usec/1000000.;
222 res = (lookfor - passed)*(up-low)/((double)hist->buckets[i].count);
227 timehist_export(struct timehist* hist, size_t* array, size_t sz)
230 if(!hist) return;
231 if(sz > hist->num)
232 sz = hist->num;
234 array[i] = hist->buckets[i].count;
238 timehist_import(struct timehist* hist, size_t* array, size_t sz)
241 if(!hist) return;
242 if(sz > hist->num)
243 sz = hist->num;
245 hist->buckets[i].count = array[i];