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() { ...@@ -310,17 +310,12 @@ static void print_histograms() {
"\"props_names\": [\"user_space\", \"kernel_space\"]," "\"props_names\": [\"user_space\", \"kernel_space\"],"
"\"units\": [\"us\", \"us\"]," "\"units\": [\"us\", \"us\"],"
"\"props_type\": \"histogram\"," "\"props_type\": \"histogram\","
"\"metadata\": {" "\"metadata\": {\"i\": \"%dus\", \"duration\": \"%dh%d\", \"etf_offset\": \"%dus\",},"
"\"i\": \"%dus\", \"duration\": \"%dh%d\", \"etf_offset\": \"%dus\"," "\"props\": [[",
"},"
"\"props\": [",
interval, duration_hour, duration_minutes, thread_params.etf_offset); interval, duration_hour, duration_minutes, thread_params.etf_offset);
histogram = kernel_latency_hist;
max_hist_val = 0; histogram = kernel_latency_hist;
for (int j = 0; j < MAX_KERNEL_LATENCY; j++) max_hist_val = histogram_max(histogram, MAX_KERNEL_LATENCY - 1);
if (histogram[j])
max_hist_val = j > max_hist_val ? j : max_hist_val;
} else { } else {
printf("{\"measure_sets\": [{" printf("{\"measure_sets\": [{"
...@@ -328,25 +323,17 @@ static void print_histograms() { ...@@ -328,25 +323,17 @@ static void print_histograms() {
"\"props_names\": [\"rtt\"]," "\"props_names\": [\"rtt\"],"
"\"units\": [\"us\"]," "\"units\": [\"us\"],"
"\"props_type\": \"histogram\"," "\"props_type\": \"histogram\","
"\"metadata\": {" "\"metadata\": {\"i\": \"%dus\", \"duration\": \"%dh%d\", \"etf_offset\": \"%dus\",},"
"\"i\": \"%dus\", \"duration\": \"%dh%d\", \"etf_offset\": \"%dus\"," "\"props\": [[",
"},"
"\"props\": [",
interval, duration_hour, duration_minutes, thread_params.etf_offset); interval, duration_hour, duration_minutes, thread_params.etf_offset);
histogram = rtt_hist;
max_hist_val = 0; histogram = rtt_hist;
for (int j = 0; j < MAX_RTT; j++) max_hist_val = histogram_max(histogram, MAX_RTT - 1);
if (histogram[j])
max_hist_val = j > max_hist_val ? j : max_hist_val;
} }
printf("[");
for (int j = 0; j < max_hist_val; j++) for (int j = 0; j < max_hist_val; j++)
printf("%" PRIi64 "%s", histogram[j], (j + 1 < max_hist_val ? ", " : "")); printf("%" PRIi64 "%s", histogram[j], (j + 1 < max_hist_val ? ", " : ""));
printf("]"); printf("]]}]}\n");
printf("]}]}\n");
} }
static void sighand(int sig_num) { static void sighand(int sig_num) {
......
...@@ -35,6 +35,20 @@ uint64_t calcdiff_ns(struct timespec t1, struct timespec t2) { ...@@ -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 max(int a, int b) { return a > b ? a : b; }
int min(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) { static void sighand_wrapper(int sig) {
// If we get un unexpected signal, report it, if not print the histogram // 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); ...@@ -29,6 +29,9 @@ void init_signals(void (*_sighand)(int), int enable_histograms);
int min(int a, int b); int min(int a, int b);
int max(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); extern void (*previous_handlers[NSIG])(int);
#endif #endif
...@@ -271,58 +271,36 @@ static void print_histograms() { ...@@ -271,58 +271,36 @@ static void print_histograms() {
if (enable_timestamps) { if (enable_timestamps) {
printf("{\"measure_sets\": [{" printf("{\"measure_sets\": [{"
"\"measure_type\": \"packet_recv_timestamps\"," "\"measure_type\": \"packet_recv_timestamps\","
"\"props_names\": [\"user_space\", \"kernel_space\"]," "\"props_names\": [\"kernel_space\"],"
"\"units\": [\"us\", \"us\"]," "\"units\": [\"us\"],"
"\"props_type\": \"histogram\"," "\"props_type\": \"histogram\","
"\"metadata\": {" "\"metadata\": \"i\": \"%dus\", \"duration\": \"%dh%d\"},"
"\"i\": \"%dus\", \"duration\": \"%dh%d\"" "\"props\": [[",
"},"
"\"props\": [",
interval, duration_hour, duration_minutes); interval, duration_hour, duration_minutes);
max_latency = 0; max_latency = histogram_max(kernel_latency_hist, MAX_KERNEL_LATENCY - 1);
for (int j = 0; j < MAX_KERNEL_LATENCY; j++)
if (kernel_latency_hist[j])
max_latency = j;
printf("[");
for (int j = 0; j < max_latency; j++) for (int j = 0; j < max_latency; j++)
printf("%" PRIi64 "%s", kernel_latency_hist[j], (j + 1 < max_latency ? ", " : "")); printf("%" PRIi64 "%s", kernel_latency_hist[j], (j + 1 < max_latency ? ", " : ""));
printf("]"); printf("]]");
} }
max_jitter = 0; max_jitter = histogram_max(jitter_hist, MAX_JITTER - 1);
for (int j = 0; j < MAX_JITTER; j++) min_jitter = histogram_min(jitter_hist, MAX_JITTER - 1);
if (jitter_hist[j])
max_jitter = j;
min_jitter = MAX_JITTER - 1; printf("%s", enable_timestamps ? "]}, {" : "{\"measure_sets\": [{");
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("\"measure_type\": \"packet_jitter\"," printf("\"measure_type\": \"packet_jitter\","
"\"props_names\": [\"jitter\"]," "\"props_names\": [\"jitter\"],"
"\"units\": [\"us\"]," "\"units\": [\"us\"],"
"\"props_type\": \"histogram\"," "\"props_type\": \"histogram\","
"\"middle\": \"%d\"," "\"middle\": \"%d\","
"\"metadata\": {" "\"metadata\": {\"i\": \"%dus\", \"duration\": \"%dh%d\"},"
"\"i\": \"%dus\", \"duration\": \"%dh%d\""
"},"
"\"props\": [[", "\"props\": [[",
MAX_JITTER / 2 - min_jitter, MAX_JITTER / 2 - min_jitter, interval, duration_hour, duration_minutes);
interval,
duration_hour,
duration_minutes);
for (int j = min_jitter; j < max_jitter; j++) for (int j = min_jitter; j < max_jitter; j++)
printf("%" PRIi64 "%s", jitter_hist[j], (j + 1 < max_jitter ? ", " : "")); printf("%" PRIi64 "%s", jitter_hist[j], (j + 1 < max_jitter ? ", " : ""));
printf("]]}]}\n"); 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