int main (int argc, char *argv[]) { // Déclare un timer, ainsi que deux recorder qui vont contenir les résultats de l'exécution du programme timer *t = timer_alloc(); recorder *bash_rec = recorder_alloc("shell-bash.csv"); recorder *prog_rec = recorder_alloc("shell-prog.csv"); // Nom du programme C et du script à comparer char * progr = "./shell-program "; char * bash = "./shell-bash.sh "; // Cette variable contient la transformation du nombre d'instruction (i). // Puisque cette variable est un int, 7 caractères suffisent à sa représentation. char nbr[7]; int i; // Allocation des emplacements contenant la commande à exécuter char*argProgr = (char *) malloc(24*sizeof(char)); char*argBash = (char *) malloc(24*sizeof(char)); if(argProgr == NULL || argBash == NULL) exit(EXIT_FAILURE); for(i=1; i<MAX_SIZE; i+=1) { // Convertit "i" en char* et le place dans nbr snprintf(nbr, 7, "%d", i); // Concatene les deux parties de la commande strncpy(argProgr, progr, 24); strncpy(argBash, bash, 24); strncat(argProgr, nbr, 7); strncat(argBash, nbr, 7); // Commence le timer et lance la commande, puis écrit le résultat dans le record approprié start_timer(t); system(argProgr); write_record(prog_rec, i, stop_timer(t)); start_timer(t); system(argBash); write_record(bash_rec, i, stop_timer(t)); } // Libère la mémoire recorder_free(bash_rec); recorder_free(prog_rec); timer_free(t); return EXIT_SUCCESS; }
int main (int argc, char *argv[]) { timer *t = timer_alloc(); recorder *parent_rec = recorder_alloc("parent.csv"); recorder *child_rec = recorder_alloc("child.csv"); pid_t pid; int status, i; for (i = 0; i < N; i++) { start_timer(t); pid = fork(); if (pid == -1) { // erreur à l'exécution de fork perror("fork"); return EXIT_FAILURE; } // pas d'erreur // BEGIN if (pid == 0) { // processus fils write_record(child_rec, i, stop_timer(t)); recorder_free(child_rec); recorder_free(parent_rec); timer_free(t); return EXIT_SUCCESS; } else { // processus père write_record(parent_rec, i, stop_timer(t)); pid = waitpid(pid, &status, 0); if (pid == -1) { perror("wait"); return EXIT_FAILURE; } } // END } recorder_free(child_rec); recorder_free(parent_rec); timer_free(t); return EXIT_SUCCESS; }
int main (int argc, char *argv[]) { timer *t = timer_alloc(); recorder *int_rec = recorder_alloc("int.csv"); recorder *long_rec = recorder_alloc("long.csv"); recorder *float_rec = recorder_alloc("float.csv"); // on init tous les `recorders` et le timer primeInt(N,t,int_rec); primeLong(N,t,long_rec); primeFloat(N,t,float_rec); // on lance les tests recorder_free(int_rec); recorder_free(long_rec); recorder_free(float_rec); timer_free(t); // on free toutes nos structures return 0; }
int main (int argc, char *argv[]) { int err; timer *t = timer_alloc(); recorder *rw_rec = recorder_alloc("rw.csv"); recorder *mmap_rec = recorder_alloc("mmap.csv"); size_t len = 0; int page_size = getpagesize(); for (len = 0x40; len <= MAX_SIZE; len *= 2) { read_write(t, rw_rec, IN, OUT, FILE_SIZE, len, 0); } for (len = page_size; len <= MAX_SIZE; len *= 2) { mmap_munmap(t, mmap_rec, IN, OUT, FILE_SIZE, len); } recorder_free(rw_rec); recorder_free(mmap_rec); return EXIT_SUCCESS; }
int main (int argc, char *argv[]) { timer *t = timer_alloc(); // brk/sbrk recorder *stack_rec = recorder_alloc("stack.csv"); recorder *heap_rec = recorder_alloc("heap.csv"); benchmark_fun(t, heap_1, heap_rec, SIZE_1); benchmark_fun(t, heap_2, heap_rec, SIZE_2); benchmark_fun(t, heap_3, heap_rec, SIZE_3); benchmark_fun(t, stack_1, stack_rec, SIZE_1); benchmark_fun(t, stack_2, stack_rec, SIZE_2); benchmark_fun(t, stack_3, stack_rec, SIZE_3); printf("%p\n", sbrk(0)); recorder_free(stack_rec); recorder_free(heap_rec); timer_free(t); return EXIT_SUCCESS; }
static BOOL Buffer_Assign(void) { /*buffer for rtsp*/ int server_size,client_size; char *server_mem,*client_mem; server_size = get_server_size(); server_mem = (char*)malloc(server_size); if(server_mem == NULL) { printf("not enough memory for rtsp server\n"); return FALSE; } else memset(server_mem,0,server_size); rtsp_server_init(server_mem, server_size); client_size = get_rtspmem_size(3); client_mem = (char*)malloc(client_size); if(client_mem == NULL) { printf("not enough memory for rtsp client\n"); free(server_mem); return FALSE; } else memset(client_mem,0,client_size); rtsp_mem_init(client_mem, client_size); #ifdef RECORDER /*init recorder buf */ if((recoreder_init_buf(g_ConfigParam.eVideoFormat,g_ConfigParam.eAudioFormat)) == 0) { diag_printf("Recorder buffer init ok!\n"); } else { recorder_free(); diag_printf("Recorder buffer init false!\n"); } #endif return TRUE; }
int main (int argc, char *argv[]) { int a = system("./dir_init.sh"); if (a==-1) exit_error("creation des files"); // Déclare un timer, ainsi qu'un recorder qui va contenir les résultats de l'exécution du programme timer * t = timer_alloc(); recorder * read_rec = recorder_alloc("readdir.csv"); int i; DIR * dirp; struct dirent *dp; for(i=0;i<100;i++) { char name[20]; sprintf(name, "file/file%d", i); dirp = opendir(name); if(dirp==NULL) {exit_error("opendir");} start_timer(t); dp=readdir(dirp); write_record(read_rec, i, stop_timer(t)); } int err = closedir(dirp); if(err<<0) {exit_error("closedir");} recorder_free(read_rec); timer_free(t); return EXIT_SUCCESS; }
int main (int argc, char* argv[]) { timer *t = timer_alloc(); recorder *thread_rec = recorder_alloc("thread.csv"); recorder *proc_rec = recorder_alloc("proc.csv"); // on init tous les `recorders` et le timer srand (1337); int* array = (int*)malloc(sizeof(int)*NLENGTH); if (array == NULL) err(1,"erreur malloc"); int i; for (i=0; i<NLENGTH; i++) { array[i] = rand() % NLENGTH; } // on génère le tableau de int aléatoires /* * _______ _ _ * |__ __| | | | * | | | |__ _ __ ___ __ _ __| |___ * | | | '_ \| '__/ _ \/ _` |/ _` / __| * | | | | | | | | __/ (_| | (_| \__ \ * |_| |_| |_|_| \___|\__,_|\__,_|___/ */ for (i = 1; i<=NTHREAD; i=i+1) { start_timer(t); // on lance le chronomètre int error = 0; pthread_t* threads = (pthread_t*)malloc(sizeof(pthread_t)*i); if (threads == NULL) err(1,"erreur malloc"); scanargs** args = (scanargs**)malloc(sizeof(scanargs*)*i); if (args == NULL) err(1,"erreur malloc"); result* res[i]; // init des tableaux d'arguments, de threads, et de resultats int j; for (j=0; j<i; j++) { args[j] = (scanargs*)malloc(sizeof(scanargs)); if (args[j] == NULL) err(1,"erreur malloc"); args[j]->start = j*(NLENGTH/i); args[j]->stop = (j+1)*(NLENGTH/i)-1; args[j]->array = array; // remplissage de la structure argument avec le segment à scanner par le thread error = pthread_create(&threads[j],NULL,&scan,(void*)args[j]); if(error!=0) err(error,"erreur create"); // lancement du thread } for (j=0; j<i; j++) { error=pthread_join(threads[j],(void**)&res[j]); if(error!=0) err(error,"erreur create"); // join du thread et réception de la structure resultat } /* * Analyse des resultats de tous les threads */ int index = -1; int max = 0; for (j=0; j<i; j++) { if (max<res[j]->count) { max = res[j]->count; index = res[j]->index; free(res[j]); free(args[j]); } } printf("%d\n",index); write_record_n(thread_rec,i,stop_timer(t),NTHREAD); //sauvegarde du temps free(threads); free(args); } puts("proc"); /* * _____ * | __ \ * | |__) | __ ___ ___ ___ ___ ___ ___ ___ * | ___/ '__/ _ \ / __/ _ \/ __/ __|/ _ \/ __| * | | | | | (_) | (_| __/\__ \__ \ __/\__ \ * |_| |_| \___/ \___\___||___/___/\___||___/ * * * Meme chose que les threads mais avec des processus cette fois ci */ for (i = 1; i<=NTHREAD; i=i+1) { start_timer(t); int error = 0; pid_t pid[i]; int fd[i][2]; int j; for (j=0; j<i; j++) { int start = j*(NLENGTH/i); int stop = (j+1)*(NLENGTH/i)-1; // on définit le segment à scanner pipe(fd[j]); // on init le pipe entre le père et fils. Il sert à ce que le fils renvoie sa réponse au père pid[j] = fork(); if (pid[j] == 0) { // on est dans le fils int k,p,index,count=0; for (k = start; k<=stop; k++) { p = primeFactors(array[k]); //printf("number: %d ; primes: %d ; index: %d\n", args->array[i],p,i); if (p>count) { count = p; index = k; } } //printf("index: %d count: %d\n",index,count); index = index*1000; index += count; // vu qu'on a 2 int à renvoyer, on les combine en 1 int à déchiffre par le père //printf("index: %d\n",index); close(fd[j][0]); write(fd[j][1], &index, sizeof(index)); // envoie de la réponse par pipe close(fd[j][1]); exit(0); } else if (pid[j] < 0) { err(-1,"erreur de fork"); } } int max = 0,index,ret; for (j=0; j<i; j++) { close(fd[j][1]); read(fd[j][0], &ret, sizeof(ret)); //réception de la réponse des fils close(fd[j][0]); pid[j] = waitpid(pid[j],NULL,0); if(pid[j]<1)err(-1,"erreur waitpid"); //printf("ret: %d\n",ret); //analyse des résultats if (max < ret%1000) { max = ret%1000; index = ret/1000; } } printf("%d\n",index); /* *int it = i; *int numCPU = sysconf( _SC_NPROCESSORS_ONLN ); *if (it > numCPU ) it = numCPU; */ write_record_n(proc_rec,i,stop_timer(t),NTHREAD); // ecriture du temps } recorder_free(thread_rec); recorder_free(proc_rec); timer_free(t); free(array); // free de nos structures }
void WebCameraSIGTERM(int iSignal) { #if 0 #ifdef USE_DDNS cyg_thread_info SelectInfo; #endif #ifdef USE_FLASH cyg_thread_info FlaseInfo; #endif cyg_thread_info CameraInfo; MSG_T msg; msg.lMsg = MSG_QUIT; //MctestThread_release(); //diag_printf("Delete Mctest Server!\n"); if (ptdCamera_handle != NULL) { SendCameraMsg(MSG_QUIT, 0); thread_join(&ptdCamera_handle,&g_ptdCamera,&CameraInfo); diag_printf("Close the Camera Thread!!!"); } if (g_pMsgCamera != NULL) { FreeMsgQueue(g_pMsgCamera); diag_printf("Delete msg queue (main & camera), Ok!\n"); } #ifdef RECORDER recorder_releative_thread_release(); recorder_free(); diag_printf("Delete Recorder!\n"); #endif #ifdef USE_DDNS if (g_pMsgSelect != NULL) SendMsg(g_pMsgSelect, &msg); if (ptdSelect_handle != NULL) { thread_join(&ptdSelect_handle,&g_ptdSelect,&SelectInfo); } if (g_pMsgSelect != NULL) { FreeMsgQueue(g_pMsgSelect); g_pMsgSelect = NULL; diag_printf("Delete msg queue (select), Ok!\n"); } #endif #ifdef USE_FLASH if (g_pMsgFlash != NULL) SendMsg(g_pMsgFlash, &msg); if (ptdFlash_handle != NULL) { thread_join(&ptdFlash_handle,&g_ptdFlash,&FlaseInfo); } if (g_pMsgFlash != NULL) { FreeMsgQueue(g_pMsgFlash); g_pMsgFlash = NULL; diag_printf("Delete msg queue (flash), Ok!\n"); } #endif #endif }
int main (int argc, char *argv[]) { // Regarde les arguments int perfbft = argc>1 && strncmp(argv[1], "--before", 9); int perfaft = argc>1 &&strncmp(argv[1], "--after", 8); if((!perfbft) && !perfaft) { // Déclare un timer, ainsi que deux recorder qui vont contenir les résultats de l'exécution du programme t = timer_alloc(); bftfork_rec = recorder_alloc("memfor-beforefork.csv"); aftfork_rec = recorder_alloc("memfor-aftfork.csv"); aftmodif_rec = recorder_alloc("memfor-aftmodif.csv"); } pid_t pid; int status, i, j; long int resultbft, resultaft; for (i = MULTIPLICATEUR; i < N; i+=MULTIPLICATEUR) { if(perfaft || perfbft) i = N; char ** tab = malloc(i*sizeof(char*)); if(tab == NULL) { perror("malloc fail"); exit(EXIT_FAILURE); } for(j=0; j<i; j++) tab[j] = malloc(i*sizeof(char)); // On le parcours une fois avant le fork pour avoir une mesure de référence if( !perfbft && !perfaft) write_record(bftfork_rec, i/MULTIPLICATEUR, parcoursTab(t, i, tab)); pid = fork(); if (pid == -1) { // erreur à l'exécution de fork perror("fork"); return EXIT_FAILURE; } if (pid == 0) { // processus fils sleep(1); // On le parcours lors du copy-on-write if(!perfaft) resultbft = parcoursTab(t, i, tab); sleep(1); // On le parcours apres le copy-on-write if(! perfbft) resultaft = parcoursTab(t, i, tab); if(!perfbft && !perfaft) { write_record(aftfork_rec, i/MULTIPLICATEUR, resultbft); write_record(aftmodif_rec, i/MULTIPLICATEUR, resultaft); } // Libération du tableau et des records si ils sont alloués if(!perfbft && !perfaft) { recorder_free(bftfork_rec); recorder_free(aftfork_rec); recorder_free(aftmodif_rec); timer_free(t); } free(tab); tab=NULL; for(j=0; j<i; j++) { free(tab[j]); tab[j]=NULL; } return EXIT_SUCCESS; } else { // processus père pid = waitpid(pid, &status, 0); if (pid == -1) { perror("wait"); return EXIT_FAILURE; } } } // Libération du tableau et des records si ils sont alloués if(!perfbft && !perfaft) { recorder_free(bftfork_rec); recorder_free(aftfork_rec); recorder_free(aftmodif_rec); timer_free(t); } return EXIT_SUCCESS; }