diff --git a/compte-rendu.md b/compte-rendu.md new file mode 100644 index 0000000..40a9481 --- /dev/null +++ b/compte-rendu.md @@ -0,0 +1,92 @@ +# Damien Riera - Tom Momméja - Gaston Chenet + +## daemon.c + +### create_daemon() + +cette fonction a une complexité de 4 + +### ping_request() + +Cette fonction a une complexité de 2 + +### send_check() + +Cette fonction a une complexité de 3 + +### check_keep_working() + +Cette fonction a une complexité de 4 + +### daemon_work() + +Cette fonction a une complexité de 3 + +## db-sqlite.c + +### db_connect() - db_disconnect() - insert_hourly_report() + +Toutes ces fonctions ont une complexité de 1 + +## ping-report.c + +### main() + +Cette fonction a une complexité de 4 + +## stats.c + +### get_ping_from_temp_log() + +Cette fonction a une complexité de 8 + +![Diagramme de complexité](./images/get_ping_from_temp_log.webp) + +### write_ping_log() + +Cette fonction a une complexité de 4 + +### set_stats_ping() + +Cette fonction a une complexité de 9 + +![Diagrame de complexité](./images/set_stats_ping.png) + +## utils.c + +### write_pid_file() + +Cette fonction a une commplexité de 2 + +### remove_file() + +Cette fonction a une complexité de 1 + +# Réduire la complexité de set_stats_ping() + +```c +/* Check if the ping is flagged as LOSS */ +if(strcmp(read_line,"LOSS") == 0){ + nb_loss++; +}else{ + /* Evaluate the ping as a double */ + ping = strtod(read_line,NULL); + /* Test null ping */ + if(ping < 0.1){ + /* Ignore null ping */ + } + /* ... */ +} +``` + +à: + +```c +/* Evaluate the ping as a double */ +ping = strtod(read_line,NULL); +/* Check if the ping is flagged as LOSS */ +if(strcmp(read_line,"LOSS") == 0 && ping < 0.1){ + nb_loss++; +} +/* ... */ +``` diff --git a/images/get_ping_from_temp_log.webp b/images/get_ping_from_temp_log.webp new file mode 100644 index 0000000..4426b12 Binary files /dev/null and b/images/get_ping_from_temp_log.webp differ diff --git a/images/set_stats_ping.png b/images/set_stats_ping.png new file mode 100644 index 0000000..beaee78 Binary files /dev/null and b/images/set_stats_ping.png differ diff --git a/ping-report/src/stats.c b/ping-report/src/stats.c index 5b343e8..85c62b9 100644 --- a/ping-report/src/stats.c +++ b/ping-report/src/stats.c @@ -198,35 +198,29 @@ void set_stats_ping(){ if(read_line == NULL){ break; } - + /* Evaluate the ping as a double */ + ping = strtod(read_line,NULL); /* Check if the ping is flagged as LOSS */ - if(strcmp(read_line,"LOSS") == 0){ + if(strcmp(read_line,"LOSS") == 0 && ping < 0.1){ nb_loss++; }else{ - /* Evaluate the ping as a double */ - ping = strtod(read_line,NULL); - /* Test null ping */ - if(ping < 0.1){ - /* Ignore null ping */ - }else{ - /* Number of ping readed (for mean calculation) */ - nb_ping++; - /* Max ping */ - if(ping > max){ - max = ping; - } - /* Min ping */ - if(ping < min){ - min = ping; - } - /* Number of ping above 100 ms */ - if(ping > 100.0){ - nb_high++; - } - /* Sum (for mean calculation) */ - sum += ping; + /* Number of ping readed (for mean calculation) */ + nb_ping++; + /* Max ping */ + if(ping > max){ + max = ping; } - } + /* Min ping */ + if(ping < min){ + min = ping; + } + /* Number of ping above 100 ms */ + if(ping > 100.0){ + nb_high++; + } + /* Sum (for mean calculation) */ + sum += ping; + } free(read_line); n = 0; }