Hardening my measurement tool
This commit is contained in:
parent
d4bbca89f0
commit
c77fcf148d
4 changed files with 42 additions and 16 deletions
|
@ -176,7 +176,11 @@ struct evt_core_cat* evt_core_rm_fd(struct evt_core_ctx* ctx, int fd) {
|
||||||
|
|
||||||
// 3. Remove structure from urltofd and socklist
|
// 3. Remove structure from urltofd and socklist
|
||||||
g_hash_table_remove(ctx->urltofd, fdinfo->url);
|
g_hash_table_remove(ctx->urltofd, fdinfo->url);
|
||||||
g_hash_table_remove(ctx->socklist, &fd); // Will be free here
|
g_hash_table_remove(ctx->socklist, &fd); // Will be freed here
|
||||||
|
|
||||||
|
// 4. List the fd as blacklisted for the end of the current loop
|
||||||
|
ctx->blacklisted_fds[ctx->blacklisted_fds_count] = fd;
|
||||||
|
ctx->blacklisted_fds_count++;
|
||||||
|
|
||||||
// 4. Close and remove file descriptor
|
// 4. Close and remove file descriptor
|
||||||
// Done in free_fdinfo
|
// Done in free_fdinfo
|
||||||
|
@ -193,8 +197,18 @@ void evt_core_free(struct evt_core_ctx* ctx) {
|
||||||
g_hash_table_destroy (ctx->urltofd);
|
g_hash_table_destroy (ctx->urltofd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int evt_core_fd_bl(struct evt_core_ctx* ctx, int fd) {
|
||||||
|
for (int j = 0; j < ctx->blacklisted_fds_count; j++) {
|
||||||
|
if (ctx->blacklisted_fds[j] == fd) {
|
||||||
|
fprintf(stderr, "fd=%d has been deleted, skipping epoll notification\n", ctx->blacklisted_fds[j]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void evt_core_loop(struct evt_core_ctx* ctx) {
|
void evt_core_loop(struct evt_core_ctx* ctx) {
|
||||||
struct epoll_event current_event, events[EVT_CORE_MAX_EVENTS];
|
struct epoll_event events[EVT_CORE_MAX_EVENTS];
|
||||||
struct evt_core_fdinfo* fdinfo;
|
struct evt_core_fdinfo* fdinfo;
|
||||||
struct evt_core_cat* cat;
|
struct evt_core_cat* cat;
|
||||||
int return_code;
|
int return_code;
|
||||||
|
@ -211,6 +225,7 @@ void evt_core_loop(struct evt_core_ctx* ctx) {
|
||||||
printf("--- Start main loop\n");
|
printf("--- Start main loop\n");
|
||||||
int num_fd, n = 0;
|
int num_fd, n = 0;
|
||||||
while(ctx->loop) {
|
while(ctx->loop) {
|
||||||
|
ctx->blacklisted_fds_count = 0;
|
||||||
timing_fx_start(&tfx_epoll);
|
timing_fx_start(&tfx_epoll);
|
||||||
num_fd = epoll_wait(ctx->epollfd, events, EVT_CORE_MAX_EVENTS, -1);
|
num_fd = epoll_wait(ctx->epollfd, events, EVT_CORE_MAX_EVENTS, -1);
|
||||||
timing_fx_stop(&tfx_epoll);
|
timing_fx_stop(&tfx_epoll);
|
||||||
|
@ -224,6 +239,7 @@ void evt_core_loop(struct evt_core_ctx* ctx) {
|
||||||
// 1. Handle errors
|
// 1. Handle errors
|
||||||
for (n = 0 ; n < num_fd; n++) {
|
for (n = 0 ; n < num_fd; n++) {
|
||||||
if (!(events[n].events & (EPOLLERR | EPOLLHUP | EPOLLRDHUP))) continue;
|
if (!(events[n].events & (EPOLLERR | EPOLLHUP | EPOLLRDHUP))) continue;
|
||||||
|
if (evt_core_fd_bl(ctx, events[n].data.fd)) continue;
|
||||||
|
|
||||||
int err_fd = events[n].data.fd;
|
int err_fd = events[n].data.fd;
|
||||||
int evt = events[n].events;
|
int evt = events[n].events;
|
||||||
|
@ -268,6 +284,8 @@ void evt_core_loop(struct evt_core_ctx* ctx) {
|
||||||
// 2. Fetch info and call appropriate function
|
// 2. Fetch info and call appropriate function
|
||||||
for (n = 0 ; n < num_fd; n++) {
|
for (n = 0 ; n < num_fd; n++) {
|
||||||
if (events[n].events & (EPOLLERR | EPOLLHUP | EPOLLRDHUP)) continue;
|
if (events[n].events & (EPOLLERR | EPOLLHUP | EPOLLRDHUP)) continue;
|
||||||
|
if (evt_core_fd_bl(ctx, events[n].data.fd)) continue;
|
||||||
|
|
||||||
fdinfo = g_hash_table_lookup(ctx->socklist, &(events[n].data.fd));
|
fdinfo = g_hash_table_lookup(ctx->socklist, &(events[n].data.fd));
|
||||||
if (fdinfo == NULL) {
|
if (fdinfo == NULL) {
|
||||||
fprintf(stderr, "Ignoring file descriptor %d as it is not registered. This is a bug.\n", events[n].data.fd);
|
fprintf(stderr, "Ignoring file descriptor %d as it is not registered. This is a bug.\n", events[n].data.fd);
|
||||||
|
|
|
@ -39,6 +39,8 @@ struct evt_core_ctx {
|
||||||
int epollfd;
|
int epollfd;
|
||||||
uint8_t verbose;
|
uint8_t verbose;
|
||||||
uint8_t loop;
|
uint8_t loop;
|
||||||
|
int blacklisted_fds[EVT_CORE_MAX_EVENTS];
|
||||||
|
int blacklisted_fds_count;
|
||||||
GHashTable* catlist; // name -> category
|
GHashTable* catlist; // name -> category
|
||||||
GHashTable* socklist; // fd -> category
|
GHashTable* socklist; // fd -> category
|
||||||
GHashTable* urltofd; // url -> fd, like "tcp:127.0.0.1:7500"
|
GHashTable* urltofd; // url -> fd, like "tcp:127.0.0.1:7500"
|
||||||
|
|
|
@ -24,7 +24,6 @@ struct measlat_ctx {
|
||||||
};
|
};
|
||||||
|
|
||||||
void free_ms(void* obj) {
|
void free_ms(void* obj) {
|
||||||
printf("free measure state\n");
|
|
||||||
measure_state_free (obj);
|
measure_state_free (obj);
|
||||||
free(obj);
|
free(obj);
|
||||||
}
|
}
|
||||||
|
@ -91,14 +90,17 @@ int on_receive_measure_packet_err(struct evt_core_ctx* ctx, struct evt_core_fdin
|
||||||
sprintf(url, "timer:%d", fdinfo->fd);
|
sprintf(url, "timer:%d", fdinfo->fd);
|
||||||
struct evt_core_fdinfo* assoc_timer = evt_core_get_from_url (ctx, url);
|
struct evt_core_fdinfo* assoc_timer = evt_core_get_from_url (ctx, url);
|
||||||
if (assoc_timer != NULL) {
|
if (assoc_timer != NULL) {
|
||||||
|
measure_summary (&mctx->mp, assoc_timer->other);
|
||||||
evt_core_rm_fd (ctx, assoc_timer->fd);
|
evt_core_rm_fd (ctx, assoc_timer->fd);
|
||||||
printf("Deleted associated timer %s\n", url);
|
printf("Deleted associated timer %s\n", url);
|
||||||
} else {
|
} else {
|
||||||
printf("No associated timer %s\n", url);
|
printf("No associated timer %s\n", url);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mctx->connectionless) return 1;
|
if (mctx->role == MEASLAT_CLIENT) exit(EXIT_FAILURE);
|
||||||
else return 0;
|
|
||||||
|
if (mctx->connectionless) return 1; // keep the NET FD
|
||||||
|
else return 0; // delete the NET fd
|
||||||
}
|
}
|
||||||
|
|
||||||
void measlat_stop(
|
void measlat_stop(
|
||||||
|
|
|
@ -178,29 +178,33 @@ void measure_summary(struct measure_params* mp, struct measure_state* ms) {
|
||||||
real_log_size--;
|
real_log_size--;
|
||||||
}
|
}
|
||||||
printf("[summary] cutted %lu values in total\n", mp->max_measure - real_log_size);
|
printf("[summary] cutted %lu values in total\n", mp->max_measure - real_log_size);
|
||||||
|
fprintf(stdout, "%s,%s,count,%lu\n", mp->tag, uuidstr, real_log_size);
|
||||||
|
if (real_log_size == 0) return;
|
||||||
|
|
||||||
|
// AVERAGE
|
||||||
|
double avg = 0;
|
||||||
|
for (int i = 0; i < real_log_size; i++) {
|
||||||
|
avg += ((double) real_log[i]) / ((double) real_log_size);
|
||||||
|
}
|
||||||
|
fprintf(stdout, "%s,%s,avg,%f\n", mp->tag, uuidstr, avg);
|
||||||
|
|
||||||
|
// DISTRIBUTION
|
||||||
|
qsort (real_log, real_log_size, sizeof(uint64_t), cmpuint64t);
|
||||||
uint64_t min = real_log[0];
|
uint64_t min = real_log[0];
|
||||||
fprintf(stdout, "%s,%s,min,%lu\n", mp->tag, uuidstr, min);
|
fprintf(stdout, "%s,%s,min,%lu\n", mp->tag, uuidstr, min);
|
||||||
|
|
||||||
uint64_t max = real_log[real_log_size-1];
|
uint64_t max = real_log[real_log_size-1];
|
||||||
fprintf(stdout, "%s,%s,max,%lu\n", mp->tag, uuidstr, max);
|
fprintf(stdout, "%s,%s,max,%lu\n", mp->tag, uuidstr, max);
|
||||||
|
|
||||||
uint64_t med = real_log[(int)(0.50 * (real_log_size - 1))];
|
uint64_t med = real_log[(int)(0.50 * real_log_size)];
|
||||||
fprintf(stdout, "%s,%s,med,%lu\n", mp->tag, uuidstr, med);
|
fprintf(stdout, "%s,%s,med,%lu\n", mp->tag, uuidstr, med);
|
||||||
|
|
||||||
uint64_t q25 = real_log[(int)(0.25 * (real_log_size - 1))];
|
uint64_t q25 = real_log[(int)(0.25 * real_log_size)];
|
||||||
fprintf(stdout, "%s,%s,q25,%lu\n", mp->tag, uuidstr, q25);
|
fprintf(stdout, "%s,%s,q25,%lu\n", mp->tag, uuidstr, q25);
|
||||||
|
|
||||||
uint64_t q75 = real_log[(int)(0.75 * (real_log_size - 1))];
|
uint64_t q75 = real_log[(int)(0.75 * real_log_size)];
|
||||||
fprintf(stdout, "%s,%s,q75,%lu\n", mp->tag, uuidstr, q75);
|
fprintf(stdout, "%s,%s,q75,%lu\n", mp->tag, uuidstr, q75);
|
||||||
|
|
||||||
uint64_t q99 = real_log[(int)(0.99 * (real_log_size - 1))];
|
uint64_t q99 = real_log[(int)(0.99 * real_log_size)];
|
||||||
fprintf(stdout, "%s,%s,q99,%lu\n", mp->tag, uuidstr, q99);
|
fprintf(stdout, "%s,%s,q99,%lu\n", mp->tag, uuidstr, q99);
|
||||||
|
|
||||||
qsort (real_log, real_log_size, sizeof(uint64_t), cmpuint64t);
|
|
||||||
double avg = 0;
|
|
||||||
for (int i = 0; i < real_log_size-1; i++) {
|
|
||||||
avg += ((double) real_log[i]) / ((double) (real_log_size - 1));
|
|
||||||
}
|
|
||||||
fprintf(stdout, "%s,%s,avg,%f\n", mp->tag, uuidstr, avg);
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue