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

Add option to print histograms to stdout on exit

parent f696b55f
This diff is collapsed.
......@@ -41,7 +41,7 @@
#define MESSAGE ((uint32_t)0x00FACADE)
static void process_timestamps(struct packet_timestamps *packet_ts);
static void process_timestamps(struct packet_timestamps *packet_ts, int64_t histograms[NB_HISTOGRAMS][MAX_HIST_VAL]);
static void init_tx_buffer(size_t _tx_buffer_len);
static int so_priority = 3;
......@@ -148,7 +148,8 @@ uint64_t get_txtime() {
*/
struct packet_timestamps send_udp_packet(int use_etf, int use_timestamps,
uint64_t txtime,
const char *server_ip) {
const char *server_ip,
int64_t histograms[NB_HISTOGRAMS][MAX_HIST_VAL]) {
char control[CMSG_SPACE(sizeof(txtime))] = {};
struct sockaddr_in sin;
struct cmsghdr *cmsg;
......@@ -205,7 +206,7 @@ struct packet_timestamps send_udp_packet(int use_etf, int use_timestamps,
if (use_timestamps) {
res = poll(&poll_fd, 1, 0);
if (res > 0)
process_timestamps(&packet_ts);
process_timestamps(&packet_ts, histograms);
else
fprintf(stderr, "select failed\n");
}
......@@ -213,7 +214,27 @@ struct packet_timestamps send_udp_packet(int use_etf, int use_timestamps,
return packet_ts;
}
static void process_timestamps(struct packet_timestamps *packet_ts) {
static void fill_histograms(struct packet_timestamps *packet_ts, int64_t histograms[NB_HISTOGRAMS][MAX_HIST_VAL]) {
uint64_t user_space_time = packet_ts->user_call_sendmsg - packet_ts->user_enter_send;
uint64_t kernel_space_time = packet_ts->kernel_leave - packet_ts->user_call_sendmsg;
user_space_time /= 1000u;
kernel_space_time /= 1000u;
if(user_space_time > MAX_HIST_VAL) {
fprintf(stderr, "user_space_time value too high: %" PRIu64 "us\n", user_space_time);
exit(EXIT_FAILURE);
}
if(kernel_space_time > MAX_HIST_VAL) {
fprintf(stderr, "kernel_space_time value too high: %" PRIu64 "us\n", kernel_space_time);
exit(EXIT_FAILURE);
}
histograms[0][user_space_time]++;
histograms[1][kernel_space_time]++;
}
static void process_timestamps(struct packet_timestamps *packet_ts, int64_t histograms[NB_HISTOGRAMS][MAX_HIST_VAL]) {
char data[256];
struct msghdr msg;
struct iovec entry;
......@@ -243,6 +264,7 @@ static void process_timestamps(struct packet_timestamps *packet_ts) {
if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SO_TIMESTAMPING) {
struct timespec *stamp = (struct timespec *)CMSG_DATA(cmsg);
packet_ts->kernel_leave = ts_to_uint(*stamp);
fill_histograms(packet_ts, histograms);
} else {
#ifdef DEBUG
fprintf(stderr, "process_timestamps: level %d type %d", cmsg->cmsg_level,
......
......@@ -4,6 +4,8 @@
#include <stdint.h>
#include <stdio.h>
#include "utilities.h"
struct packet_timestamps {
uint64_t user_enter_send;
uint64_t user_call_sendmsg;
......@@ -11,6 +13,6 @@ struct packet_timestamps {
};
void init_udp_send(int use_etf, int use_timestamps, int so_priority, char * network_if, size_t tx_buffer_len);
struct packet_timestamps send_udp_packet(int use_etf, int use_timestamps, uint64_t txtime, const char *server_ip);
struct packet_timestamps send_udp_packet(int use_etf, int use_timestamps, uint64_t txtime, const char *server_ip, int64_t histograms[NB_HISTOGRAMS][MAX_HIST_VAL]);
#endif
......@@ -98,7 +98,7 @@ static void *packet_receiving_thread(void *p) {
for (stats->packets_received = 0;; stats->packets_received++) {
if (param->tsn_task == RTT_TASK) {
recv_udp_packet(param->sockfd);
send_udp_packet(0, 0, 0, param->ip_address);
send_udp_packet(0, 0, 0, param->ip_address, NULL);
} else if (param->tsn_task == RECV_PACKET_TASK) {
recv_udp_packet(param->sockfd);
......
......@@ -10,6 +10,8 @@
#define NSEC_PER_SEC UINT64_C(1000000000)
#define SERVER_PORT "50000"
#define SERVER_PORT_INT 50000
#define MAX_HIST_VAL 1000
#define NB_HISTOGRAMS 3
uint64_t ts_to_uint(struct timespec t);
void add_ns(struct timespec *t, uint64_t ns);
......
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