#include #include #include #include #include #include #include #include "../framework/framework.h" #include "gmonview.h" #include "gmonview.m" static bool gmonview_pickfile (SSTRING &path, const char *init) { path.setfrom (init); bool ret = false; DIALOG dia; dia.settype (DIATYPE_POPUP); dia.newf_str ("File path",path); dia.last_noempty(); int nof = 0; while (1){ MENU_STATUS code = dia.edit ("","",help_nil,nof); if (code == MENU_ESCAPE || code == MENU_CANCEL){ break; }else{ ret = true; break; } } return ret; } class GMONVIEW_DOCUMENT: public FRAMEWORK_DOCUMENT { public: SSTRING path; SSTRING function; SSTRING filter; GMONVIEW_DOCUMENT (const char *_path){ path = _path; } GMONVIEW_DOCUMENT (const char *_path, const char *_function){ path = _path; function = _function; } GMONVIEW_DOCUMENT (const char *_path, const char *_function, const char *_filter){ path = _path; function = _function; filter = _filter; } bool same (const FRAMEWORK_DOCUMENT &other){ GMONVIEW_DOCUMENT *o = (GMONVIEW_DOCUMENT*)&other; return o->path == path && o->function == function && o->filter == filter; } }; int main (int argc, char *argv[]) { glocal SSTRING status; glocal PRIVATE_MESSAGE status_update; glocal PRIVATE_MESSAGE showsplash; int ret = (argc, argv,"tlmpwork"); xconf_error(msg); return main (0,NULL); glocal PRIVATE_MESSAGE msg; glocal int argc = argc; glocal char **argv = argv; (MSG_U(T_GMONVIEW,"GMONVIEW 1.0"),glocal.msg); layout_area1(true); //layout_area2(false); ("gmonview",TLMPWORK_VERSION,TLMPWORK_RELEASE); printf (MSG_U(I_ABOUT ,"Experimental gprof viewer\n")); printf ("Jacques Gélinas jack@solucorp.qc.ca\n"); setgpl(); printf ("http://www.solucorp.qc.ca/tlmp\n"); topmenu (MSG_U(M_FILE,"File")); menuentry (1,MSG_U(M_OPEN,"Open")); menuentry (4,MSG_U(M_CLOSE,"Close")); menuentry (99,MSG_U(M_QUIT,"Quit")); endmenu(); topmenu (MSG_U(M_OPTIONS,"Options")); menuentry (901,MSG_U(M_PREFER,"Preferences")); endmenu(); helpmenu(); endmenu(); if (id == 99){ end(); }else if (id == 1){ SSTRING path; if (gmonview_pickfile (path,"")){ newdocument (new GMONVIEW_DOCUMENT(path.get())); } }else if (id == 4){ dialog_sendmessage (focus[0]->docmsgs.close); } newbutton (2,"folder",MSG_U(B_OPEN,"Open"),""); newbutton (3,"search",MSG_U(B_SEARCH,"Search"),""); if (id == 2){ SSTRING path; if (gmonview_pickfile (path,"")){ newdocument (new GMONVIEW_DOCUMENT(path.get())); } } dialog_sendmessage (glocal.showsplash); GMONVIEW_DOCUMENT *doc = (GMONVIEW_DOCUMENT*)info.data; glocal const char *fname = doc->path.get(); glocal const char *function = doc->function.get(); glocal const char *filter = doc->filter.get(); glocal FRAMEWORK_INFO *info = &info; glocal FRAMEWORK_MSGS *msgs = &info.msgs; glocal SSTRINGS funcs; SSTRING tmp_func; tmp_func.setfrom (glocal.function,80); (glocal.fname,tmp_func.get(),help_none); if (glocal.function[0] == '\0'){ newf_head (MSG_U(H_FLAT,"% time\tCumulative\tSelf\tCalls\tMs/call\tTotal\tFunction")); sethdispo ("rrrrrrl"); sortable(); sortpolicy ("nnnnnna"); waitfor(glocal.info->docmsgs.taskbar); }else{ newf_head (MSG_U(H_GRAPH,"Detail\tFunction")); } nobutton(); waitfor(glocal.info->docmsgs.close); waitfor(glocal.info->docmsgs.focus); waitfor(glocal.msgs->mayend); waitfor(glocal.msgs->ending); if (dialog_testmessage(glocal.msgs->mayend)){ glocal.msgs->endok(); }else if (dialog_testmessage(glocal.msgs->ending) || dialog_testmessage(glocal.info->docmsgs.close)){ endedit(); }else if (dialog_testmessage(glocal.info->docmsgs.focus)){ UISTATE state; diajava_lastmousestate (state); if (state.middleb){ endedit(); } }else if (dialog_testmessage(glocal.info->docmsgs.taskbar)){ DIALOG dia; dia.settype (DIATYPE_POPUP); SSTRING str; dia.newf_str (MSG_U(F_SEARCH,"Search"),str); dia.last_noempty(); if (dia.edit ("","",help_nil) == MENU_ACCEPT){ glocal.FRAMEWORK.newdocument(new GMONVIEW_DOCUMENT(glocal.fname ,"",str.get())); } } glocal.funcs.remove_all(); if (glocal.function[0] == '\0'){ (glocal.fname,true); int ret = 0; if (noline > 4){ SSTRING ftime,fcum,fself,fcalls,fms,ftotal; const char *pt = str_copyword (ftime,line); if (!isdigit(ftime.get()[0])){ //fprintf (stderr,"ftime :%s: %d :%s\n",ftime.get(),noline,line); ret = -1; }else{ const char *func = str_skip(line + 54); if (glocal.filter[0] == '\0' || strstr(func,glocal.filter)!=NULL){ pt = str_copyword (fcum,pt); pt = str_copyword (fself,pt); if (!isspace(line[33])){ pt = str_copyword (fcalls,pt); pt = str_copyword (fms,pt); pt = str_copyword (ftotal,pt); } glocal.editrecords.new_menuitemf(ftime.get() ,"%s\t%s\t%s\t%s\t%s\t%-150.150s" ,fcum.get(),fself.get(),fcalls.get() ,fms.get(),ftotal.get(),func); #if 0 printf ("%s\t%s\t%s\t%s\t%s\t%s\t%s\n" ,ftime.get(),fcum.get(),fself.get(),fcalls.get() ,fms.get(),ftotal.get(),func); #endif glocal.funcs.add(func); } } } return ret; }else{ glocal bool graph=false; glocal SSTRINGS lines; glocal bool seen = false; glocal int flen = strlen(glocal.function); (glocal.fname,true); int ret = 0; if (!glocal.graph){ if (strncmp(line,"index % time",12)==0){ glocal.graph = true; } }else if (strncmp(line," This table describes the call tree",30)==0){ ret = -1; }else if (strncmp(line,"-----",5)==0){ if (glocal.seen){ ret = -1; }else{ glocal.lines.remove_all(); } }else{ glocal.lines.add(line); if (line[0] == '['){ const char *pt = str_skip(line + 45); //fprintf (stderr,"cmp :%s: :%s:\n",glocal.function,pt); if(strncmp(pt,glocal.function,glocal.flen)==0 && pt[glocal.flen+1] == '['){ // fprintf (stderr,"seen\n"); glocal.seen = true; } } } return ret; for (int i=0; iget(); const char *func = str_skipword(line+16); func = str_skipword(func); func = str_skipword(func); SSTRING prefix; prefix.setfrom (line,(int)(func-line)); func = str_skip(func); SSTRING suffix; int len = strlen(func); if (len > 100) len = 200; suffix.setfrom (func,len); // fprintf (stderr,":%s: :%s\n",prefix.get(),suffix.get()); new_menuitemf (prefix.get(),"%s",suffix.get()); const char *pt = func+strlen(func)-1; while (pt > func && pt[0] != ' ') pt--; SSTRING tmp; tmp.setfrom (func,(int)(pt-func)); glocal.funcs.add(tmp); } // Avoid small windows... for (int i=0; i<20; i++){ new_menuitem("",""); glocal.funcs.add (""); } } const char *func = glocal.funcs.getitem(no)->get(); if (func[0] != '\0'){ glocal.FRAMEWORK.newdocument(new GMONVIEW_DOCUMENT(glocal.fname ,func)); } (ending); dia.newf_str (NULL,glocal.status,60); dia.set_lastreadonly(); dia.waitfor (glocal.status_update); if (argc > 0){ for (int i=0; i return ret; }