Commit b62397e6 authored by Joanne Hugé's avatar Joanne Hugé

Clean up histogram printing and fix missing bracket

parent 8f5998b7
......@@ -310,17 +310,12 @@ static void print_histograms() {
"\"props_names\": [\"user_space\", \"kernel_space\"],"
"\"units\": [\"us\", \"us\"],"
"\"props_type\": \"histogram\","
"\"metadata\": {"
"\"i\": \"%dus\", \"duration\": \"%dh%d\", \"etf_offset\": \"%dus\","
"},"
"\"props\": [",
"\"metadata\": {\"i\": \"%dus\", \"duration\": \"%dh%d\", \"etf_offset\": \"%dus\",},"
"\"props\": [[",
interval, duration_hour, duration_minutes, thread_params.etf_offset);
histogram = kernel_latency_hist;
max_hist_val = 0;
for (int j = 0; j < MAX_KERNEL_LATENCY; j++)
if (histogram[j])
max_hist_val = j > max_hist_val ? j : max_hist_val;
histogram = kernel_latency_hist;
max_hist_val = histogram_max(histogram, MAX_KERNEL_LATENCY - 1);
} else {
printf("{\"measure_sets\": [{"
......@@ -328,25 +323,17 @@ static void print_histograms() {
"\"props_names\": [\"rtt\"],"
"\"units\": [\"us\"],"
"\"props_type\": \"histogram\","
"\"metadata\": {"
"\"i\": \"%dus\", \"duration\": \"%dh%d\", \"etf_offset\": \"%dus\","
"},"
"\"props\": [",
"\"metadata\": {\"i\": \"%dus\", \"duration\": \"%dh%d\", \"etf_offset\": \"%dus\",},"
"\"props\": [[",
interval, duration_hour, duration_minutes, thread_params.etf_offset);
histogram = rtt_hist;
max_hist_val = 0;
for (int j = 0; j < MAX_RTT; j++)
if (histogram[j])
max_hist_val = j > max_hist_val ? j : max_hist_val;
histogram = rtt_hist;
max_hist_val = histogram_max(histogram, MAX_RTT - 1);
}
printf("[");
for (int j = 0; j < max_hist_val; j++)
printf("%" PRIi64 "%s", histogram[j], (j + 1 < max_hist_val ? ", " : ""));
printf("]");
printf("]}]}\n");
printf("]]}]}\n");
}
static void sighand(int sig_num) {
......
......@@ -35,6 +35,20 @@ uint64_t calcdiff_ns(struct timespec t1, struct timespec t2) {
int max(int a, int b) { return a > b ? a : b; }
int min(int a, int b) { return a < b ? a : b; }
int histogram_min(uint64_t * histogram, int max_value) {
int ret = max_value;
for (int i = max_value; i >= 0; i--)
ret = histogram[i] ? i : ret;
return ret;
}
int histogram_max(uint64_t * histogram, int max_value) {
int ret = 0;
for (int i = 0; i <= max_value; i++)
ret = histogram[i] ? i : ret;
return ret;
}
static void sighand_wrapper(int sig) {
// If we get un unexpected signal, report it, if not print the histogram
......
......@@ -29,6 +29,9 @@ void init_signals(void (*_sighand)(int), int enable_histograms);
int min(int a, int b);
int max(int a, int b);
int histogram_min(uint64_t * histogram, int max_value);
int histogram_max(uint64_t * histogram, int max_value);
extern void (*previous_handlers[NSIG])(int);
#endif
......@@ -271,58 +271,36 @@ static void print_histograms() {
if (enable_timestamps) {
printf("{\"measure_sets\": [{"
"\"measure_type\": \"packet_recv_timestamps\","
"\"props_names\": [\"user_space\", \"kernel_space\"],"
"\"units\": [\"us\", \"us\"],"
"\"props_names\": [\"kernel_space\"],"
"\"units\": [\"us\"],"
"\"props_type\": \"histogram\","
"\"metadata\": {"
"\"i\": \"%dus\", \"duration\": \"%dh%d\""
"},"
"\"props\": [",
"\"metadata\": \"i\": \"%dus\", \"duration\": \"%dh%d\"},"
"\"props\": [[",
interval, duration_hour, duration_minutes);
max_latency = 0;
for (int j = 0; j < MAX_KERNEL_LATENCY; j++)
if (kernel_latency_hist[j])
max_latency = j;
max_latency = histogram_max(kernel_latency_hist, MAX_KERNEL_LATENCY - 1);
printf("[");
for (int j = 0; j < max_latency; j++)
printf("%" PRIi64 "%s", kernel_latency_hist[j], (j + 1 < max_latency ? ", " : ""));
printf("]");
printf("]]");
}
max_jitter = 0;
for (int j = 0; j < MAX_JITTER; j++)
if (jitter_hist[j])
max_jitter = j;
max_jitter = histogram_max(jitter_hist, MAX_JITTER - 1);
min_jitter = histogram_min(jitter_hist, MAX_JITTER - 1);
min_jitter = MAX_JITTER - 1;
for (int j = MAX_JITTER - 1; j >= 0; j--)
if (jitter_hist[j])
min_jitter = j;
if (!enable_timestamps)
printf("{\"measure_sets\": [{");
else
printf("]}, {");
printf("%s", enable_timestamps ? "]}, {" : "{\"measure_sets\": [{");
printf("\"measure_type\": \"packet_jitter\","
"\"props_names\": [\"jitter\"],"
"\"units\": [\"us\"],"
"\"props_type\": \"histogram\","
"\"middle\": \"%d\","
"\"metadata\": {"
"\"i\": \"%dus\", \"duration\": \"%dh%d\""
"},"
"\"metadata\": {\"i\": \"%dus\", \"duration\": \"%dh%d\"},"
"\"props\": [[",
MAX_JITTER / 2 - min_jitter,
interval,
duration_hour,
duration_minutes);
MAX_JITTER / 2 - min_jitter, interval, duration_hour, duration_minutes);
for (int j = min_jitter; j < max_jitter; j++)
printf("%" PRIi64 "%s", jitter_hist[j], (j + 1 < max_jitter ? ", " : ""));
printf("]]}]}\n");
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment