void SpeedTestUsingMinGen1(std::vector<std::string> fileNames, std::ofstream &output) { std::ifstream input; for (size_t fileInd = 0; fileInd < fileNames.size(); ++fileInd) { input.open(fileNames[fileInd].c_str()); FCA::Context context; ReadContext(context, input); input.close(); std::cout << "MinGen1 algorithm and convertion" << " \"" << fileNames[fileInd] << '\"' << std::endl; Timer timer; timer.StartTiming(); std::vector<FCA::ImplicationInd> mingenBasis = FCA::MinGen1(context); timer.StopTiming(); double timeComputingMinGenBasis = timer.GetUserSeconds(); std::cout << "mingen basis complete in " << Time(timeComputingMinGenBasis) << " " << mingenBasis.size() << " mingen basis" << std::endl; timer.StartTiming(); std::vector<FCA::ImplicationInd> implications = FCA::MinimalCover(mingenBasis); timer.StopTiming(); double timeConverting = timer.GetUserSeconds(); output << fileInd + 1 << ". " << Time(timeComputingMinGenBasis + timeConverting) << " " << implications.size() << std::endl; output << "mingen basis size " << mingenBasis.size() << std::endl; std::cout << "converting complete in " << Time(timeConverting) << " " << implications.size() << " implications" << std::endl; } }
void SpeedTestUsingObjIncremental(std::vector<std::string> fileNames, std::ofstream &output) { std::ifstream input; for (size_t fileInd = 0; fileInd < fileNames.size(); ++fileInd) { input.open(fileNames[fileInd].c_str()); FCA::Context context; ReadContext(context, input); input.close(); std::cout << "ObjIncremental" << " \"" << fileNames[fileInd] << '\"'; Timer timer; timer.StartTiming(); std::vector<FCA::ImplicationInd> implications = FCA::ObjIncremental(context); timer.StopTiming(); Time buildingTime = Time(timer.GetUserSeconds()); size_t directBasisSize = implications.size(); std::cout << std::endl << "basis complite, minimizing..." << std::endl; timer.StartTiming(); implications = FCA::MinimizeBasis(implications); timer.StopTiming(); Time minimizationTime = Time(timer.GetUserSeconds()); output << fileInd + 1 << ". " << buildingTime << " - algo" << std::endl << minimizationTime << " - minimization" << std::endl << directBasisSize << " - direct basis size" << std::endl << implications.size() << " - dq basis size" << std::endl; std::cout << " complete in " << Time(timer.GetUserSeconds()) << " " << implications.size() << " implications" << std::endl; } }
void ReadContextAndPrintProperBasis(std::istream &input, std::ofstream &output) { FCA::Context cxt; ReadContext(cxt, input); std::vector<FCA::ImplicationInd> implsInd = FCA::ComputeProperBasis(cxt); std::vector<FCA::Implication> impls = FCA::Convert(implsInd, cxt.getAttributes()); PrintImplications(output, impls); }
void BuildBasisAndCloseSet(std::vector<std::string> fileNames, std::ofstream &output, const double probability, const size_t rep) { output << probability << std::endl << std::endl; std::ifstream input; for (size_t fileInd = 0; fileInd < fileNames.size(); ++fileInd) { input.open(fileNames[fileInd].c_str()); FCA::Context context; ReadContext(context, input); input.close(); std::cout << fileNames[fileInd] << " is on the way" << std::endl; std::vector<FCA::ImplicationInd> implications = FCA::ComputeDGBasis<FCA::LinClosure>(context); FCA::BitSet s = GetRandomBitSet(context.getAttributesCnt(), probability); FCA::BitSet tmp; Timer timer; timer.StartTiming(); for (size_t i = 0; i < rep; ++i) { FCA::Closure::Apply(s, implications, tmp); } timer.StopTiming(); Time timeClosure = Time(timer.GetUserSeconds()); timer.StartTiming(); for (size_t i = 0; i < rep; ++i) { FCA::LinClosure::Apply(s, implications, tmp); } timer.StopTiming(); Time timeLinClosure = Time(timer.GetUserSeconds()); timer.StartTiming(); for (size_t i = 0; i < rep; ++i) { tmp = FCA::LinClosureImproved::Apply(s, implications, tmp); } timer.StopTiming(); Time timeLinClosureImproved = Time(timer.GetUserSeconds()); output << fileInd << std::endl << "Closure " << timeClosure << std::endl << "LinClosure " << timeLinClosure << std::endl << "LinClosureImproved " << timeLinClosureImproved << std::endl << "implications number is " << implications.size() << std::endl << std::endl; } }
void ReadContextAndPrintDGBasisUsingObjIncremental(std::istream &input, std::ofstream &output) { FCA::Context cntx; ReadContext(cntx, input); std::vector<FCA::ImplicationInd> impsBool; std::vector<FCA::Implication> imps; std::cout << "ObjIncremental" << std::endl; impsBool = FCA::ObjIncremental(cntx); imps = FCA::Convert(impsBool, cntx.getAttributes()); PrintImplications(output, imps); }
int main(int argc, char **argv) // ---------------------------------------------------------------------------- // Parse the command line and run the compiler phases // ---------------------------------------------------------------------------- { #if CONFIG_USE_SBRK char *low_water = (char *) sbrk(0); #endif text cmd, end = ""; // Make sure debug function is linked in... debug(NULL); // Initialize basic XL syntax from syntax description file ReadContext("xl.syntax", gContext); // Initialize the C translator XLInitCTrans(); for (cmd = gOptions.Parse(argc, argv); cmd != end; cmd = gOptions.ParseNext()) { XLParser parser (cmd.c_str(), &gContext); XLTree *tree = parser.Parse(); IFTRACE(source) { std::cout << *tree << "\n"; } IFTRACE(parse) { XLTree::outputDebug = true; std::cout << *tree << "\n"; } XL2C(tree); } #if CONFIG_USE_SBRK IFTRACE(timing) fprintf(stderr, "Total memory usage: %ldK\n", long ((char *) malloc(1) - low_water) / 1024); #endif return 0; }
void ReadContextAndPrintDGBasisUsingAttrIncremental(std::istream &input, std::ofstream &output) { FCA::Context cntx; ReadContext(cntx, input); std::vector<FCA::ImplicationInd> impsBool; std::vector<FCA::Implication> imps; /*std::cout << "Ganter" << " " << cfName << std::endl;*/ std::cout << "Attribute incremental" << std::endl; impsBool = FCA::ComputeDGBasisAttrIncremental(cntx); imps = FCA::Convert(impsBool, cntx.getAttributes()); PrintImplications(output, imps); }
void Pdb::AddThread(dword dwThreadId, HANDLE hThread) { if(threads.Find(dwThreadId) >= 0) return; DR_LOG("AddThread"); Thread& f = threads.GetAdd(dwThreadId); // Retrive "base-level" stack-pointer, to have limit for stackwalks: Context c = ReadContext(hThread); #ifdef CPU_64 f.sp = win64 ? c.context64.Rsp : c.context32.Esp; #else f.sp = c.context32.Esp; #endif f.hThread = hThread; LLOG("Adding thread " << dwThreadId << ", Thread SP: " << Hex(f.sp) << ", handle: " << FormatIntHex((dword)(hThread))); }
void ReadContextAndPrintDGBasisUsingProperBasis(std::istream &input, std::ofstream &output) { FCA::Context cntx; ReadContext(cntx, input); std::vector<FCA::ImplicationInd> properBasis; std::vector<FCA::ImplicationInd> impsBool; std::vector<FCA::Implication> imps; std::cout << "Impec algorithm to construct DG basis" << std::endl; properBasis = FCA::ComputeProperBasis(cntx); impsBool = FCA::MinimalCover(properBasis); imps = FCA::Convert(impsBool, cntx.getAttributes()); PrintImplications(output, imps); }
void ReadContextAndPrintDGBasisUsingMinGen1(std::istream &input, std::ofstream &output) { FCA::Context cntx; ReadContext(cntx, input); std::vector<FCA::ImplicationInd> mingen; std::vector<FCA::ImplicationInd> impsBool; std::vector<FCA::Implication> imps; std::cout << "MinGen algorithm to construct DG basis" << std::endl; mingen = FCA::MinGen1(cntx); std::cout << "MinGen size is " << mingen.size() << std::endl; impsBool = FCA::MinimalCover(mingen); imps = FCA::Convert(impsBool, cntx.getAttributes()); PrintImplications(output, imps); }
void SpeedTestUsingAttrIncremental(std::vector<std::string> fileNames, std::ofstream &output) { std::ifstream input; for (size_t fileInd = 0; fileInd < fileNames.size(); ++fileInd) { input.open(fileNames[fileInd].c_str()); FCA::Context context; ReadContext(context, input); input.close(); std::cout << "Attribute incremental" << " \"" << fileNames[fileInd] << '\"'; Timer timer; timer.StartTiming(); std::vector<FCA::ImplicationInd> implications = FCA::ComputeDGBasisAttrIncremental(context); timer.StopTiming(); output << fileInd + 1 << ". " << Time(timer.GetUserSeconds()) << " " << implications.size() << std::endl; std::cout << " complete in " << Time(timer.GetUserSeconds()) << " " << implications.size() << " implications" << std::endl; } }
ReadContext Reader::from(input& stream) const { const supplier_registry& suppliers = *this; return ReadContext(suppliers, stream); }
void BuildBasisAndCloseSetOpt(std::vector<std::string> fileNames, std::ofstream &output, const double probability, const size_t rep) { std::cout << "Precounting..." << std::endl << std::endl; const size_t testNum = fileNames.size(); std::vector<std::vector<FCA::ImplicationInd> > basises(testNum); std::vector<FCA::BitSet> sets(testNum); std::vector<size_t> attrNum(testNum); std::ifstream input; for (size_t fileInd = 0; fileInd < fileNames.size(); ++fileInd) { input.open(fileNames[fileInd].c_str()); FCA::Context context; ReadContext(context, input); input.close(); basises[fileInd] = FCA::ComputeDGBasis<FCA::LinClosure>(context); sets[fileInd] = GetRandomBitSet(context.getAttributesCnt(), probability); attrNum[fileInd] = context.getAttributesCnt(); } Timer timer; output << "Closure" << std::endl << std::endl; for (size_t i = 0; i < testNum; ++i) { FCA::BitSet tmp(attrNum[i]); timer.StartTiming(); for (size_t j = 0; j < rep; ++j) { FCA::Closure::Apply(sets[i], basises[i], tmp); } timer.StopTiming(); output << i << ". " << Time(timer.GetUserSeconds()) << " " << basises[i].size() << std::endl; } output << std::endl; output << "LinClosure" << std::endl << std::endl; for (size_t i = 0; i < testNum; ++i) { std::vector<size_t> premiseCount; std::vector<std::vector<size_t> > list(attrNum[i]); size_t prevImplSetSize = 0; FCA::BitSet tmp(attrNum[i]); FCA::LinClosure::Apply(sets[i], basises[i], premiseCount, list, prevImplSetSize, tmp); timer.StartTiming(); for (size_t j = 0; j < rep; ++j) { FCA::LinClosure::Apply(sets[i], basises[i], premiseCount, list, prevImplSetSize, tmp); } timer.StopTiming(); output << i << ". " << Time(timer.GetUserSeconds()) << " " << basises[i].size() << std::endl; } output << std::endl; output << "LinClosureImproved" << std::endl << std::endl; for (size_t i = 0; i < testNum; ++i) { std::vector<FCA::BitSet> list(attrNum[i]); size_t prevImplSetSize = 0; FCA::BitSet tmp(attrNum[i]); FCA::LinClosureImproved::Apply(sets[i], basises[i], list, prevImplSetSize, tmp); timer.StartTiming(); for (size_t j = 0; j < rep; ++j) { FCA::LinClosureImproved::Apply(sets[i], basises[i], list, prevImplSetSize, tmp); } timer.StopTiming(); output << i << ". " << Time(timer.GetUserSeconds()) << " " << basises[i].size() << std::endl; } output << std::endl; }
bool Pdb::RunToException() { DR_LOG("RunToException"); LLOG("RUN TO EXCEPTION"); TimeStop ts; bool disasfocus = disas.HasFocus(); bool locked = false; bool frestored = false; invalidpage.Clear(); mempage.Clear(); int opn = 0; for(;;) { if(terminated) { if(locked) Unlock(); return false; } opn++; DR_LOG("WaitForDebugEvent"); if(WaitForDebugEvent(&event, 0)) { DR_LOG("WaitForDebugEvent ended"); debug_threadid = event.dwThreadId; opn = 0; running = false; switch(event.dwDebugEventCode) { case EXCEPTION_DEBUG_EVENT: { DR_LOG("EXCEPTION_DEBUG_EVENT"); LLOG("Exception: " << FormatIntHex(event.u.Exception.ExceptionRecord.ExceptionCode) << " at: " << FormatIntHex(event.u.Exception.ExceptionRecord.ExceptionAddress) << " first: " << event.u.Exception.dwFirstChance); SaveForeground(); const EXCEPTION_RECORD& x = event.u.Exception.ExceptionRecord; if(findarg(x.ExceptionCode, EXCEPTION_BREAKPOINT, EXCEPTION_SINGLE_STEP, STATUS_WX86_BREAKPOINT, STATUS_WX86_SINGLE_STEP) < 0) { LLOG("Non-debug EXCEPTION"); if(event.u.Exception.dwFirstChance) { LLOG("First chance " << FormatIntHex(x.ExceptionCode)); break; } String desc = Format("Exception: [* %lX] at [* %16llX]&", (int64)x.ExceptionCode, (int64)x.ExceptionAddress); for(int i = 0; i < __countof(ex_desc); i++) if(ex_desc[i].code == x.ExceptionCode) desc << "[* " << DeQtf(ex_desc[i].text) << "]&"; if(x.ExceptionCode == EXCEPTION_ACCESS_VIOLATION) { desc << (x.ExceptionInformation[0] ? "[*@3 writing]" : "[*@4 reading]"); desc << Format(" at [* %08llX]", (int64)x.ExceptionInformation[1]); } ToForeground(); PromptOK(desc); } #ifdef CPU_64 if(!win64 && x.ExceptionCode == EXCEPTION_BREAKPOINT && !break_running) // Ignore x64 breakpoint in wow64 break; #endif if(break_running) debug_threadid = mainThreadId; break_running = false; ToForeground(); if(disasfocus) disas.SetFocus(); if(locked) Unlock(); if(refreshmodules) LoadModuleInfo(); LLOG("event.dwThreadId = " << event.dwThreadId); bool isbreakpoint = findarg(x.ExceptionCode, EXCEPTION_BREAKPOINT, STATUS_WX86_BREAKPOINT) >= 0; for(int i = 0; i < threads.GetCount(); i++) { Thread& t = threads[i]; (Context&)t = ReadContext(threads[i].hThread); if(event.dwThreadId == threads.GetKey(i)) { LLOG("Setting current context"); if(isbreakpoint #ifdef CPU_64 && bp_set.Find((win64 ? t.context64.Rip : t.context32.Eip) - 1) >= 0 #else && bp_set.Find(t.context32.Eip - 1) >= 0 #endif ) // We have stopped at breakpoint, need to move address back #ifdef CPU_64 if(win64) t.context64.Rip--; else #endif t.context32.Eip--; context = t; } } RemoveBp(); return true; } case CREATE_THREAD_DEBUG_EVENT: DR_LOG("CREATE_THREAD_DEBUG_EVENT"); LLOG("Create thread: " << event.dwThreadId); AddThread(event.dwThreadId, event.u.CreateThread.hThread); break; case EXIT_THREAD_DEBUG_EVENT: DR_LOG("EXIT_THREAD_DEBUG_EVENT"); LLOG("Exit thread: " << event.dwThreadId); RemoveThread(event.dwThreadId); break; case CREATE_PROCESS_DEBUG_EVENT: DR_LOG("CREATE_PROCESS_DEBUG_EVENT"); LLOG("Create process: " << event.dwProcessId); processid = event.dwProcessId; AddThread(event.dwThreadId, event.u.CreateProcessInfo.hThread); CloseHandle(event.u.CreateProcessInfo.hFile); CloseHandle(event.u.CreateProcessInfo.hProcess); break; case EXIT_PROCESS_DEBUG_EVENT: DR_LOG("EXIT_PROCESS_DEBUG_EVENT"); LLOG("Exit process: " << event.dwProcessId); if(locked) Unlock(); terminated = true; return false; case LOAD_DLL_DEBUG_EVENT: { DR_LOG("LOAD_DLL_DEBUG_EVENT"); LLOG("Load dll: " << event.u.LoadDll.lpBaseOfDll); CloseHandle(event.u.LoadDll.hFile); refreshmodules = true; break; } case UNLOAD_DLL_DEBUG_EVENT: DR_LOG("UNLOAD_DLL_DEBUG_EVENT"); LLOG("UnLoad dll: " << event.u.UnloadDll.lpBaseOfDll); refreshmodules = true; break; case RIP_EVENT: DR_LOG("RIP_EVENT"); LLOG("RIP!"); Exclamation("Process being debugged died unexpectedly!"); terminated = true; if(locked) Unlock(); return false; } DR_LOG("ContinueDebugEvent"); ContinueDebugEvent(event.dwProcessId, event.dwThreadId, DBG_EXCEPTION_NOT_HANDLED); running = true; } if(ts.Elapsed() > 200) { DR_LOG("ts.Elpsed() > 200"); if(!lock) { Lock(); locked = true; } if(!frestored) { RestoreForeground(); frestored = true; } } if(lock) { DR_LOG("GuiSleep"); GuiSleep(opn < 1000 ? 0 : 100); Ctrl::ProcessEvents(); } else { DR_LOG("Sleep"); Sleep(opn < 1000 ? 0 : 100); } } }