10 int histogram_init(struct histogram *h,
15 h->allocated = max_value/resolution + 1;
16 h->resolution = resolution;
17 mem = h->allocated*sizeof(*h->data);
18 h->data = malloc(mem);
20 memset(h->data, 0, mem);
26 void histogram_add(struct histogram *h, unsigned value)
28 unsigned index = value / h->resolution;
29 if (index >= h->allocated)
30 index = h->allocated - 1;
34 void histogram_fprint(struct histogram *h, FILE *f)
36 unsigned long long sum = 0, cum;
38 for (i = 0; i < h->allocated; i++)
41 for (i = 0; i < h->allocated; i++) {
42 if (h->data[i] != 0) {
43 if (!getenv("CANPING_MS"))
44 fprintf(f, "%d %lld\n", i*h->resolution, cum);
46 fprintf(f, "%g %lld\n", 1e-3*(i*h->resolution), cum);