Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
1ee3a351b6 | |||
02b728aa6b | |||
c6356a66eb | |||
37384315ff | |||
fd0c17a4f0 | |||
2cdf49fb6f | |||
7949ba7f52 | |||
eeb103dace | |||
17f5d95148 | |||
0ce3f8d77c | |||
4fb2808ce3 |
75
compte_rendu_genique_vallat.md
Normal file
75
compte_rendu_genique_vallat.md
Normal file
@ -0,0 +1,75 @@
|
||||
# COMPTE RENDU
|
||||
|
||||
## Fait par VALLAT Guillaume et GENIQUE Florian
|
||||
|
||||
## Calculer la complexité cyclomatique du code donnée
|
||||
|
||||
### 1. daemon.c :
|
||||
|
||||
* create_daemon() : 4 complexité cyclomatique
|
||||
|
||||
* ping_request() : 2 complexité cyclomatique
|
||||
|
||||
* send_check() : 4 complexité cyclomatique
|
||||
|
||||
* check_keep_working() : 4 complexité cyclomatique
|
||||
|
||||
* daemon_work() : 3 complexité cyclomatique
|
||||
|
||||
### 2. db-sqlite.c :
|
||||
|
||||
* db_connect() : 1 complexité cyclomatique
|
||||
|
||||
* db_disconnect() : 1 complexité cyclomatique
|
||||
|
||||
* insert_hourly_report(): 1 complexité cyclomatique
|
||||
|
||||
### 3. ping-report.c :
|
||||
|
||||
* main() : 4 complexité cyclomatique
|
||||
|
||||
### 4. stats.C :
|
||||
|
||||
* get_ping_from_temp_log() : 13 complexité cyclomatique
|
||||
|
||||
* write_ping_log() : 4 complexité cyclomatiquue
|
||||
|
||||
* set_stats_ping() : 23 complexité cyclomatique
|
||||
|
||||
### 5. utils.c :
|
||||
|
||||
* write_pid_file() : 2 complexité cyclomatique
|
||||
|
||||
* remove_file() : 1 complexité cyclomatique
|
||||
|
||||
|
||||
## DIAGRAMMES
|
||||
|
||||
* fonction : set_stats_ping :
|
||||
|
||||
![diagramme1](/img/diagrammes_stats_c_set_stats_ping.png "fonction set_stats_ping")
|
||||
|
||||
|
||||
## OPTIMISATION DU CODE DE LA FONCTION get_ping_from_temp_log() :
|
||||
|
||||
ligne de 127 à 130 mis en commentaire
|
||||
|
||||
les if :
|
||||
|
||||
- if(p_reg == NULL)
|
||||
- if(fd == NULL)
|
||||
- if(regcomp(p_reg,"time=(.*) ms",REG_EXTENDED) != 0)
|
||||
- if(pmatch == NULL)
|
||||
|
||||
on été décaler dans une fonction a part appelé ifFunct(FILE* fd, regex_t *p_reg, regmatch_t* pmatch) et nous retourne le ping ce qui de la fonction get_ping_from_temp_log 5 de compléxité cyclomatique. Et également 5 de compléxité cyclomatique pour la nouvelle fonction crée.
|
||||
|
||||
## NOUVEAU DIAGRAMMES
|
||||
|
||||
* fonction get_ping_from_temp_log optimisé :
|
||||
|
||||
![diagramme2](/img/diagramme2.png "fonction get_ping_from_temp_log optimisé")
|
||||
|
||||
* fonction ifFunct :
|
||||
|
||||
![diagramme3](/img/diagramme3.png "fonction ifFunct")
|
||||
|
BIN
img/diagramme2.png
Normal file
BIN
img/diagramme2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 39 KiB |
BIN
img/diagramme3.png
Normal file
BIN
img/diagramme3.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 37 KiB |
BIN
img/diagrammes_stats_c_set_stats_ping.png
Normal file
BIN
img/diagrammes_stats_c_set_stats_ping.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 90 KiB |
@ -22,6 +22,32 @@
|
||||
Return value :
|
||||
Ping value as a string or NULL if an error occured
|
||||
*/
|
||||
|
||||
char* ifFunct(FILE* fd, regex_t *p_reg, regmatch_t* pmatch){
|
||||
char* ping = NULL;
|
||||
if(p_reg == NULL){
|
||||
return ping; /* NULL */
|
||||
}
|
||||
if(fd == NULL){
|
||||
free(p_reg);
|
||||
return ping; /* NULL */
|
||||
}
|
||||
if(regcomp(p_reg,"time=(.*) ms",REG_EXTENDED) != 0){
|
||||
//if(p_reg != NULL){
|
||||
free(p_reg);
|
||||
//}
|
||||
(void) fclose(fd);
|
||||
return ping; /* NULL */
|
||||
}
|
||||
if(pmatch == NULL){
|
||||
(void) fclose(fd);
|
||||
regfree(p_reg);
|
||||
free(p_reg);
|
||||
return ping; /* NULL */
|
||||
}
|
||||
return ping;
|
||||
}
|
||||
|
||||
/*@null@*/char* get_ping_from_temp_log(){
|
||||
|
||||
/* Variables */
|
||||
@ -38,34 +64,19 @@
|
||||
|
||||
/* regex struct memory allocation */
|
||||
p_reg = (regex_t *) malloc(sizeof(*p_reg));
|
||||
if(p_reg == NULL){
|
||||
return ping; /* NULL */
|
||||
}
|
||||
|
||||
|
||||
/* Open ping log file */
|
||||
fd = fopen("/var/log/ping-report/last-ping.log","r");
|
||||
if(fd == NULL){
|
||||
free(p_reg);
|
||||
return ping; /* NULL */
|
||||
}
|
||||
|
||||
|
||||
/* Construct regex to get ping from log file */
|
||||
if(regcomp(p_reg,"time=(.*) ms",REG_EXTENDED) != 0){
|
||||
if(p_reg != NULL){
|
||||
free(p_reg);
|
||||
}
|
||||
(void) fclose(fd);
|
||||
return ping; /* NULL */
|
||||
}
|
||||
|
||||
|
||||
/* match info memory allocation */
|
||||
pmatch = malloc(sizeof(*pmatch) * nmatch);
|
||||
if(pmatch == NULL){
|
||||
(void) fclose(fd);
|
||||
regfree(p_reg);
|
||||
free(p_reg);
|
||||
return ping; /* NULL */
|
||||
}
|
||||
|
||||
ping = ifFunct(fd, p_reg, pmatch);
|
||||
|
||||
/* Read file */
|
||||
while(getline(&read_line,&n,fd) != -1){
|
||||
@ -113,9 +124,9 @@
|
||||
regfree(p_reg);
|
||||
free(p_reg);
|
||||
free(pmatch);
|
||||
if(read_line != NULL){
|
||||
free(read_line);
|
||||
}
|
||||
//if(read_line != NULL){
|
||||
// free(read_line);
|
||||
//}
|
||||
|
||||
(void) fclose(fd);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user