Fini !
This commit is contained in:
		
							
								
								
									
										4
									
								
								Fonction - get_ping_from_temp_log.svg
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								Fonction - get_ping_from_temp_log.svg
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							| 
		 After Width: | Height: | Size: 59 KiB  | 
							
								
								
									
										4
									
								
								Fonction - set_stats_ping.svg
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								Fonction - set_stats_ping.svg
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							| 
		 After Width: | Height: | Size: 48 KiB  | 
							
								
								
									
										4
									
								
								Légende.svg
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								Légende.svg
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							| 
		 After Width: | Height: | Size: 62 KiB  | 
							
								
								
									
										42
									
								
								Notes.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								Notes.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,42 @@
 | 
			
		||||
Auteurs : Aurélien Amary, Adrien Dick
 | 
			
		||||
 | 
			
		||||
# TP2 Conplexité cyclomatique
 | 
			
		||||
*Complexité cyclomatique as CC*
 | 
			
		||||
## Calcul du nombre de chemins pour chaque fonction
 | 
			
		||||
### daemon
 | 
			
		||||
- create_daemon ; CC = 4
 | 
			
		||||
- ping_request ; CC = 2
 | 
			
		||||
- send_check ; CC = 3
 | 
			
		||||
- check_keep_working ; CC = 4
 | 
			
		||||
- daemon_work ; CC = 3
 | 
			
		||||
 | 
			
		||||
### db-sqlite
 | 
			
		||||
- db_connect ; CC = 1
 | 
			
		||||
- db_disconnect ; CC = 1
 | 
			
		||||
- insert_hourly_report ; CC = 1
 | 
			
		||||
 | 
			
		||||
### ping-report
 | 
			
		||||
- main ; CC = 4
 | 
			
		||||
 | 
			
		||||
### stats
 | 
			
		||||
- get_ping_from_temp_log ; CC = 15 (voir graphe)
 | 
			
		||||
- write_ping_log ; CC = 4
 | 
			
		||||
- set_stats_ping ; CC = 25 (voir graphe)
 | 
			
		||||
 | 
			
		||||
### utils
 | 
			
		||||
- write_pid_file ; CC = 2
 | 
			
		||||
- remove_file ; C = 1
 | 
			
		||||
 | 
			
		||||
## Simplification du code
 | 
			
		||||
*Commentaire "Modif" aux endroits modifiés*
 | 
			
		||||
### get_ping_from_temp_lo
 | 
			
		||||
Factorisation du while en une sous fonction : sub_get_ping_from_temp_log \
 | 
			
		||||
Résultat :
 | 
			
		||||
- get_ping_from_temp_log ; CC = 7
 | 
			
		||||
- sub_get_ping_from_temp_log ; CC = 4
 | 
			
		||||
 | 
			
		||||
### set_stats_ping
 | 
			
		||||
Factorisation des trois derniers "if" du while en une sous fonction : sub_set_stats_ping \
 | 
			
		||||
Résultat :
 | 
			
		||||
- set_stats_ping ; CC = 9
 | 
			
		||||
- sub_set_stats_ping ; CC = 8
 | 
			
		||||
@@ -23,7 +23,6 @@
 | 
			
		||||
        Ping value as a string or NULL if an error occured
 | 
			
		||||
*/
 | 
			
		||||
/*@null@*/char* get_ping_from_temp_log(){
 | 
			
		||||
 | 
			
		||||
    /* Variables */
 | 
			
		||||
    FILE* fd = NULL;
 | 
			
		||||
    char* read_line = NULL;
 | 
			
		||||
@@ -67,6 +66,23 @@
 | 
			
		||||
        return ping; /* NULL */
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    sub_get_ping_from_temp_log(&read_line, &n, &fd, ...);  //Modif
 | 
			
		||||
 | 
			
		||||
    /* 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;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void sub_get_ping_from_temp_log(char** read_line, size_t* n, FILE** fd, ...){  //Modif
 | 
			
		||||
    /* Read file */
 | 
			
		||||
    while(getline(&read_line,&n,fd) != -1){
 | 
			
		||||
        
 | 
			
		||||
@@ -108,21 +124,9 @@
 | 
			
		||||
        read_line = NULL;
 | 
			
		||||
        n = 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* 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;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
    -- write_ping_log --
 | 
			
		||||
    Desc :
 | 
			
		||||
@@ -209,22 +213,7 @@ void set_stats_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;
 | 
			
		||||
                    sub_set_stats_ping(&nb_ping, &ping, &max, &min, &nb_high, &sum);  //Modif
 | 
			
		||||
                }
 | 
			
		||||
            } 
 | 
			
		||||
            free(read_line);
 | 
			
		||||
@@ -246,4 +235,21 @@ void set_stats_ping(){
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void sub_set_stats_ping(int* nb_ping, double* ping, double* max, double* min, int* nb_high, double* sum){  //Modif
 | 
			
		||||
    /* Number of ping readed (for mean calculation) */
 | 
			
		||||
    *nb_ping++;
 | 
			
		||||
    /* Max ping */
 | 
			
		||||
    if(*ping > m*ax){
 | 
			
		||||
        *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;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user