?? xrun.c
字號:
/*--caller tree op----------------------------------------*/ /*--------------------------------------- fun_name:LevelTraverse author: date: 2009-03-16 23:33 purpose: traverse the noder as the level order in: Caller * out: none return: Status: Okay or Do nothing. history: On the 20090316, Creat it! -----------------------------------------*/ Status LevelTraverse(Caller *tree) { Caller *th = tree; Caller *to= NULL; if(th == NULL) return DONT; printf("--------------------------------------------------------------------\n"); while(th != NULL) { //printf("%s ==>", searchnameasid(th->id)); printf("%d --", th->id); to = th->next; while((th != NULL)&&(to != NULL)) { //printf("%s -->", searchnameasid(to->id)); printf("%d --", to->id); if((th->rear != NULL)&&(to->head != NULL)) { th->rear->next = to->head; to->head->front= th->rear; } th = to; to = to->next; } while(th->head != NULL) { if(th->head->front == NULL) break; th = th->front; } printf("\n"); th = th->head; } printf("\n--------------------------------------------------------------------\n"); return (OKAY); } /*--------------------------------------- fun_name:KillCallerTree author: date: 2009-03-16 23:33 purpose: free the memory as: one by one node . in: out: return: history: On the 20090316, Creat it! -----------------------------------------*/ Status KillCallerTree(Caller * tree) { Caller * tr = tree; Caller * tf = NULL; if(tr == NULL) return DONT; while(tr != NULL) { if((tr->id == 0)||(tr->depth == 0)) { break; } while(tr->rear != NULL) { tr = tr->rear; } if(tr->front != NULL) { tf = tr->front; } else { tf = tr->father; } tr->father = NULL; tr->head = NULL; tr->rear = NULL; tr->front = NULL; tr->next = NULL; free(tr); tr = tf; } return (OKAY); } /*--------------------------------------- fun_name: AccessCaller author: date: 20090317 00:14 purpose: when traverse one tree ,it can accesse the node's information. in: one node with the type is Caller out: none return: Status : okay or do nothing ! history: On 20090317, Creat it! On 20090319, modify it!-----------------------------------------*/ Status AccessCaller(Caller *cp) { char yinyin[256]; char *liy = yinyin; unsigned int lov; Caller *cpp = NULL; if(cp == NULL) return DONT; memset(liy, 0x20, sizeof(char)*256); liy[256-1] = 0x00; #if RELEASE printf("%s", searchnameasid(cp->id)); #else printf("%d", cp->id); #endif if(cp->head != NULL) /* ask his first child */ { printf("\n "); lov = (cp->depth + 1)*2; if((lov < 255)&&(lov>0)) { liy += lov; *(liy - 2) = '-'; *(liy - 1) = '>'; *(liy - 0) = 0x00; printf("%s", yinyin); } else { *liy = 0x00; } } else if(cp->next != NULL) /* ask his first buddy*/ { printf("\n "); lov = (cp->depth -1)*2; if(lov < 255) { liy += lov; *liy = '.'; liy++; *liy = '<'; *(liy+1) = '-'; *(liy+2) = '\n'; *(liy+3) = 0x20; *(liy+4) = 0x00; printf("%s", yinyin); lov = 0; memset(yinyin, 0x20, sizeof(char)*256); liy = yinyin; } else { *liy = 0x00; printf("Too long ! error !\n"); } /*-------------*/ lov = (cp->depth)*2; if((lov < 255)&&(lov>0)) { liy += lov; *(liy - 2) = '-'; *(liy - 1) = '>'; *(liy - 0) = 0x00; printf("%s", yinyin); } else { *liy = 0x00; } } else /* RETURN HIS parents */ { cpp = cp; while(cpp != NULL) { if(cpp->father == NULL) break; printf("\n "); lov = (cpp->father->depth)*2; if(lov < 255) { liy += lov; *liy = '.'; *(liy+1) = '.'; liy += 2; *liy = '<'; *(liy+1) = '-'; *(liy+2) = 0x00; printf("%s", yinyin); } else { *liy = 0x00; printf("Too long ! error !\n"); } lov = 0; memset(yinyin, 0x20, sizeof(char)*256); liy = yinyin; cpp = cpp->father; if(cpp->next != NULL) { break; } } /*------------------*/ printf("\n "); lov = (cpp->depth)*2; if((lov < 255)&&(lov>0)) { liy += lov; *(liy - 2) = '-'; *(liy - 1) = '>'; *(liy - 0) = 0x00; printf("%s", yinyin); } else { *liy = 0x00; } } return (OKAY);} /*--------------------------------------- fun_name: PreOrderTraverse author: date: 20090311purpose: pre - travel a treein: out: return: history: -----------------------------------------*/ Status PreOrderTraverse(Caller *Tree, Status (*Visit)(Caller *Branch)) { if(Tree) { if(Visit(Tree)) { if(PreOrderTraverse(Tree->head, AccessCaller)) { if(PreOrderTraverse(Tree->next, AccessCaller)) { return OKAY; } } } else { return DONT; } } else { return OKAY; } } /*--------------------------------------- fun_name: EmergeBeautifulTree author: date: purpose: BeautifulTree rise , Must: call it after LevelTraversein: out: return: history: 20090320 liyi write here.-----------------------------------------*/ Status EmergeBeautifulTree(Caller * arc){ Caller *to; Caller *at; to = arc; while(to != NULL) { at = to; while(at != NULL) { printf("%d", at->id); if(at->next != NULL) { at = at->next; } else { while(at != NULL) { if(at->head != NULL) { to = at->head; at = NULL; break; } else { if(at != to) { at = at->front; } else { if(at->front != NULL) { at->front->next = NULL; //cut the line at = at->front->father; } else { at = at->father->front; to = at; } } } } } } printf("\n"); } return (OKAY);}/*--------------------------------------- fun_name: ScanGetLineDeepauthor: date: purpose: in: &order ; &depthout: return: nonehistory: 20090404 write here-----------------------------------------*/ Lineinfo * ScanGetLineDeep(Caller *ot,int *morder, int *mdeep){ int i = 0; int depth = 0; Caller *to; Caller *tc; Caller *tn; Lineinfo *linezero = NULL; Lineinfo *linetmpe = NULL; Lineinfo *linenew = NULL; if(ot == NULL) return (NULL); to = ot; tc = to->head; tn = to->next; while((tc != NULL) || (tn != NULL)) { linenew = (Lineinfo *)malloc(sizeof(Lineinfo)); if(linenew == NULL) return (NULL); linenew->icall = to->id; linenew->lcall.y = to->depth; linenew->lcall.x = i; linenew->lcall.life = to->exeinfo.elapse; if(i == 0) { linezero = linenew; linetmpe = linezero; #if (!RELEASE) printf("i id deep eat\n"); #endif } else { linetmpe->nline = (Lineinfo *)linenew; linetmpe = linenew; } linenew = NULL; depth = (depth >= to->depth)?(depth):(to->depth); #if (!RELEASE) printf("%d %d %d %ld\n", i, to->id, to->depth, to->exeinfo.elapse); #endif i ++; if(to->head != NULL) { to = to->head; tc = to; continue; } else { tc = NULL; } if(to->next != NULL) { to = to->next; tn = to; continue; } else { while(to->father != NULL) { to = to->father; if(to->next != NULL) { i++; to = to->next; tn = to; break; } else { tn = NULL; } } } } *morder = i; *mdeep = depth; return (linezero);}/*-------------------------------------------------------------*/void DeleteLinelist(Lineinfo *listhead){ Lineinfo *irecycle = listhead; Lineinfo *ifree = NULL; if(irecycle == NULL) return; ifree = irecycle; while(irecycle != NULL) { free(ifree); irecycle = irecycle->nline; ifree = irecycle; }}/*--------------------------------------- fun_name: DirectoryOutPutauthor: date: purpose: DirectoryOutPut rise , Must: call it after LevelTraversein: out: return: history: 20090326 liyi write here.-----------------------------------------*/ Status DirectoryOutPut(Caller *toor, const char *pstr){ int i = 0; int maxorder = 0; int maxdeep = 0; int blocksize = 0; int order = 0; int depth = 0; int maxcolumn = 0; Lineinfo *linelist = NULL; Lineinfo *linehead = NULL; char *block = NULL; FILE *ftree = NULL; char fname[LEN_NAME]; char cmd[256]; char cycle[LEN_CYCLE]; char lenstr = 0; char *istr = NULL; char *bstr = NULL; if((toor == NULL) || (pstr == NULL)) return (DONT); memset(fname,0x00, LEN_NAME*sizeof(char)); memset(cmd, 0x00, 256 *sizeof(char)); memset(cycle, 0x00,LEN_CYCLE*sizeof(char)); sprintf(fname, "%s_call_tree.txt", pstr); /* compute maxdepth & every node's order */ linehead = ScanGetLineDeep(toor,&maxorder, &maxdeep); if(linehead == NULL) exit(1); linelist = linehead; #if (!RELEASE) printf(" %d x %d \n", (maxorder+1), (maxdeep+1)*2); #endif /* malloc the mem */ maxcolumn = (maxdeep+1)*2 + LEN_FUNS; blocksize = (maxorder+1)*maxcolumn; block = (char *)malloc(blocksize*sizeof(char)); if(block == NULL) { printf("mem alloc error !"); exit(1); } memset(block, 0x20, blocksize*sizeof(char)); /* write mem */ while((i <= maxorder) ||(linelist != NULL)) { order = linelist->lcall.x; depth = linelist->lcall.y * 2; /* block[order*maxcolumn + depth] = i + 0x30; */ /* Get the fuction name */ istr = block + (order*maxcolumn + depth); bstr = searchnameasid(linelist->icall); lenstr = strlen(bstr); if(lenstr < LEN_FUNS) { strncpy(istr, bstr, lenstr); } else { strncpy(istr, bstr, LEN_FUNS); } if((order > 0) && (depth >0)) { block[order*maxcolumn + depth - 1] = '_'; block[order*maxcolumn + depth - 2] = '-'; } /* insert the cycle value */ istr = block+(order * maxcolumn + maxcolumn - 1 - LEN_CYCLE); sprintf(cycle, "%ld", linelist->lcall.life); lenstr = strlen(cycle); strncpy(istr, cycle, lenstr); istr = NULL; lenstr = 0; block[order * maxcolumn + maxcolumn - 1] = '\n'; block[i * maxcolumn + maxcolumn - 1] = '\n'; i++; linelist = linelist->nline; } /* rm the file */ sprintf(cmd, "rm -f %s", fname); system(cmd); /* new a file -- app_call_tree.txt */ ftree = fopen(fname,"wt"); if(ftree <= 0) exit(1); /*fwrite the file with mem */ fwrite(block, sizeof(char), blocksize, ftree); /*fclose file & free mem*/ fclose(ftree); memset(cmd, 0x00, 256*sizeof(char)); sprintf(cmd, "cat %s", fname); system(cmd); DeleteLinelist(linehead); free(block); return (OKAY);}/*-------------------------------------------------------*/ /*extern interface for other file.c*/int open_wiretap(char *appname){ Status x = DONT; if(appname != NULL) x = wiretapinit(appname); return (x == OKAY)?(1):(0);}void close_wiretap(){ wiretapkill();}void exe_wiretap(unsigned int lastia, unsigned int currentia){ cycle ++; wiretap(&calltree, lastia, currentia);}void babble_wiretap(char *appname){ printf("____________________________________________________________________ \n"); PreOrderTraverse(rootcall, AccessCaller); printf("\n____________________________________________________________________ \n"); DirectoryOutPut(rootcall, appname); printf("____________________________________________________________________ \n"); #if (!RELEASE) //LevelTraverse(rootcall); //printf("\n~~~~~~~~~~~~~~~~~~The Beutiful 0~~~~~~~~~~~~~~~~\n"); //EmergeBeautifulTree(rootcall); //printf("\n~~~~~~~~~~~~~~~~~~The Beutiful 1~~~~~~~~~~~~\n"); //printf("\n"); #endif}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -