/* --- Function: int read_taskconnections(Graph gr, char taskconn[][NR_OF_TASKNODES], int nr_of_nodes) --- */ int read_taskconnections(Graph gr, char taskconn[][NR_OF_TASKNODES], int nr_of_nodes) { int i, j, tmp, retval; struct DfsVertexdata_ dfstmp; DfsVertexdata dfs; for (i = 0; i < nr_of_nodes; ++i) { for (j = 0; j < nr_of_nodes; ++j) { if (taskconn[i][j] != 0) { dfs = (DfsVertexdata)malloc(sizeof(struct DfsVertexdata_)); MALCHK(dfs); dfs->data = (char *)malloc(sizeof(char)); MALCHK(dfs->data); *(char *)dfs->data = 'a'+j; /* Temporary vertex (search) data.. */ tmp = 'a'+i; dfstmp.data = &tmp; if ((retval = GRAPHinsedge(gr, &dfstmp, dfs)) != OK) { dfs_destroy(dfs); return retval; } } } } /* Everything OK */ return OK; }
/* --- Function: int read_tasknodes(Graph gr, char *pnodes, int nr_of_nodes) --- */ int read_tasknodes(Graph gr, char *pnodes, int nr_of_nodes) { int i, retval; DfsVertexdata dfs; for (i = 0; i < nr_of_nodes; ++i) { dfs = (DfsVertexdata)malloc(sizeof(struct DfsVertexdata_)); MALCHK(dfs); dfs->data = (char *)malloc(sizeof(char)); MALCHK(dfs->data); /* Copy data to vertex.. */ *((char *)dfs->data) = *(pnodes+i); /* *pi = *(pnodes+i); */ if ((retval = GRAPHinsvertex(gr, dfs)) != OK) { dfs_destroy(dfs); return retval; } } /* Everything OK */ return OK; }
int main(int argc, char **argv) { int result; int upload_count; int rand_num; int file_index; char file_id[64]; char storage_ip[IP_ADDRESS_SIZE]; int count_sums[FILE_TYPE_COUNT]; int i; struct timeval tv_start; struct timeval tv_end; int time_used; if (argc < 2) { printf("Usage: %s <process_index>\n", argv[0]); return EINVAL; } log_init(); proccess_index = atoi(argv[1]); if (proccess_index < 0 || proccess_index >= PROCESS_COUNT) { printf("Invalid proccess index: %d\n", proccess_index); return EINVAL; } if ((result = load_file_contents()) != 0) { return result; } if ((result=test_init()) != 0) { return result; } if ((result=dfs_init(proccess_index)) != 0) { return result; } if (daemon(1, 1) != 0) { return errno != 0 ? errno : EFAULT; } memset(&storages, 0, sizeof(storages)); upload_count = 0; for (i=0; i<FILE_TYPE_COUNT; i++) { upload_count += files[i].count; count_sums[i] = upload_count; } if (upload_count == 0) { return EINVAL; } memset(file_id, 0, sizeof(file_id)); memset(storage_ip, 0, sizeof(storage_ip)); start_time = time(NULL); srand(SRAND_SEED); result = 0; total_count = 0; success_count = 0; while (total_count < upload_count) { rand_num = (int)(upload_count * ((double)rand() / RAND_MAX)); for (file_index=0; file_index<FILE_TYPE_COUNT; file_index++) { if (rand_num < count_sums[file_index]) { break; } } if (files[file_index].upload_count >= files[file_index].count) { continue; } files[file_index].upload_count++; total_count++; gettimeofday(&tv_start, NULL); *storage_ip = '\0'; result = upload_file(files[file_index].file_buff, files[file_index].bytes, file_id, storage_ip); gettimeofday(&tv_end, NULL); time_used = TIME_SUB_MS(tv_end, tv_start); files[file_index].time_used += time_used; add_to_storage_stat(storage_ip, result, time_used); if (result == 0) //success { success_count++; files[file_index].success_count++; fprintf(fpSuccess, "%d %d %s %s %d\n", (int)tv_end.tv_sec, files[file_index].bytes, file_id, storage_ip, time_used); } else //fail { fprintf(fpFail, "%d %d %d %d\n", (int)tv_end.tv_sec, files[file_index].bytes, result, time_used); fflush(fpFail); } if (total_count % 100 == 0) { if ((result=save_stats_by_overall()) != 0) { break; } if ((result=save_stats_by_file_type()) != 0) { break; } if ((result=save_stats_by_storage_ip()) != 0) { break; } } } save_stats_by_overall(); save_stats_by_file_type(); save_stats_by_storage_ip(); fclose(fpSuccess); fclose(fpFail); dfs_destroy(); printf("proccess %d, time used: %ds\n", proccess_index, (int)(time(NULL) - start_time)); return result; }
int main(int argc, char **argv) { int result; int i; int file_type; char storage_ip[IP_ADDRESS_SIZE]; struct timeval tv_start; struct timeval tv_end; int time_used; if (argc < 2) { printf("Usage: %s <process_index>\n", argv[0]); return EINVAL; } proccess_index = atoi(argv[1]); if (proccess_index < 0 || proccess_index >= PROCESS_COUNT) { printf("Invalid proccess index: %d\n", proccess_index); return EINVAL; } if ((result = load_file_ids()) != 0) { return result; } if ((result=test_init()) != 0) { return result; } if ((result=dfs_init(proccess_index)) != 0) { return result; } if (daemon(1, 1) != 0) { return errno != 0 ? errno : EFAULT; } /* printf("file_count = %d\n", file_count); printf("file_entries[0]=%s\n", file_entries[0].file_id); printf("file_entries[%d]=%s\n", file_count-1, file_entries[file_count-1].file_id); */ memset(&storages, 0, sizeof(storages)); memset(storage_ip, 0, sizeof(storage_ip)); start_time = time(NULL); result = 0; total_count = 0; success_count = 0; for (i=0; i<file_count; i++) { file_type = file_entries[i].file_type; files[file_type].delete_count++; total_count++; gettimeofday(&tv_start, NULL); *storage_ip = '\0'; result = delete_file(file_entries[i].file_id, storage_ip); gettimeofday(&tv_end, NULL); time_used = TIME_SUB_MS(tv_end, tv_start); files[file_type].time_used += time_used; add_to_storage_stat(storage_ip, result, time_used); if (result == 0) //success { success_count++; files[file_type].success_count++; } else //fail { fprintf(fpFail, "%d %d %s %s %d %d\n", (int)tv_end.tv_sec, files[file_type].bytes, file_entries[i].file_id, storage_ip, result, time_used); fflush(fpFail); } if (total_count % 10000 == 0) { if ((result=save_stats_by_overall()) != 0) { break; } if ((result=save_stats_by_file_type()) != 0) { break; } if ((result=save_stats_by_storage_ip()) != 0) { break; } } } save_stats_by_overall(); save_stats_by_file_type(); save_stats_by_storage_ip(); fclose(fpFail); dfs_destroy(); printf("proccess %d, time used: %ds\n", proccess_index, (int)(time(NULL) - start_time)); return result; }
int main(int argc, char **argv) { int result; int file_index; int file_type; int file_size; char *conf_filename; char storage_ip[IP_ADDRESS_SIZE]; struct timeval tv_start; struct timeval tv_end; int time_used; if (argc < 2) { printf("Usage: %s <process_index> [config_filename]\n", argv[0]); return EINVAL; } log_init(); proccess_index = atoi(argv[1]); if (proccess_index < 0 || proccess_index >= PROCESS_COUNT) { printf("Invalid proccess index: %d\n", proccess_index); return EINVAL; } if (argc >= 3) { conf_filename = argv[2]; } else { conf_filename = "/etc/fdfs/client.conf"; } if ((result = load_file_ids()) != 0) { return result; } if ((result=test_init()) != 0) { return result; } if ((result=dfs_init(proccess_index, conf_filename)) != 0) { return result; } #ifndef WIN32 if (daemon(1, 1) != 0) { return errno != 0 ? errno : EFAULT; } #endif /* printf("file_count = %d\n", file_count); printf("file_entries[0]=%s\n", file_entries[0].file_id); printf("file_entries[%d]=%s\n", file_count-1, file_entries[file_count-1].file_id); */ memset(&storages, 0, sizeof(storages)); memset(storage_ip, 0, sizeof(storage_ip)); start_time = time(NULL); srand(SRAND_SEED); result = 0; total_count = 0; success_count = 0; while (time(NULL) - start_time < TOTAL_SECONDS) { file_index = (int)(file_count * ((double)rand() / RAND_MAX)); if (file_index >= file_count) { printf("file_index=%d!!!!\n", file_index); continue; } file_type = file_entries[file_index].file_type; files[file_type].download_count++; total_count++; gettimeofday(&tv_start, NULL); *storage_ip = '\0'; result = download_file(file_entries[file_index].file_id, &file_size, storage_ip); gettimeofday(&tv_end, NULL); time_used = TIME_SUB_MS(tv_end, tv_start); files[file_type].time_used += time_used; add_to_storage_stat(storage_ip, result, time_used); if (result == 0) //success { if (file_size != files[file_type].bytes) { result = EINVAL; } } if (result == 0) //success { success_count++; files[file_type].success_count++; } else //fail { fprintf(fpFail, "%d %d %s %s %d %d\n", (int)tv_end.tv_sec, files[file_type].bytes, file_entries[file_index].file_id, storage_ip, result, time_used); fflush(fpFail); } if (total_count % 10000 == 0) { if ((result=save_stats_by_overall()) != 0) { break; } if ((result=save_stats_by_file_type()) != 0) { break; } if ((result=save_stats_by_storage_ip()) != 0) { break; } } } save_stats_by_overall(); save_stats_by_file_type(); save_stats_by_storage_ip(); fclose(fpFail); dfs_destroy(); printf("proccess %d, time used: %ds\n", proccess_index, (int)(time(NULL) - start_time)); return result; }