Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
6ef95a4754 | |||
0565005ad3 | |||
cb68919063 | |||
870450fe84 |
49
compterendu.md
Normal file
49
compterendu.md
Normal file
@ -0,0 +1,49 @@
|
||||
# Compte-rendu TP
|
||||
###### Groupe SCHIED Killian, LANDRIN Dylan
|
||||
## Fichier "deamon.c"
|
||||
#### Détails
|
||||
##### create_deamon()
|
||||
Complexité Cyclomatique : 4
|
||||
##### ping_request()
|
||||
Complexité Cyclomatique : 2
|
||||
##### send_check()
|
||||
Complexité Cyclomatique : 4
|
||||
##### check_keep_working()
|
||||
Complexité Cyclomatique : 4
|
||||
##### daemon_work()
|
||||
Complexité Cyclomatique : 3
|
||||
## Fichier "db-sqlite.c"
|
||||
#### Détails
|
||||
##### db_connect()
|
||||
Complexité Cyclomatique : 1
|
||||
##### db_disconnect()
|
||||
Complexité Cyclomatique : 1
|
||||
##### insert_hourly_report()
|
||||
Complexité Cyclomatique : 1
|
||||
## Fichier "ping-report.c"
|
||||
#### Détails
|
||||
##### main()
|
||||
Complexité Cyclomatique : 4
|
||||
## Fichier "stats.c"
|
||||
### Avant modification
|
||||
#### Détails
|
||||
##### get_ping_from_temp_log()
|
||||
Complexité Cyclomatique : 15
|
||||
##### write_ping_log()
|
||||
Complexité Cyclomatique : 4
|
||||
##### set_stats_ping()
|
||||
Complexité Cyclomatique : 25
|
||||
### Après modification
|
||||
#### Détails
|
||||
##### get_ping_from_temp_log()
|
||||
Complexité Cyclomatique : 5
|
||||
##### find_ping() (Nouvelle fonction pour diminuer la complexité de get_ping_from_temp_log())
|
||||
Complexité Cyclomatique : 8
|
||||
##### set_stats_ping()
|
||||
Complexité Cyclomatique : ?
|
||||
## Fichier "utils.c"
|
||||
#### Détails
|
||||
##### write_pid_file()
|
||||
Complexité Cyclomatique : 2
|
||||
##### remove_file()
|
||||
Complexité Cyclomatique : 1
|
4
diagrammes/find_ping.drawio.svg
Normal file
4
diagrammes/find_ping.drawio.svg
Normal file
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 201 KiB |
4
diagrammes/get_ping_from_temp_log-OPTIMIZED.drawio.svg
Normal file
4
diagrammes/get_ping_from_temp_log-OPTIMIZED.drawio.svg
Normal file
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 119 KiB |
4
diagrammes/get_ping_from_temp_log.svg
Normal file
4
diagrammes/get_ping_from_temp_log.svg
Normal file
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 317 KiB |
4
diagrammes/set_stats_ping.svg
Normal file
4
diagrammes/set_stats_ping.svg
Normal file
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 481 KiB |
BIN
ping-report/ping-report
Executable file
BIN
ping-report/ping-report
Executable file
Binary file not shown.
BIN
ping-report/ping-report.db
Normal file
BIN
ping-report/ping-report.db
Normal file
Binary file not shown.
@ -32,9 +32,6 @@
|
||||
regex_t *p_reg;
|
||||
regmatch_t* pmatch;
|
||||
char* ping = NULL;
|
||||
int start;
|
||||
int end;
|
||||
size_t size_ping;
|
||||
|
||||
/* regex struct memory allocation */
|
||||
p_reg = (regex_t *) malloc(sizeof(*p_reg));
|
||||
@ -51,9 +48,9 @@
|
||||
|
||||
/* Construct regex to get ping from log file */
|
||||
if(regcomp(p_reg,"time=(.*) ms",REG_EXTENDED) != 0){
|
||||
if(p_reg != NULL){
|
||||
//if(p_reg != NULL){
|
||||
free(p_reg);
|
||||
}
|
||||
//}
|
||||
(void) fclose(fd);
|
||||
return ping; /* NULL */
|
||||
}
|
||||
@ -67,6 +64,41 @@
|
||||
return ping; /* NULL */
|
||||
}
|
||||
|
||||
ping = find_ping(read_line, n, fd);
|
||||
|
||||
/* free allocated memory */
|
||||
regfree(p_reg);
|
||||
free(p_reg);
|
||||
free(pmatch);
|
||||
//if(read_line != NULL){
|
||||
//free(read_line);
|
||||
//}
|
||||
|
||||
(void) fclose(fd);
|
||||
|
||||
/* ping may be null, then it must mean that the ping request was lost */
|
||||
return ping;
|
||||
}
|
||||
|
||||
/*
|
||||
La fonction get_ping_from_temp_log avait une complexité cyclomatique de 15.
|
||||
|
||||
Modifications:
|
||||
Ligne 51 et 53 (anciennement 54 et 56):
|
||||
Retirer la verification if, car peut importe ce qu'il se passe, p_reg ne peut pas être null, la fonction ce serait arretée
|
||||
Ligne 73,74 et 75 (anciennement 116, 117 et 118):
|
||||
Retirer encore du code mort, car la verification est inutile, avant de déplacer le while, read_line était forcemment null à ce moment.
|
||||
Le while a été segmenté en une fonction find_ping() à part, qui prend en paramètre ce dont il a besoin et retourne ping.
|
||||
|
||||
Tous ces changements on fait passer la complexité cyclomatique de get_ping_from_temp_log de 15, à 5. find_ping() quand a lui est également à 8.
|
||||
*/
|
||||
|
||||
char* find_ping(char* read_line, size_t n, FILE* fd){
|
||||
int start;
|
||||
int end;
|
||||
size_t size_ping;
|
||||
char* ping2 = NULL;
|
||||
|
||||
/* Read file */
|
||||
while(getline(&read_line,&n,fd) != -1){
|
||||
|
||||
@ -84,8 +116,8 @@
|
||||
size_ping = (size_t) (end - start);
|
||||
|
||||
/* ping string memory allocation */
|
||||
ping = malloc(sizeof(char) * (size_ping+2));
|
||||
if(ping == NULL){
|
||||
ping2 = malloc(sizeof(char) * (size_ping+2));
|
||||
if(ping2 == NULL){
|
||||
free(read_line);
|
||||
read_line = NULL;
|
||||
n = 0;
|
||||
@ -93,9 +125,9 @@
|
||||
}
|
||||
|
||||
/* Create ping string */
|
||||
(void) strncpy(ping, &read_line[start], size_ping);
|
||||
ping[size_ping]='\n';
|
||||
ping[size_ping+1]='\0';
|
||||
(void) strncpy(ping2, &read_line[start], size_ping);
|
||||
ping2[size_ping]='\n';
|
||||
ping2[size_ping+1]='\0';
|
||||
|
||||
/* Free memory */
|
||||
free(read_line);
|
||||
@ -107,20 +139,8 @@
|
||||
free(read_line);
|
||||
read_line = NULL;
|
||||
n = 0;
|
||||
return ping2;
|
||||
}
|
||||
|
||||
/* free allocated memory */
|
||||
regfree(p_reg);
|
||||
free(p_reg);
|
||||
free(pmatch);
|
||||
if(read_line != NULL){
|
||||
free(read_line);
|
||||
}
|
||||
|
||||
(void) fclose(fd);
|
||||
|
||||
/* ping may be null, then it must mean that the ping request was lost */
|
||||
return ping;
|
||||
}
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user