void Admin::adminOperations(UserList* userlist) { std::vector<std::string> actions; std::ostringstream oss; oss << "Toggle execution trace - Currently " << (execTrace ? "ON" : "OFF"); actions.push_back(oss.str()); actions.push_back("View the contents of the execution trace"); actions.push_back("Clear the execution trace log"); actions.push_back("Change your password"); int input = 0; while(input != NUM_OPTIONS) { input = IOUtils::getUserAction(&actions); switch(input) { //toggle exec trace case 1: { execTrace = !execTrace; std::cout << "Execution trace is now " << (execTrace ? "ON" : "OFF") << std::endl; break; } //echo the trace file case 2: { std::ifstream tracefile(LOGFILE); std::string line; //output file line-by-line while(getline(tracefile, line)) { std::cout << line << std::endl; } break; } //clear the file case 3: { //empty the contents of the file using ofstream::trunc std::ofstream tracefile(LOGFILE, std::ofstream::out | std::ofstream::trunc); std::cout << "Log file has been cleared." << std::endl; break; } case 4: { if(!IOUtils::getUserResponse("Are you sure you want to change your password?", 'y', 'n')) break; IOUtils::changePassword(ADMIN_NAME, userlist); break; } } } }
void SysTrace::refresh(void) { int pos = ui.textTrace->verticalScrollBar()->value(); QString debugbuffer; QFile tracefile(QDir::tempPath() + "/rbutil-trace.log"); tracefile.open(QIODevice::ReadOnly); QTextStream c(&tracefile); QString line; QString color; while(!c.atEnd()) { line = c.readLine(); if(line.contains("WARNING")) color = "orange"; else if(line.contains("ERROR")) color = "red"; else if(line.contains("DEBUG")) color = "blue"; #if 0 else if(line.contains("INFO")) color = "green"; #endif else color = "black"; debugbuffer += QString("<div style='color:%1;'>%2</div>").arg(color, line); } tracefile.close(); ui.textTrace->setHtml("<pre>" + debugbuffer + "</pre>"); ui.textTrace->verticalScrollBar()->setValue(pos); QString oldlog = RbSettings::value(RbSettings::CachePath).toString() + "/rbutil-trace.log"; ui.buttonSavePrevious->setEnabled(QFileInfo(oldlog).isFile()); }
QString SysTrace::getTrace(void) { QString debugbuffer; QFile tracefile(QDir::tempPath() + "/rbutil-trace.log"); tracefile.open(QIODevice::ReadOnly); QTextStream c(&tracefile); debugbuffer = c.readAll(); tracefile.close(); return debugbuffer; }
void Trace::outputTrace(const char* filename){ ofstream tracefile(filename); if(!tracefile ){ cerr << "error: unable to open trace file: " << filename; return; } Event *iter = head; int seq_num = 0; while(iter){ tracefile << iter->toString(seq_num++) << "\n"; iter = iter->next; } tracefile.close(); }
//writes the system time + s to LOGFILE if execution trace is toggled ON. void Admin::logExecutionTrace(std::string s) { if(!execTrace) return; //get system time time_t rawtime; time(&rawtime); struct tm* now = localtime(&rawtime); char formattedTime[80]; //format the time into a string strftime(formattedTime, 80, "[%D %R] ", now); //log it, in append mode std::ofstream tracefile(LOGFILE, std::ios_base::app); tracefile << formattedTime << s << std::endl; }
void Tracer::run() { QFile tracefile(QCoreApplication::applicationDirPath() + "/trace.bin"); tracefile.open(QFile::WriteOnly); while(!mStop) { sleep(2); mMutex.lock(); QByteArray* trace = mCurrentTrace; mCurrentTraceId = (mCurrentTraceId+1) % 2; mCurrentTrace = &mTraces[mCurrentTraceId]; mMutex.unlock(); tracefile.write(*trace); tracefile.flush(); int size = trace->capacity(); trace->resize(0); trace->reserve(size); } }
Trace* Trace::inputTrace(const char* filename, int mode, int rank){ string line, eventbuf; ifstream tracefile(filename); if(!tracefile){ cerr << "error: unable to open trace file: " << filename << endl; exit(1); } Trace *trace = new Trace(); int seqnum = 0; while(getline(tracefile, line)){ if(line.size() > 0){ eventbuf += line + "\n"; } else { Event *e = Event::inputEvent(eventbuf, mode, rank); if (e){ e->setId(seqnum++); trace->appendEvent(e, false); } eventbuf.clear(); } } tracefile.close(); return trace; }