void CBProfilerExecDlg::ParseMisc(const wxArrayString& msg, wxProgressDialog &progress, const size_t maxcount, size_t &count) { // parsing wxString output; progress.Update(count, _("Parsing miscellaneous information. Please wait...")); for ( ; count < maxcount; ++count ) { if ((count%10) == 0) progress.Update(count); output << msg[count] << _T("\n"); } outputMiscArea->SetValue(output); }
void MyFrame::OnWorkerEvent(wxThreadEvent& event) { int n = event.GetInt(); if ( n == -1 ) { m_dlgProgress->Destroy(); m_dlgProgress = (wxProgressDialog *)NULL; // the dialog is aborted because the event came from another thread, so // we may need to wake up the main event loop for the dialog to be // really closed wxWakeUpIdle(); } else { if ( !m_dlgProgress->Update(n) ) { wxCriticalSectionLocker lock(m_csCancelled); m_cancelled = true; } } }
void CBProfilerExecDlg::ParseFlatProfile(const wxArrayString& msg, wxProgressDialog &progress, const size_t maxcount, size_t &count) { // Setting colums names outputFlatProfileArea->InsertColumn(0, _T("% time"), wxLIST_FORMAT_CENTRE); outputFlatProfileArea->InsertColumn(1, _T("cum. sec."), wxLIST_FORMAT_CENTRE); outputFlatProfileArea->InsertColumn(2, _T("self sec."), wxLIST_FORMAT_CENTRE); outputFlatProfileArea->InsertColumn(3, _T("calls"), wxLIST_FORMAT_CENTRE); outputFlatProfileArea->InsertColumn(4, _T("self ms/call"), wxLIST_FORMAT_CENTRE); outputFlatProfileArea->InsertColumn(5, _T("total ms/call"), wxLIST_FORMAT_CENTRE); outputFlatProfileArea->InsertColumn(6, _T("name")); // Jump header lines progress.Update(count,_("Parsing flat profile information. Please wait...")); while ((count < maxcount)&&(msg[count].Find(_T("time seconds")) == -1)) { ++count; } ++count; // Parsing Call Graph size_t next(0); unsigned int spacePos[6] = {6, 16, 25, 34, 43, 52}; wxString TOKEN; for ( ; count < maxcount; ++count ) { if ((count%10) == 0) progress.Update(count); TOKEN = msg[count]; if ( (TOKEN.IsEmpty()) || (TOKEN.Find(wxChar(0x0C)) != -1) ) break; long item = outputFlatProfileArea->InsertItem(next,_T("")); outputFlatProfileArea->SetItemData(item, next); // check that we have spaces where spaces are supposed to be if (TOKEN.Len() > spacePos[5]) { bool need_parsing = false; for (int i=0; i<6; ++i) { if (TOKEN[spacePos[i]] != ' ') { need_parsing = true; break; } } // if profile output is not in perfect table format // manually parse for space positions if (need_parsing) { int cnt=0; int i=0; int len = TOKEN.Len(); while (i < len && cnt < 6) { // we start with spaces while (TOKEN[i] == ' ' && ++i < len); if (i>=len) break; // now we parse everything else than while (TOKEN[i] != ' ' && ++i < len); if (i>=len) break; // found a new space position spacePos[cnt++] = i; } } } outputFlatProfileArea->SetItem(next, 0, ((TOKEN.Mid(0,spacePos[0])).Trim(true)).Trim(false)); for (int i(1); i<6; ++i) outputFlatProfileArea->SetItem(next, i,((TOKEN.Mid(spacePos[i-1],spacePos[i] - spacePos[i-1])).Trim(true)).Trim(false)); outputFlatProfileArea->SetItem(next, 6, ((TOKEN.Mid(spacePos[5])).Trim(true)).Trim(false)); /* outputFlatProfileArea->SetItem(next, 0, ((TOKEN.Mid(0,6)).Trim(true)).Trim(false)); outputFlatProfileArea->SetItem(next, 1, ((TOKEN.Mid(6,10)).Trim(true)).Trim(false)); outputFlatProfileArea->SetItem(next, 2, ((TOKEN.Mid(16,9)).Trim(true)).Trim(false)); outputFlatProfileArea->SetItem(next, 3, ((TOKEN.Mid(25,9)).Trim(true)).Trim(false)); outputFlatProfileArea->SetItem(next, 4, ((TOKEN.Mid(34,9)).Trim(true)).Trim(false)); outputFlatProfileArea->SetItem(next, 5, ((TOKEN.Mid(43,9)).Trim(true)).Trim(false)); outputFlatProfileArea->SetItem(next, 6, ((TOKEN.Mid(52)).Trim(true)).Trim(false)); */ ++next; } // Resize columns outputFlatProfileArea->SetColumnWidth(0, wxLIST_AUTOSIZE_USEHEADER ); outputFlatProfileArea->SetColumnWidth(1, wxLIST_AUTOSIZE_USEHEADER ); outputFlatProfileArea->SetColumnWidth(2, wxLIST_AUTOSIZE_USEHEADER ); outputFlatProfileArea->SetColumnWidth(3, wxLIST_AUTOSIZE ); outputFlatProfileArea->SetColumnWidth(4, wxLIST_AUTOSIZE_USEHEADER ); outputFlatProfileArea->SetColumnWidth(5, wxLIST_AUTOSIZE_USEHEADER ); outputFlatProfileArea->SetColumnWidth(6, wxLIST_AUTOSIZE); // Printing Flat Profile Help wxString output_help; for ( ; count < maxcount; ++count ) { if ((count%10) == 0) progress.Update(count); TOKEN = msg[count]; if (TOKEN.Find(wxChar(0x0C)) != -1) break; output_help << msg[count] << _T("\n"); } outputHelpFlatProfileArea->SetValue(output_help); ++count; }
void CBProfilerExecDlg::ParseCallGraph(const wxArrayString& msg, wxProgressDialog &progress, const size_t maxcount, size_t& count) { // Setting colums names outputCallGraphArea->InsertColumn(0, _T("index"), wxLIST_FORMAT_CENTRE); outputCallGraphArea->InsertColumn(1, _T("% time"), wxLIST_FORMAT_CENTRE); outputCallGraphArea->InsertColumn(2, _T("self"), wxLIST_FORMAT_CENTRE); outputCallGraphArea->InsertColumn(3, _T("children"), wxLIST_FORMAT_CENTRE); outputCallGraphArea->InsertColumn(4, _T("called"), wxLIST_FORMAT_CENTRE); outputCallGraphArea->InsertColumn(5, _T("name")); // Jump header lines progress.Update(count,_("Parsing call graph information. Please wait...")); while ( (count < maxcount) && (msg[count].Find(_T("index % time")) == -1) ) { if ((count%10) == 0) progress.Update(count); ++count; } ++count; // Parsing Call Graph size_t next(0); wxListItem item; wxString TOKEN; // setting listctrl default text colour for secondary lines const wxColour COLOUR(wxTheColourDatabase->Find(_T("GREY"))); for ( ; count < maxcount; ++count ) { if ((count%10) == 0) progress.Update(count); TOKEN = msg[count]; if ( (TOKEN.IsEmpty()) || (TOKEN.Find(wxChar(0x0C)) != -1) ) break; outputCallGraphArea->InsertItem(count,_T("")); char first_char = TOKEN.GetChar(0); // treating the empty separator lines if (first_char == '-') { outputCallGraphArea->SetItem(next, 0, _T("")); item.Clear(); item.SetId(next); item.SetBackgroundColour(*wxLIGHT_GREY); outputCallGraphArea->SetItem(item); } else { outputCallGraphArea->SetItem(next, 0, TOKEN(0,6).Trim(true).Trim(false)); outputCallGraphArea->SetItem(next, 1, TOKEN(6,6).Trim(true).Trim(false)); outputCallGraphArea->SetItem(next, 2, TOKEN(12,8).Trim(true).Trim(false)); outputCallGraphArea->SetItem(next, 3, TOKEN(20,8).Trim(true).Trim(false)); outputCallGraphArea->SetItem(next, 4, TOKEN(28,17).Trim(true).Trim(false)); outputCallGraphArea->SetItem(next, 5, TOKEN.Mid(45)); if (first_char != '[') { outputCallGraphArea->SetItemTextColour(next,COLOUR); } } ++next; } // Resize columns outputCallGraphArea->SetColumnWidth(0, wxLIST_AUTOSIZE_USEHEADER ); outputCallGraphArea->SetColumnWidth(1, wxLIST_AUTOSIZE_USEHEADER ); outputCallGraphArea->SetColumnWidth(2, wxLIST_AUTOSIZE_USEHEADER ); outputCallGraphArea->SetColumnWidth(3, wxLIST_AUTOSIZE_USEHEADER ); outputCallGraphArea->SetColumnWidth(4, wxLIST_AUTOSIZE ); outputCallGraphArea->SetColumnWidth(5, wxLIST_AUTOSIZE); // Printing Call Graph Help wxString output_help; for ( ; count < maxcount; ++count ) { if ((count%10) == 0) progress.Update(count); TOKEN = msg[count]; if (TOKEN.Find(wxChar(0x0C)) != -1) break; output_help << TOKEN << _T("\n"); } outputHelpCallGraphArea->SetValue(output_help); ++count; }
bool Book::Process( FILE *infile, wxProgressDialog &progress ) { bool aborted = false; char buf[BOOK_BUFLEN+10]; static char comment_buf[10000]; int ch, comment_ch=0, previous_ch=0, push_back=0, len=0, move_number=0; STATE state=INIT, old_state, save_state=INIT; static int nag_value; fseek(infile,0,SEEK_END); unsigned long file_len=ftell(infile); rewind(infile); // Loop through characters ch = fgetc(infile); int old_percent = -1; unsigned char modulo_256=0; while( ch != EOF ) { if( modulo_256 == 0 ) { unsigned long file_offset=ftell(infile); int percent; if( file_len == 0 ) percent = 100; else if( file_len < 10000000 ) percent = (int)( (file_offset*100L) / file_len ); else // if( file_len > 10000000 ) percent = (int)( file_offset / (file_len/100L) ); if( percent != old_percent ) { #if wxABI_VERSION > 28600 if( progress.CanAcceptFocus() ) #endif progress.SetFocus(); if( !progress.Update( percent>100 ? 100 : percent ) ) { aborted = true; break; } } old_percent = percent; } modulo_256++; modulo_256 &= 0xff; if( push_back == '\0' ) { error_buf[error_ptr++] = (char)ch; error_ptr &= (sizeof(error_buf)-1); } push_back = '\0'; debug_buf[debug_ptr].c = (char)ch; debug_buf[debug_ptr].state = state; debug_ptr++; debug_ptr &= (nbrof(debug_buf)-1); // State machine old_state = state; if( ch == '{' && ( state!=HEADER && state!=IN_COMMENT && state!=IN_MOVE_BLACK && state!=IN_MOVE_WHITE ) ) { save_state = state; comment_ch = '{'; state = IN_COMMENT; } else if( ch == ';' && ( state!=HEADER && state!=IN_COMMENT && state!=IN_MOVE_BLACK && state!=IN_MOVE_WHITE ) ) { save_state = state; comment_ch = ';'; state = IN_COMMENT; } else if( state==IN_COMMENT && ( (comment_ch=='{' && ch=='}') || (comment_ch==';' && ch!=';' && previous_ch=='\n') ) ) { if( comment_ch == ';' ) push_back = ch; comment_buf[len] = '\0'; state = save_state; } else if( ch == '$' && ( state!=HEADER && state!=IN_COMMENT && state!=IN_MOVE_BLACK && state!=IN_MOVE_WHITE ) ) { save_state = state; state = IN_DOLLAR; nag_value = 0; } else if( state==IN_DOLLAR && isascii(ch) && isdigit(ch) ) { nag_value = nag_value*10+(ch-'0'); } else if( state==IN_DOLLAR && isascii(ch) && !isdigit(ch) ) { /* const char *nag_array[] = { "", " !", // $1 " ?", // $2 " !!", // $3 " ??", // $4 " !?", // $5 " ?!", // $6 "", // $7 "", // $8 " ??", // $9 " =", // $10 " =", // $11 " =", // $12 "", // $13 " +=", // $14 " =+", // $15 " +/-", // $16 " -/+", // $17 " +-", // $18 " -+", // $19 " +-", // $20 " -+" // $21 }; */ push_back = ch; state = save_state; } else if( ch == '(' && ( state!=HEADER && state!=IN_COMMENT && state!=ERROR_STATE && state!=IN_MOVE_BLACK && state!=IN_MOVE_WHITE ) ) state = Push(state); else if( ch == ')' && ( state!=HEADER && state!=IN_COMMENT && state!=ERROR_STATE && state!=IN_MOVE_BLACK && state!=IN_MOVE_WHITE ) ) { state = Pop(); } else { switch( state ) { case IN_COMMENT: { if( len < sizeof(comment_buf)-3 ) { if( comment_ch == '{' ) comment_buf[len++] = (char)ch; else { if( ch!=';' || previous_ch!='\n' ) comment_buf[len++] = (char)ch; } } break; } case INIT: { push_back = ch; state = PREFIX; break; } case PREFIX: { if( ch == '[' ) { state = HEADER; push_back = ch; } else if( isascii(ch) && isdigit(ch) ) { push_back = ch; state = MOVE_NUMBER; } else if( ch == '*' ) { push_back = ch; state = MOVE_NUMBER; } break; } case HEADER: { if( len < BOOK_BUFLEN ) buf[len++] = (char)ch; if( ch == ']' ) state = PREFIX; break; } case MOVE_NUMBER: { if( ch=='.' || ch==' ' || ch=='\t' || ch=='\n' ) { buf[len] = '\0'; len = 0; if( TestResult(buf) ) state = PREFIX; else if( (move_number=atoi(buf)) > 0 ) { state = POST_MOVE_NUMBER; if( ch == '.' ) push_back = ch; } else { Error( "Bad move number" ); state = ERROR_STATE; } } else { if( len < BOOK_BUFLEN ) buf[len++] = (char)ch; else { Error( "Internal buffer overflow" ); state = ERROR_STATE; } } break; } case POST_MOVE_NUMBER: { if( ch == '.' ) state = POST_MOVE_NUMBER_HAVE_PERIOD; else if( ch!=' ' && ch!='\t' && ch!='\n' ) { Error( "Bad move number" ); state = ERROR_STATE; } break; } case POST_MOVE_NUMBER_HAVE_PERIOD: { if( ch == '.' ) state = POST_MOVE_NUMBER_BLACK; else { push_back = ch; state = PRE_MOVE_WHITE; } break; } case POST_MOVE_NUMBER_BLACK: { if( ch != '.' ) { push_back = ch; state = PRE_MOVE_BLACK; } break; } case ERROR_STATE: { if( ch == '[' ) { push_back = ch; state = PREFIX; } break; } case PRE_MOVE_WHITE: case PRE_MOVE_BLACK: { if( ch == '[' ) { push_back = ch; state = PREFIX; } else if( isascii(ch) && isdigit(ch) ) { push_back = ch; state = MOVE_NUMBER; } else if( ch!=' ' && ch!='\t' && ch!='\n' ) { push_back = ch; state = (state==PRE_MOVE_WHITE?IN_MOVE_WHITE:IN_MOVE_BLACK); } break; } case IN_MOVE_WHITE: case IN_MOVE_BLACK: { if( ch == '[' ) { push_back = ch; state = PREFIX; } else if( ch==' ' || ch=='\t' || ch=='\n' || ch=='(' || ch==')' || ch=='{' || ch=='}' || ch=='$' ) { buf[len] = '\0'; len = 0; if( TestResult(buf) ) state = PREFIX; else if( !DoMove(state==IN_MOVE_WHITE,move_number,buf) ) state = ERROR_STATE; else state = (state==IN_MOVE_WHITE?PRE_MOVE_BLACK:BETWEEN_MOVES); if( ch=='(' || ch==')' || ch=='{' || ch=='}' || ch=='?' ) push_back = ch; } else { if( len < BOOK_BUFLEN ) buf[len++] = (char)ch; else { Error( "Internal buffer overflow" ); state = ERROR_STATE; } } break; } case BETWEEN_MOVES: { if( ch == '[' ) { push_back = ch; state = PREFIX; } else if( isascii(ch) && isdigit(ch) ) { push_back = ch; state = MOVE_NUMBER; } break; } } } // State changes if( state != old_state ) { //fprintf( debug_log_file(), "State change %s->%s\n", ShowState(old_state), ShowState(state) ); if( old_state == HEADER ) { buf[len++] = '\0'; Header( buf ); } if( state==HEADER || state==IN_COMMENT || state==MOVE_NUMBER || state==IN_MOVE_WHITE || state==IN_MOVE_BLACK ) len=0; if( state==PREFIX && ( //old_state==IN_COMMENT || old_state==BETWEEN_MOVES || old_state==MOVE_NUMBER || old_state==POST_MOVE_NUMBER || old_state==POST_MOVE_NUMBER_HAVE_PERIOD || old_state==POST_MOVE_NUMBER_BLACK || old_state==PRE_MOVE_WHITE || old_state==PRE_MOVE_BLACK || old_state==IN_MOVE_WHITE || old_state==IN_MOVE_BLACK ) ) { GameOver(); } if( state==PREFIX && old_state!=HEADER && old_state!=IN_COMMENT ) { GameBegin(); } } // Next character previous_ch = ch; if( push_back ) ch = push_back; else { ch = fgetc(infile); if( ch==EOF && ( state==MOVE_NUMBER || state==POST_MOVE_NUMBER || state==POST_MOVE_NUMBER_HAVE_PERIOD || state==POST_MOVE_NUMBER_BLACK || state==PRE_MOVE_WHITE || state==PRE_MOVE_BLACK || state==BETWEEN_MOVES ) ) GameOver(); } } FileOver(); return aborted; }