forked from menault/TD2_DEV51_Qualite_Algo
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8253ce6fe8 |
BIN
Qualité Algorithmique - Profiling & Complexité cyclomatique.pptx
Normal file
BIN
Qualité Algorithmique - Profiling & Complexité cyclomatique.pptx
Normal file
Binary file not shown.
@@ -1,75 +0,0 @@
|
||||
# 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 :
|
||||
|
||||

|
||||
|
||||
|
||||
## 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é :
|
||||
|
||||

|
||||
|
||||
* fonction ifFunct :
|
||||
|
||||

|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 39 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 37 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 90 KiB |
@@ -22,32 +22,6 @@
|
||||
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 */
|
||||
@@ -64,19 +38,34 @@ char* ifFunct(FILE* fd, regex_t *p_reg, regmatch_t* pmatch){
|
||||
|
||||
/* 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);
|
||||
|
||||
ping = ifFunct(fd, p_reg, pmatch);
|
||||
if(pmatch == NULL){
|
||||
(void) fclose(fd);
|
||||
regfree(p_reg);
|
||||
free(p_reg);
|
||||
return ping; /* NULL */
|
||||
}
|
||||
|
||||
/* Read file */
|
||||
while(getline(&read_line,&n,fd) != -1){
|
||||
@@ -124,9 +113,9 @@ char* ifFunct(FILE* fd, regex_t *p_reg, regmatch_t* pmatch){
|
||||
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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user