From 4d3b17540d9163b2d74aa6ac1a03c97553bae18d Mon Sep 17 00:00:00 2001 From: Samuel Date: Thu, 18 Jul 2024 21:31:23 +0200 Subject: [PATCH] Mesure de performance de l'envoi UDP --- picow_udp_beacon.c | 48 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/picow_udp_beacon.c b/picow_udp_beacon.c index 8f6a566..061c40c 100644 --- a/picow_udp_beacon.c +++ b/picow_udp_beacon.c @@ -25,7 +25,12 @@ struct udp_pcb* pcb; ip_addr_t addr; -int teleplot_counter = 0; +int teleplot_compteur_envoie = 0; +int teleplot_compteur_cache = 0; +int time_snprintf = 0; +int time_strlen = 0; +int time_strcat = 0; +int time_udp = 0; char teleplot_tampon[BEACON_MSG_LEN_MAX]=""; @@ -34,27 +39,39 @@ void teleplot_udp_send_string(char * message); void Teleplot_ajout_ou_envoie_tampon(char * message){ // Si le tampon ne peut pas accueillir le prochain message // On envoie et on vide le tampon + int time = time_us_32(); if(strlen(message) + strlen(teleplot_tampon) > BEACON_MSG_LEN_MAX){ + int m_time = time_us_32(); teleplot_udp_send_string(teleplot_tampon); - teleplot_tampon[0]='\0'; // On "vide" le tampon - teleplot_counter++; - } + time_udp = time_us_32() - m_time; + teleplot_tampon[0]='\0'; // On "vide" le tampon + teleplot_compteur_envoie++; + }else{ + time_strlen += time_us_32() - time; + } // On ajoute le message au tampon + time = time_us_32(); strcat(teleplot_tampon, message); + time_strcat += time_us_32() - time; + teleplot_compteur_cache++; } void Teleplot_add_variable_float_2decimal(char * nom_variable, float valeur){ char tampon[100]; + int time = time_us_32(); sprintf(tampon, "%s:%lu:%.2f\n", nom_variable, (long)time_us_64()/1000, valeur); - teleplot_udp_send_string(tampon); + time_snprintf += time_us_32() - time; + Teleplot_ajout_ou_envoie_tampon(tampon); } void Teleplot_add_variable_int(char * nom_variable, int valeur){ char tampon[100]; + int time = time_us_32(); sprintf(tampon, "%s:%lu:%d\n", nom_variable, (long)time_us_64()/1000, valeur); - teleplot_udp_send_string(tampon); + time_snprintf += time_us_32() - time; + Teleplot_ajout_ou_envoie_tampon(tampon); } void teleplot_udp_send_string(char * message){ @@ -97,7 +114,7 @@ void run_udp_beacon() { uint32_t old_time = time_us_32(); uint32_t time, driver_time; uint32_t delta_time = 0, delta_driver = 0, teleplot_time=0, delta_teleplot=0; - int teleplot_counter_old = teleplot_counter; + int teleplot_counter_old = teleplot_compteur_envoie; while (true) { char tampon[100]; @@ -114,10 +131,21 @@ void run_udp_beacon() { teleplot_time = time_us_32(); Teleplot_add_variable_float_2decimal("cos", cosf(counter/10.)); Teleplot_add_variable_float_2decimal("sin", sinf(counter/10.)); - if(teleplot_counter_old != teleplot_counter){ - Teleplot_add_variable_int("m_time", delta_teleplot / teleplot_counter); + if(teleplot_counter_old != teleplot_compteur_envoie){ + Teleplot_add_variable_int("t_time", delta_teleplot); + Teleplot_add_variable_int("m_time", delta_teleplot / (teleplot_compteur_cache)); + Teleplot_add_variable_int("snprintf_time", time_snprintf / (teleplot_compteur_cache)); + Teleplot_add_variable_int("strlen_time", time_strlen / (teleplot_compteur_cache)); + Teleplot_add_variable_int("strcat_time", time_strcat / (teleplot_compteur_cache)); + Teleplot_add_variable_int("time_udp", time_udp / (teleplot_compteur_cache)); + Teleplot_add_variable_float_2decimal("nb_cache", teleplot_compteur_cache); delta_teleplot = 0; - teleplot_counter_old = teleplot_counter; + time_snprintf= 0; + time_strlen = 0; + time_strcat = 0; + time_udp = 0; + teleplot_compteur_cache = 0; + teleplot_counter_old = teleplot_compteur_envoie; } delta_teleplot += time_us_32() - teleplot_time;