4 Commits

8 changed files with 108 additions and 23 deletions
+49
View 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
File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 201 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 119 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 317 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 481 KiB

BIN
View File
Binary file not shown.
Binary file not shown.
+43 -23
View File
@@ -32,9 +32,6 @@
regex_t *p_reg; regex_t *p_reg;
regmatch_t* pmatch; regmatch_t* pmatch;
char* ping = NULL; char* ping = NULL;
int start;
int end;
size_t size_ping;
/* regex struct memory allocation */ /* regex struct memory allocation */
p_reg = (regex_t *) malloc(sizeof(*p_reg)); p_reg = (regex_t *) malloc(sizeof(*p_reg));
@@ -51,9 +48,9 @@
/* Construct regex to get ping from log file */ /* Construct regex to get ping from log file */
if(regcomp(p_reg,"time=(.*) ms",REG_EXTENDED) != 0){ if(regcomp(p_reg,"time=(.*) ms",REG_EXTENDED) != 0){
if(p_reg != NULL){ //if(p_reg != NULL){
free(p_reg); free(p_reg);
} //}
(void) fclose(fd); (void) fclose(fd);
return ping; /* NULL */ return ping; /* NULL */
} }
@@ -67,6 +64,41 @@
return ping; /* NULL */ 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 */ /* Read file */
while(getline(&read_line,&n,fd) != -1){ while(getline(&read_line,&n,fd) != -1){
@@ -84,8 +116,8 @@
size_ping = (size_t) (end - start); size_ping = (size_t) (end - start);
/* ping string memory allocation */ /* ping string memory allocation */
ping = malloc(sizeof(char) * (size_ping+2)); ping2 = malloc(sizeof(char) * (size_ping+2));
if(ping == NULL){ if(ping2 == NULL){
free(read_line); free(read_line);
read_line = NULL; read_line = NULL;
n = 0; n = 0;
@@ -93,9 +125,9 @@
} }
/* Create ping string */ /* Create ping string */
(void) strncpy(ping, &read_line[start], size_ping); (void) strncpy(ping2, &read_line[start], size_ping);
ping[size_ping]='\n'; ping2[size_ping]='\n';
ping[size_ping+1]='\0'; ping2[size_ping+1]='\0';
/* Free memory */ /* Free memory */
free(read_line); free(read_line);
@@ -107,20 +139,8 @@
free(read_line); free(read_line);
read_line = NULL; read_line = NULL;
n = 0; 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;
} }
/* /*