}
int distribution_marshal_text(strbuf_t *buf, distribution_t *dist) {
- buckets_array_t buckets = get_buckets(dist);
- int status_buckets_heading = strbuf_printf(buf, "\"buckets:\" {\n");
- if (status_buckets_heading != 0) {
- return status_buckets_heading;
+ if (dist == NULL) {
+ return EINVAL;
}
+
+ buckets_array_t buckets = get_buckets(dist);
+
for (size_t i = 0; i < buckets.num_buckets; i++) {
if (i < buckets.num_buckets - 1) {
- int status_buckets =
- strbuf_printf(buf, "\"%.2f\":\"%lu\",\n", buckets.buckets[i].maximum,
- buckets.buckets[i].bucket_counter);
+ int status_buckets = strbuf_printf(buf, "bucket{l=\"%.2f\"} %lu\n",
+ buckets.buckets[i].maximum,
+ buckets.buckets[i].bucket_counter);
if (status_buckets != 0) {
return status_buckets;
}
} else {
- int status_buckets =
- strbuf_printf(buf, "\"%.2f\":\"%lu\"\n", buckets.buckets[i].maximum,
- buckets.buckets[i].bucket_counter);
+ int status_buckets = strbuf_printf(buf, "bucket{l=\"+%.2f\"} %lu\n",
+ buckets.buckets[i].maximum,
+ buckets.buckets[i].bucket_counter);
if (status_buckets != 0) {
return status_buckets;
}
}
}
- int status_count = strbuf_printf(buf, "},\n\"count\":\"%lu\",\n",
- distribution_total_counter(dist));
+
+ int status_count =
+ strbuf_printf(buf, "sum %.2f\n", distribution_total_sum(dist));
if (status_count != 0) {
return status_count;
}
int status_sum =
- strbuf_printf(buf, "\"sum\":\"%.2f\n", distribution_total_sum(dist));
+ strbuf_printf(buf, "count %lu\n", distribution_total_counter(dist));
if (status_sum != 0) {
return status_sum;
}
} cases[] = {
{
.value.distribution = distribution_new_linear(2, 20),
- .want = "\"buckets:\" {\n"
- "\"20.00\":\"0\",\n"
- "\"inf\":\"0\"\n"
- "},\n\"count\":\"0\",\n"
- "\"sum\":\"0.00\n",
+ .want = "bucket{l=\"20.00\"} 0\n"
+ "bucket{l=\"+inf\"} 0\n"
+ "sum 0.00\n"
+ "count 0\n"
},
{
.value.distribution = distribution_new_exponential(10, 2, 3),
- .want = "\"buckets:\" {\n"
- "\"3.00\":\"0\",\n"
- "\"6.00\":\"0\",\n"
- "\"12.00\":\"0\",\n"
- "\"24.00\":\"0\",\n"
- "\"48.00\":\"0\",\n"
- "\"96.00\":\"0\",\n"
- "\"192.00\":\"0\",\n"
- "\"384.00\":\"0\",\n"
- "\"768.00\":\"0\",\n"
- "\"inf\":\"0\"\n"
- "},\n\"count\":\"0\",\n"
- "\"sum\":\"0.00\n",
+ .want = "bucket{l=\"3.00\"} 0\n"
+ "bucket{l=\"6.00\"} 0\n"
+ "bucket{l=\"12.00\"} 0\n"
+ "bucket{l=\"24.00\"} 0\n"
+ "bucket{l=\"48.00\"} 0\n"
+ "bucket{l=\"96.00\"} 0\n"
+ "bucket{l=\"192.00\"} 0\n"
+ "bucket{l=\"384.00\"} 0\n"
+ "bucket{l=\"768.00\"} 0\n"
+ "bucket{l=\"+inf\"} 0\n"
+ "sum 0.00\n"
+ "count 0\n"
},
{
.value.distribution =
distribution_new_custom(4, (double[]){3, 10, 50, 100}),
- .want = "\"buckets:\" {\n"
- "\"3.00\":\"0\",\n"
- "\"10.00\":\"0\",\n"
- "\"50.00\":\"0\",\n"
- "\"100.00\":\"0\",\n"
- "\"inf\":\"0\"\n"
- "},\n\"count\":\"0\",\n"
- "\"sum\":\"0.00\n",
+ .want = "bucket{l=\"3.00\"} 0\n"
+ "bucket{l=\"10.00\"} 0\n"
+ "bucket{l=\"50.00\"} 0\n"
+ "bucket{l=\"100.00\"} 0\n"
+ "bucket{l=\"+inf\"} 0\n"
+ "sum 0.00\n"
+ "count 0\n"
},
};