void ttyout(unsigned char c) { switch(mode) { /* Print mode */ case 5: if(c==6) break; pp(c); return; /* No prefix characters */ case 0: switch(c) { case 6: mode=5; return; /* Pass-thru printing */ case 7: bell(); break; case 8: dowrap=0; bs(); break; case 9: tab(); break; case 10: case 11: case 12: dowrap=0; if(mnl) cr(); lf(); break; case 13: dowrap=0; cr(); break; case 27: mode=1; return; case 0x84: dowrap=0; lf(); break; case 0x85: dowrap=0; cr(); lf(); break; case 0x88: settab(); break; case 0x8d: dowrap=0; ups(); break; case 0x9b: begin(); mode=2; return; default: if(minsert) insc(c); else type(c); } break; /* ESC has been received */ case 1: switch(c) { case 27: return; case '[': begin(); mode=2; return; case 'D': dowrap=0; lf(); break; case 'E': dowrap=0; cr(); lf(); break; case 'H': settab(); break; case 'M': dowrap=0; ups(); break; case '#': mode=3; return; } break; /* ESC [ or 0x9B has been received */ case 2: /* Enter numbers */ switch(c) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': parry[nptr]=parry[nptr]*10+c-'0'; return; case ';': if(MAXPARMS== ++nptr) break; else return; case 27: mode=1; return; case '[': begin(); return; case 'c': ttyinit(); break; case 'p': dowrap=0; break; /* Reset what? */ case 'r': dowrap=0; setregn(); break; case 'm': setattrib(); break; case 'J': clrs(); break; case 'K': clrl(); break; case 'X': clrc(); break; case 'H': dowrap=0; pos(); break; case 'C': dowrap=0; right(); break; case 'D': dowrap=0; left(); break; case 'A': dowrap=0; up(); break; case 'B': dowrap=0; down(); break; case 'g': clrt(); break; case 'M': dell(); break; case 'L': insl(); break; case 'P': delc(); break; case '@': inss(); break; case 'h': hmode(); break; case 'l': lmode(); break; case '!': case '?': return; } break; /* ESC # has been received */ case 3: switch(c) { case 27: mode=1; return; case '[': begin(); mode=2; return; } break; } mode=0; }
IReport* Registry::DumpDataJSON() { ProfileThreadsVec allThreads; { std::lock_guard<std::mutex> lock(m_ThreadsMutex); allThreads = m_ProfiledThreads; } std::function<void (indent, const unsigned long long, ProfileScope*, unsigned&, opstringstream&)> dumpScope = [&] (indent in, const unsigned long long totalTime, ProfileScope* scope, unsigned& row_id, opstringstream& output) { const auto count = scope->GetCallCount(); if(!count) return; indent_scope insc(in); output << in << "\"id\": " << row_id++ << "," << std::endl; output << in << "\"name\": \"" << scope->GetName() << "\", " << std::endl; HashMap childrenCopy = scope->Children(); unsigned long long childrenTimes = 0; if(childrenCopy.size()) { output << in << "\"children\": [ " << std::endl; { indent_scope insc(in); for(auto scopeIt = childrenCopy.begin(); scopeIt != childrenCopy.end();) { childrenTimes += (*scopeIt)->GetTime(); output << in << "{" << std::endl; dumpScope(in, totalTime, *scopeIt, row_id, output); output << in << "}" << (++scopeIt != childrenCopy.end() ? "," : "") << std::endl; } } output << in << "]," << std::endl; } const auto time = scope->GetTime(); const auto excl_time = time - childrenTimes; output << in << "\"excl_time\": " << excl_time << "," << std::endl; output << in << "\"excl_time_perc\": " << (excl_time / double(totalTime)) * 100.0 << "," << std::endl; output << in << "\"time\": " << time /* not sync */ << "," << std::endl; output << in << "\"time_perc\": " << (time / double(totalTime)) * 100.0 /* not sync */ << "," << std::endl; output << in << "\"call_count\": " << count /* not sync */ << "," << std::endl; output << in << "\"avg_call_incl\": " << time / (double)count << "," << std::endl; output << in << "\"avg_call_excl\": " << excl_time / (double)count << std::endl; }; unsigned threadId = 0; opstringstream ostream; indent in; unsigned row_id = 0; ostream << "[" << std::endl; indent_scope insc(in); unsigned long long totalTime = 0; for(auto threadIt = allThreads.cbegin(); threadIt != allThreads.cend();) { ostream << in << "{" << std::endl; totalTime = (*threadIt)->GetTime(); dumpScope(in, totalTime, *threadIt, row_id, ostream); ostream << in << "}" << (++threadIt != allThreads.cend() ? "," : "") << std::endl; } ostream << "]" << std::endl; std::unique_ptr<JSONReport, profi_deleter<JSONReport>> report(profi_new(JSONReport)); report->GetString() = ostream.str(); return report.release(); }