📄 d2s_util.c
字号:
{ ierr = SLOG_RDEF_AddRecDef( slog, (SLOG_intvltype_t)one->state_id, (SLOG_bebit_t)1, (SLOG_bebit_t)1, (SLOG_N_assocs_t)0, (SLOG_N_args_t)0 ); } else { ierr = SLOG_RDEF_AddRecDef( slog, FORWARD_MSG, (SLOG_bebit_t)1, (SLOG_bebit_t)1, (SLOG_N_assocs_t)0, (SLOG_N_args_t)0 ); if ( ierr != SLOG_SUCCESS ) { fprintf( stderr,__FILE__":%d: SLOG Record Definition initialization failed. \n",__LINE__); DLOG_free_resources(); return D2S_ERROR; } ierr = SLOG_RDEF_AddRecDef( slog, BACKWARD_MSG, (SLOG_bebit_t)1, (SLOG_bebit_t)1, (SLOG_N_assocs_t)0, (SLOG_N_args_t)0 ); } if ( ierr != SLOG_SUCCESS ) { fprintf( stderr,__FILE__":%d: SLOG Record Definition initialization failed. \n", __LINE__); DLOG_free_resources(); return D2S_ERROR; } } pState = pEventStateList; while (pState) { if (SLOG_RDEF_AddRecDef( slog, (SLOG_intvltype_t)pState->state_id, (SLOG_bebit_t)1, (SLOG_bebit_t)1, (SLOG_N_assocs_t)0, (SLOG_N_args_t)0 ) != SLOG_SUCCESS) { fprintf( stderr,__FILE__":%d: SLOG Record Definition initialization failed. \n", __LINE__); DLOG_free_resources(); return D2S_ERROR; } pState = pState->next; } if ( SLOG_RDEF_SetExtraNumOfRecDefs( slog,EXTRA_STATES ) != SLOG_SUCCESS ) { fprintf(stderr, __FILE__":%d: SLOG_RDEF_SetExtraNumOfRecDefs() fails! \n", __LINE__); DLOG_free_resources(); return D2S_ERROR; } return D2S_SUCCESS;}int addEventState(int state, char *color, char *description){ struct state_info *pState; pState = pEventStateList; while (pState) { if (pState->state_id == state) return D2S_SUCCESS; pState = pState->next; } pState = ( struct state_info *) MALLOC( sizeof(struct state_info) ); pState->state_id = state; if (color) strcpy(pState->color, color); else pState->color[0] = '\0'; if (description) strcpy(pState->description, description); else pState->description[0] = '\0'; pState->end_event_num = -1; pState->start_event_num = -1; pState->next = pEventStateList; pEventStateList = pState; return D2S_SUCCESS;}/**** add a new state definition to the end of the state definition list.****/int addState(int stat_id, int strt_id, int end_id, char *colr, char *desc){ struct state_info *temp_ptr; int s_id, e_id; s_id = findState_strtEvnt(strt_id); e_id = findState_endEvnt(end_id); if ((s_id != D2S_ERROR) && (e_id != D2S_ERROR)) { if (s_id == e_id) { replace_state_in_list(strt_id, end_id, colr, desc); return D2S_SUCCESS; } else { fprintf(stderr,__FILE__":%d: event ids defined for state %s already " "exist. Use DLOG_GetNextEvent() to define new event ids.", __LINE__,desc); return D2S_ERROR; } } else if ((s_id != D2S_ERROR) || (e_id != D2S_ERROR)) { fprintf(stderr,__FILE__":%d: event ids defined for state %s already " "exist. Use DLOG_GetNextEvent() to define new event ids.", __LINE__,desc); return D2S_ERROR; } temp_ptr = ( struct state_info *) MALLOC( sizeof(struct state_info) ); if (temp_ptr == NULL) { fprintf(stderr,__FILE__":%d: not enough memory for start event list!\n", __LINE__); DLOG_free_resources(); return D2S_ERROR; } if (stat_id != MSG_STATE) temp_ptr->state_id = get_new_state_id(); else temp_ptr->state_id = MSG_STATE; temp_ptr->start_event_num = strt_id; temp_ptr->end_event_num = end_id; /*temp_ptr->color = (char *)(MALLOC(strlen(colr)+1)); */ /*temp_ptr->description = (char *)(MALLOC(strlen(desc)+1));*/ strncpy(temp_ptr->color, colr, DLOG_COLOR_LENGTH); temp_ptr->color[DLOG_COLOR_LENGTH-1] = '\0'; strncpy(temp_ptr->description, desc, DLOG_DESCRIPTION_LENGTH-1); temp_ptr->description[DLOG_DESCRIPTION_LENGTH-1] = '\0'; temp_ptr->next = NULL; if (first == NULL) { first = temp_ptr; last = temp_ptr; } else { last->next = temp_ptr; last = temp_ptr; } return D2S_SUCCESS;}int replace_state_in_list(int start_id, int end_id, char *colr, char *desc){ struct state_info *one = NULL, *two = NULL; for (one = first; one != NULL; one = two) { two = one->next; if (one->start_event_num == start_id) { one->start_event_num = start_id; one->end_event_num = end_id; strncpy(one->color, colr, DLOG_COLOR_LENGTH-1); one->color[DLOG_COLOR_LENGTH-1] = '\0'; strncpy(one->description, desc, DLOG_DESCRIPTION_LENGTH-1); one->description[DLOG_DESCRIPTION_LENGTH-1] = '\0'; return D2S_SUCCESS; } } return D2S_ERROR;} /**** finds a state id for the given start event id from the state def list.****/int findState_strtEvnt(int strt_id){ struct state_info *p; for (p = first; p != NULL; p = p->next) { if (p->start_event_num == strt_id) return p->state_id; } return D2S_ERROR;}/**** finds a state id for the given end event id from the state def list.****/int findState_endEvnt(int end_id){ struct state_info *p; for (p = first; p != NULL; p = p->next) { if (p->end_event_num == end_id) return p->state_id; } return D2S_ERROR;}/**** frees up memory malloced for state definitions in the list of state defs.****/void DLOG_freeStateInfo(void){ struct state_info *one = NULL, *two = NULL; for (one = first; one != NULL; one = two) { two = one->next; free(one); }}/**** adds a start event to the start event list. the only relevant info needed for slogging are state id, the data from DLOG_RAWEVENT and the start time. the start time is needed to calculate the interval duration when the end event is found. the new element is added to the front of the list - why??? - well, just in case there are nested events(threads) or non-blocking MPI calls. hasnt been tested on those two conditions yet.****/int addToList(int stat_id, int data, int proc_id, double strt_time){ struct list_elemnt *temp_ptr = (struct list_elemnt *)MALLOC(sizeof(struct list_elemnt)); if (temp_ptr == NULL) { fprintf(stderr,__FILE__":%d: not enough memory for start event list!\n", __LINE__); DLOG_free_resources(); return D2S_ERROR; } temp_ptr->state_id = stat_id; temp_ptr->data = data; temp_ptr->process_id = proc_id; temp_ptr->start_time = strt_time; temp_ptr->next = NULL; if (list_first == NULL) { list_first = temp_ptr; list_last = temp_ptr; } else { temp_ptr->next = list_first; list_first = temp_ptr; } return D2S_SUCCESS;}/**** adds a start event to the start event list. the only relevant info needed for slogging are state id, the data from DLOG_RAWEVENT and the start time. the start time is needed to calculate the interval duration when the end event is found. the new element is added to the front of the list - why??? - well, just in case there are nested events(threads) or non-blocking MPI calls. hasnt been tested on those two conditions yet.****/int addToMsgList(int stat_id, int data, int proc_id, int rec_type, double strt_time){ struct list_elemnt *temp_ptr = (struct list_elemnt *)MALLOC(sizeof(struct list_elemnt)); if (temp_ptr == NULL) { fprintf(stderr,__FILE__":%d: not enough memory for message list!\n", __LINE__); DLOG_free_resources(); return D2S_ERROR; } temp_ptr->state_id = stat_id; temp_ptr->data = data; temp_ptr->process_id = proc_id; temp_ptr->rectype = rec_type; temp_ptr->start_time = strt_time; temp_ptr->next = NULL; if (msg_list_first == NULL) { msg_list_first = temp_ptr; msg_list_last = temp_ptr; } else { msg_list_last->next = temp_ptr; msg_list_last = temp_ptr; } return D2S_SUCCESS;}/**** find a start element for the corresponding end event info passed in the arguments from the start event list. that start event is then removed from the list and copied to pResult.****/int remove_element(int stat_id, int data,int procid, struct list_elemnt *pResult){ struct list_elemnt *pElement = NULL, *pNext = NULL, *pTrailer = NULL; for (pElement = list_first, pTrailer = list_first; pElement != NULL; pElement = pNext) { pNext = pElement->next; if ((pElement->state_id != MSG_STATE) && (pElement->state_id == stat_id) && (pElement->process_id == procid)) { pResult->state_id = pElement->state_id; pResult->data = pElement->data; pResult->process_id = pElement->process_id; pResult->start_time = pElement->start_time; pResult->next = NULL; if (pElement == list_first) { if (pElement->next == NULL) { list_first = NULL; list_last = NULL; } else { list_first = pElement->next; } } else { pTrailer->next = pElement->next; if (pElement == list_last) { list_last = pTrailer; } } free(pElement); return D2S_SUCCESS; } if (pElement != list_first) { pTrailer = pTrailer->next; } } return D2S_ERROR;}int remove_msg_elemnt(int stat_id, int data, int procid, int record_type, struct list_elemnt *pResult){ struct list_elemnt *pElement = NULL, *pNext = NULL, *pTrailer = NULL; for(pElement = msg_list_first, pTrailer = msg_list_first; pElement != NULL; pElement = pNext) { pNext = pElement->next; if ((pElement->state_id == MSG_STATE) && (pElement->state_id == stat_id) && (pElement->process_id == data) && (pElement->data == procid) && (pElement->rectype != record_type)) { pResult->state_id = pElement->state_id; pResult->data = pElement->data; pResult->process_id = pElement->process_id; pResult->rectype = pElement->rectype; pResult->start_time = pElement->start_time; pResult->next = NULL; if (pElement == msg_list_first) { if (pElement->next == NULL) { msg_list_first = NULL; msg_list_last = NULL; } else msg_list_first = pElement->next; } else { pTrailer->next = pElement->next; if (pElement == msg_list_last) msg_list_last = pTrailer; } free(pElement); return D2S_SUCCESS; } if (pElement != msg_list_first) { pTrailer = pTrailer->next; } } return D2S_ERROR;}/**** frees memory malloced to the start event list. in theory there shouldnt be any elements left in this list at the end of the second pass but wierd things happen when you dont know how the dlog file got generated.****/void freeList(void){ struct list_elemnt *one = NULL, *two = NULL; for(one = list_first; one != NULL; one = two) { two = one->next; free(one); } list_first = NULL; list_last = NULL;}/**** frees memory malloced to the message event list.****/void freeMsgList(void){ struct list_elemnt *one = NULL, *two = NULL; for(one = msg_list_first; one != NULL; one = two) { two = one->next; free(one); } msg_list_first = NULL; msg_list_last = NULL;}int get_new_state_id(void) { return state_id++;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -