__declspec(noinline) void PointerToDurableMappedFile::makeChunkWritable(size_t chunkno) { stdx::lock_guard<stdx::mutex> lkPrivateViews(_m); if (writable.get(chunkno)) // double check lock return; // remap all maps in this chunk. // common case is a single map, but could have more than one with smallfiles or .ns files size_t chunkStart = chunkno * MemoryMappedCOWBitset::ChunkSize; size_t chunkNext = chunkStart + MemoryMappedCOWBitset::ChunkSize; stdx::lock_guard<stdx::mutex> lkMapView(mapViewMutex); map<void*, DurableMappedFile*>::iterator i = _views.upper_bound((void*)(chunkNext - 1)); while (1) { const pair<void*, DurableMappedFile*> x = *(--i); DurableMappedFile* mmf = x.second; if (mmf == 0) break; size_t viewStart = reinterpret_cast<size_t>(x.first); size_t viewEnd = viewStart + mmf->length(); if (viewEnd <= chunkStart) break; size_t protectStart = std::max(viewStart, chunkStart); dassert(protectStart < chunkNext); size_t protectEnd = std::min(viewEnd, chunkNext); size_t protectSize = protectEnd - protectStart; dassert(protectSize > 0 && protectSize <= MemoryMappedCOWBitset::ChunkSize); DWORD oldProtection; bool ok = VirtualProtect( reinterpret_cast<void*>(protectStart), protectSize, PAGE_WRITECOPY, &oldProtection); if (!ok) { DWORD dosError = GetLastError(); if (dosError == ERROR_COMMITMENT_LIMIT) { // System has run out of memory between physical RAM & page file, tell the user BSONObjBuilder bb; ProcessInfo p; p.getExtraInfo(bb); severe() << "MongoDB has exhausted the system memory capacity."; severe() << "Current Memory Status: " << bb.obj(); } severe() << "VirtualProtect for " << mmf->filename() << " chunk " << chunkno << " failed with " << errnoWithDescription(dosError) << " (chunk size is " << protectSize << ", address is " << hex << protectStart << dec << ")" << " in mongo::makeChunkWritable, terminating" << endl; fassertFailed(16362); } } writable.set(chunkno); }
int dmtcp::CkptSerializer::openMtcpCheckpointFile(const dmtcp::string& path){ int fd = openDmtcpCheckpointFile(path); jalib::JBinarySerializeReaderRaw rdr(path, fd); static ConnectionToFds cfd; static ProcessInfo pInfo; cfd.serialize(rdr); pInfo.serialize(rdr); return fd; }
void NewProcessDialog::accept() { ProcessInfo* info = new ProcessInfo(); info->setProcessType(static_cast<FiniteElement::ProcessType>(this->processTypeBox->currentIndex() + 1)); info->setProcessPrimaryVariable(static_cast<FiniteElement::PrimaryVariable>(this->pvTypeBox->currentIndex() + 1)); emit addProcess(info); this->done(QDialog::Accepted); }
logical ErrorHandle :: DisplayMessage (Error *error_obj ) { char string[129]; char string1[10]; char buffer[sizeof(message.text)+1]; ProcessInfo *procinfo; BEGINSEQ if ( TestSysVariable("SUPRESS_ERRORS","YES") ) LEAVESEQ procinfo = ThreadEntry::GetCurProcInfo(); if ( procinfo ) WriteProtocol(error_obj,procinfo->GetProtocolFile()); if ( error_obj ) message.SetData(error_obj); if ( !gui_message ) { if ( TestSysVariable("NO_CONSOLE_MESSAGES","YES") ) LEAVESEQ puts(gvtxbts(buffer,message.text,StringLength(message.text,sizeof(message.text)))); LEAVESEQ } if ( gui_message != YES ) // temporary enabled gui_message = NO; #ifndef __unix__ int type = MB_OK | MB_TOPMOST; if ( error_obj ) switch ( error_obj->type ) { case 'D' : type = MB_OKCANCEL; case 'M' : type |= MB_ICONQUESTION; break; case 'S' : case 'I' : type |= MB_ICONINFORMATION; break; case 'W' : type |= MB_ICONWARNING; break; default : type |= MB_ICONERROR; } else type = MB_ICONERROR; gvtxbts(string,message.component,19); strcat(string," "); strcat(string,gvtxbts(string1,message.error_code,4)); MessageBox(NULL, message.text, string, type); #else if // hier fehlt noch der XWIN-Teil #endif RECOVER ENDSEQ return(NO); }
void ErrorHandle :: WriteError (Error *error_obj ) { char path[256]; Error saverr = *error_obj; logical show_errors = NO; ProcessInfo *procinfo; short handle; BEGINSEQ if ( error_obj->CheckError() ) { if ( (procinfo = ThreadEntry::GetCurProcInfo()) && procinfo->get_error_file() && *procinfo->get_error_file() ) { strcpy(path,procinfo->get_error_file()); strcat(strcat(path,"/"),"error.lst"); } else strcpy(path,cpath); show_errors = TestSysVariable("SHOW_ERRORS","YES"); *error_obj = saverr; ILock(); if ( error_obj ) message.SetData(error_obj); #ifdef __unix__ if ( (handle = _open (path, (int)(O_RDWR | O_APPEND | O_CREAT ), (S_IREAD | S_IWRITE) )) > 0 ) #else if ( (handle = _open (path, (int)(O_WRONLY | O_APPEND | O_CREAT | O_BINARY ), S_IWRITE )) > 0 ) #endif { _write(handle,&message,sizeof(message)); _close(handle); } if ( show_errors ) { if ( !gui_message ) gui_message = AUTO; // enable temporaily ShowMessage(NULL); } IUnlock(); } RECOVER ENDSEQ }
RocksEngine::RocksEngine(const std::string& path, bool durable) : _path(path), _durable(durable) { { // create block cache uint64_t cacheSizeGB = 0; ProcessInfo pi; unsigned long long memSizeMB = pi.getMemSizeMB(); if (memSizeMB > 0) { double cacheMB = memSizeMB / 2; cacheSizeGB = static_cast<uint64_t>(cacheMB / 1024); } if (cacheSizeGB < 1) { cacheSizeGB = 1; } _block_cache = rocksdb::NewLRUCache(cacheSizeGB * 1024 * 1024 * 1024LL); } // open DB rocksdb::DB* db; auto s = rocksdb::DB::Open(_options(), path, &db); ROCKS_STATUS_OK(s); _db.reset(db); // open iterator boost::scoped_ptr<rocksdb::Iterator> _iter(_db->NewIterator(rocksdb::ReadOptions())); // find maxPrefix _maxPrefix = 0; _iter->SeekToLast(); if (_iter->Valid()) { // otherwise the DB is empty, so we just keep it at 0 bool ok = extractPrefix(_iter->key(), &_maxPrefix); // this is DB corruption here invariant(ok); } // load ident to prefix map { boost::mutex::scoped_lock lk(_identPrefixMapMutex); for (_iter->Seek(kMetadataPrefix); _iter->Valid() && _iter->key().starts_with(kMetadataPrefix); _iter->Next()) { rocksdb::Slice ident(_iter->key()); ident.remove_prefix(kMetadataPrefix.size()); // this could throw DBException, which then means DB corruption. We just let it fly // to the caller BSONObj identConfig(_iter->value().data()); BSONElement element = identConfig.getField("prefix"); // TODO: SERVER-16979 Correctly handle errors returned by RocksDB // This is DB corruption invariant(!element.eoo() || !element.isNumber()); uint32_t identPrefix = static_cast<uint32_t>(element.numberInt()); _identPrefixMap[StringData(ident.data(), ident.size())] = identPrefix; } } }
void printMemInfo( const char * where ){ cout << "mem info: "; if ( where ) cout << where << " "; ProcessInfo pi; if ( ! pi.supported() ){ cout << " not supported" << endl; return; } cout << "vsize: " << pi.getVirtualMemorySize() << " resident: " << pi.getResidentSize() << " mapped: " << ( MemoryMappedFile::totalMappedLength() / ( 1024 * 1024 ) ) << endl; }
BSONObj JSGetMemInfo(const BSONObj& args, void* data) { ProcessInfo pi; uassert(10258, "processinfo not supported", pi.supported()); BSONObjBuilder e; e.append("virtual", pi.getVirtualMemorySize()); e.append("resident", pi.getResidentSize()); BSONObjBuilder b; b.append("ret", e.obj()); return b.obj(); }
void ClientMetadata::serialize(StringData driverName, StringData driverVersion, BSONObjBuilder* builder) { ProcessInfo processInfo; serializePrivate(driverName, driverVersion, processInfo.getOsType(), processInfo.getOsName(), processInfo.getArch(), processInfo.getOsVersion(), builder); }
void printMemInfo(const char* where) { LogstreamBuilder out = log(); out << "mem info: "; if (where) out << where << " "; ProcessInfo pi; if (!pi.supported()) { out << " not supported"; return; } out << "vsize: " << pi.getVirtualMemorySize() << " resident: " << pi.getResidentSize() << " mapped: " << (MemoryMappedFile::totalMappedLength() / (1024 * 1024)); }
// static void Explain::generateServerInfo(BSONObjBuilder* out) { BSONObjBuilder serverBob(out->subobjStart("serverInfo")); out->append("host", getHostNameCached()); out->appendNumber("port", serverGlobalParams.port); out->append("version", versionString); out->append("gitVersion", gitVersion()); ProcessInfo p; BSONObjBuilder bOs; bOs.append("type", p.getOsType()); bOs.append("name", p.getOsName()); bOs.append("version", p.getOsVersion()); serverBob.append(StringData("os"), bOs.obj()); serverBob.doneFast(); }
//************************************************************************************ //************************************************************************************ void ThermalFace2D::CalculateAll(MatrixType& rLeftHandSideMatrix, VectorType& rRightHandSideVector, ProcessInfo& rCurrentProcessInfo, bool CalculateStiffnessMatrixFlag, bool CalculateResidualVectorFlag) { KRATOS_TRY unsigned int number_of_nodes = GetGeometry().size(); //resizing as needed the LHS unsigned int MatSize=number_of_nodes; ConvectionDiffusionSettings::Pointer my_settings = rCurrentProcessInfo.GetValue(CONVECTION_DIFFUSION_SETTINGS); const Variable<double>& rUnknownVar = my_settings->GetUnknownVariable(); const Variable<double>& rSurfaceSourceVar = my_settings->GetSurfaceSourceVariable(); //calculate lenght double x21 = GetGeometry()[1].X() - GetGeometry()[0].X(); double y21 = GetGeometry()[1].Y() - GetGeometry()[0].Y(); double lenght = x21*x21 + y21*y21; lenght = sqrt(lenght); const Properties& ConstProp = GetProperties(); const double& ambient_temperature = ConstProp[AMBIENT_TEMPERATURE]; double StefenBoltzmann = 5.67e-8; double emissivity = ConstProp[EMISSIVITY]; double convection_coefficient = ConstProp[CONVECTION_COEFFICIENT]; const double& T0 = GetGeometry()[0].FastGetSolutionStepValue(rUnknownVar); const double& T1 = GetGeometry()[1].FastGetSolutionStepValue(rUnknownVar); const double& q0 =GetGeometry()[0].FastGetSolutionStepValue(rSurfaceSourceVar); const double& q1 =GetGeometry()[1].FastGetSolutionStepValue(rSurfaceSourceVar); if (CalculateStiffnessMatrixFlag == true) //calculation of the matrix is required { if(rLeftHandSideMatrix.size1() != MatSize ) rLeftHandSideMatrix.resize(MatSize,MatSize,false); noalias(rLeftHandSideMatrix) = ZeroMatrix(MatSize,MatSize); rLeftHandSideMatrix(0,0) = ( convection_coefficient + emissivity*StefenBoltzmann*4.0*pow(T0,3) )* 0.5 * lenght; rLeftHandSideMatrix(1,1) = ( convection_coefficient + emissivity*StefenBoltzmann*4.0*pow(T1,3) )* 0.5 * lenght; } //resizing as needed the RHS double aux = pow(ambient_temperature,4); if (CalculateResidualVectorFlag == true) //calculation of the matrix is required { if(rRightHandSideVector.size() != MatSize ) rRightHandSideVector.resize(MatSize,false); rRightHandSideVector[0] = q0 - emissivity*StefenBoltzmann*(pow(T0,4) - aux) - convection_coefficient * ( T0 - ambient_temperature); rRightHandSideVector[1] = q1 - emissivity*StefenBoltzmann*(pow(T1,4) - aux) - convection_coefficient * ( T1 - ambient_temperature); rRightHandSideVector *= 0.5*lenght; } KRATOS_CATCH("") }
size_t WiredTigerUtil::getCacheSizeMB(double requestedCacheSizeGB) { double cacheSizeMB; const double kMaxSizeCacheMB = 10 * 1000 * 1000; if (requestedCacheSizeGB == 0) { // Choose a reasonable amount of cache when not explicitly specified by user. // Set a minimum of 256MB, otherwise use 50% of available memory over 1GB. ProcessInfo pi; double memSizeMB = pi.getMemSizeMB(); cacheSizeMB = std::max((memSizeMB - 1024) * 0.5, 256.0); } else { cacheSizeMB = 1024 * requestedCacheSizeGB; } if (cacheSizeMB > kMaxSizeCacheMB) { log() << "Requested cache size: " << cacheSizeMB << "MB exceeds max; setting to " << kMaxSizeCacheMB << "MB"; cacheSizeMB = kMaxSizeCacheMB; } return static_cast<size_t>(cacheSizeMB); }
//************************************************************************************ //************************************************************************************ void ThermalFace2D::GetDofList(DofsVectorType& ConditionalDofList,ProcessInfo& CurrentProcessInfo) { ConvectionDiffusionSettings::Pointer my_settings = CurrentProcessInfo.GetValue(CONVECTION_DIFFUSION_SETTINGS); const Variable<double>& rUnknownVar = my_settings->GetUnknownVariable(); ConditionalDofList.resize(GetGeometry().size()); for (unsigned int i=0; i<GetGeometry().size(); i++) { ConditionalDofList[i] = (GetGeometry()[i].pGetDof(rUnknownVar)); } }
bool run(const string& dbname, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { ProcessInfo p; BSONObjBuilder bSys, bOs; bSys.appendDate( "currentTime" , jsTime() ); bSys.append( "hostname" , prettyHostName() ); bSys.append( "cpuAddrSize", p.getAddrSize() ); bSys.append( "memSizeMB", static_cast <unsigned>( p.getMemSizeMB() ) ); bSys.append( "numCores", p.getNumCores() ); bSys.append( "cpuArch", p.getArch() ); bSys.append( "numaEnabled", p.hasNumaEnabled() ); bOs.append( "type", p.getOsType() ); bOs.append( "name", p.getOsName() ); bOs.append( "version", p.getOsVersion() ); result.append( StringData( "system" ), bSys.obj() ); result.append( StringData( "os" ), bOs.obj() ); p.appendSystemDetails( result ); return true; }
void SearchTransaction::Search(DWORD value) { ProcessInfo info; this->searchResults->clear(); this->value = value; if ( this->process ) { this->process->GetProcessInformation(&info); SIZE_T bytesRead = 0; DWORD buffer = 0; QWORD address = 0x0; BOOL result = TRUE; while( address < info.GetWorkingSize() ) { buffer = 0; result = this->process->ReadMemory( (LPCVOID)address, &buffer, this->width, &bytesRead); for ( SIZE_T d = 0 ; d < bytesRead ; d++ ) { if ( value == buffer && this->searchResults->find(address) == this->searchResults->end() ) { this->searchResults->insert( std::pair<QWORD,QWORD>(address,address) ); } } address+=this->width; } } }
//************************************************************************************ //************************************************************************************ void ThermalFace2D::EquationIdVector(EquationIdVectorType& rResult, ProcessInfo& CurrentProcessInfo) { ConvectionDiffusionSettings::Pointer my_settings = CurrentProcessInfo.GetValue(CONVECTION_DIFFUSION_SETTINGS); const Variable<double>& rUnknownVar = my_settings->GetUnknownVariable(); unsigned int number_of_nodes = GetGeometry().PointsNumber(); if(rResult.size() != number_of_nodes) rResult.resize(number_of_nodes,false); for (unsigned int i=0; i<number_of_nodes; i++) { rResult[i] = (GetGeometry()[i].GetDof(rUnknownVar)).EquationId(); } }
/** called once a minute from killcursors thread */ void sayMemoryStatus() { static time_t last; static Mem mlast; try { ProcessInfo p; if ( !cmdLine.quiet && p.supported() ) { Mem m; m.res = p.getResidentSize(); m.virt = p.getVirtualMemorySize(); m.mapped = MemoryMappedFile::totalMappedLength() / (1024 * 1024); time_t now = time(0); if( now - last >= 300 || m.grew(mlast) ) { log() << "mem (MB) res:" << m.res << " virt:" << m.virt; long long totalMapped = m.mapped; if (cmdLine.dur) { totalMapped *= 2; log() << " mapped (incl journal view):" << totalMapped; } else { log() << " mapped:" << totalMapped; } log() << " connections:" << connTicketHolder.used(); if (theReplSet) { log() << " replication threads:" << ReplSetImpl::replWriterThreadCount + ReplSetImpl::replPrefetcherThreadCount; } last = now; mlast = m; } } } catch(const std::exception&) { log() << "ProcessInfo exception" << endl; } }
/** called once a minute from killcursors thread */ void sayMemoryStatus() { static time_t last; static Mem mlast; try { ProcessInfo p; if ( !cmdLine.quiet && p.supported() ) { Mem m; m.res = p.getResidentSize(); m.virt = p.getVirtualMemorySize(); m.mapped = (int) (MemoryMappedFile::totalMappedLength() / ( 1024 * 1024 )); if( time(0)-last >= 300 || m.grew(mlast) ) { log() << "mem (MB) res:" << m.res << " virt:" << m.virt << " mapped:" << m.mapped << endl; if( m.virt - (cmdLine.dur?2:1)*m.mapped > 5000 ) { ONCE log() << "warning virtual/mapped memory differential is large. journaling:" << cmdLine.dur << endl; } last = time(0); mlast = m; } } } catch(...) { log() << "ProcessInfo exception" << endl; } }
bool ProcFS::ReadProcessInfo(pid_t pid, ProcessInfo &info) { pid_t ppid; uid_t uid, euid; gid_t gid, egid; ELFInfo elf; std::string path; info.clear(); if (!ReadProcessIds(pid, ppid, uid, euid, gid, egid) || !GetProcessELFInfo(pid, elf) || (path = GetProcessExecutablePath(pid)).empty()) return false; info.pid = pid; info.parentPid = ppid; info.name.swap(path); info.realUid = uid; info.effectiveUid = euid; info.realGid = gid; info.effectiveGid = egid; if (!ELFSupport::MachineTypeToCPUType(elf.machine, elf.is64Bit, info.cpuType, info.cpuSubType)) { info.cpuType = kCPUTypeAny; info.cpuSubType = kCPUSubTypeInvalid; } info.nativeCPUType = elf.machine; info.nativeCPUSubType = kInvalidCPUType; info.endian = elf.endian; info.pointerSize = elf.is64Bit ? 8 : 4; info.osType = Platform::GetOSTypeName(); info.osVendor = Platform::GetOSVendorName(); return true; }
int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QStringList args = a.arguments(); if(args.size() < 5) { std::cout << ">>> KESM Composer Controller ver " << kComposerControllerVersion << " <<<" << std::endl; std::cout << "Control composers." << std::endl; QFileInfo pathInfo(args[0]); QString fileName(pathInfo.completeBaseName()); std::cout << qPrintable(fileName )<< " dataPathName startIndex endIndex numberOfImagesToCompose" << std::endl; return kKESM_ERROR; } ProcessInfo processInfo; processInfo.init(args[1], args[2].toInt(), args[3].toInt(), args[4].toInt()); QString logTag; if(args.size() > 5) logTag = args[5]; std::cout << ">>> KESM Composer Controller ver " << kComposerControllerVersion << " <<<" << std::endl; std::cout << "Control composers." << std::endl; std::cout << "dataPathName: " << qPrintable(processInfo.dataPathName) << std::endl; std::cout << "startIndex: " << processInfo.startIndex << std::endl; std::cout << "endIndex: " << processInfo.endIndex << std::endl; std::cout << "numberOfImages: " << processInfo.numberOfImages << std::endl; //////////////////////////////////////////// // Controller KESM::ComposerController controller; for (int i = processInfo.startIndex; i < processInfo.endIndex; i+=kComposerUnitDepth) { //(processInfo.numberOfImages)/2) { processInfo.prepareArgs(i); QStringList argList; QString numberOfImages = QString("%1").arg(processInfo.args.numberOfImages); if(args.size() > 5) argList << processInfo.args.baseFilePathName << processInfo.args.outputPath << numberOfImages << logTag; else argList << processInfo.args.baseFilePathName << processInfo.args.outputPath << numberOfImages; std::cout << "Processing... " << i << ": " << qPrintable(processInfo.args.baseFilePathName) << std::endl; controller.process.startDetached(processInfo.processName, argList); //controller.process.start(processInfo.processName, argList); // default max wait time is 30 sec. // if more than 30 sec needed, we got to wait more... controller.process.waitForFinished();//kMaxProcessWaitTime); if(controller.isProcessError) break; } return kKESM_OK; //a.exec(); }
//------------------------------------------------------------------------------------------------- int_t xTMAIN(int_t a_argsNum, tchar_t *a_args[]) { xUNUSED(a_argsNum); xUNUSED(a_args); { #if 1 std::vector<int_t> signalNums; signalNums.push_back(SIGHUP); // Hangup (POSIX) signalNums.push_back(SIGINT); // Interrupt (ANSI) signalNums.push_back(SIGQUIT); // Quit (POSIX) signalNums.push_back(SIGILL); // Illegal instruction (ANSI) signalNums.push_back(SIGTRAP); // Trace trap (POSIX) signalNums.push_back(SIGABRT); // Abort (ANSI) signalNums.push_back(SIGIOT); // IOT trap (4.2 BSD) signalNums.push_back(SIGBUS); // BUS error (4.2 BSD) signalNums.push_back(SIGFPE); // Floating-point exception (ANSI) signalNums.push_back(SIGKILL); // Kill); unblockable (POSIX) signalNums.push_back(SIGUSR1); // User-defined signal 1 (POSIX) signalNums.push_back(SIGSEGV); // Segmentation violation (ANSI) signalNums.push_back(SIGUSR2); // User-defined signal 2 (POSIX) signalNums.push_back(SIGPIPE); // Broken pipe (POSIX) signalNums.push_back(SIGALRM); // Alarm clock (POSIX) signalNums.push_back(SIGTERM); // Termination (ANSI) signalNums.push_back(SIGSTKFLT); // Stack fault signalNums.push_back(SIGCLD); // Same as SIGCHLD (System V) signalNums.push_back(SIGCHLD); // Child status has changed (POSIX) signalNums.push_back(SIGCONT); // Continue (POSIX) signalNums.push_back(SIGSTOP); // Stop); unblockable (POSIX) signalNums.push_back(SIGTSTP); // Keyboard stop (POSIX) signalNums.push_back(SIGTTIN); // Background read from tty (POSIX) signalNums.push_back(SIGTTOU); // Background write to tty (POSIX) signalNums.push_back(SIGURG); // Urgent condition on socket (4.2 BSD) signalNums.push_back(SIGXCPU); // CPU limit exceeded (4.2 BSD) signalNums.push_back(SIGXFSZ); // File size limit exceeded (4.2 BSD) signalNums.push_back(SIGVTALRM); // Virtual alarm clock (4.2 BSD) signalNums.push_back(SIGPROF); // Profiling alarm clock (4.2 BSD) signalNums.push_back(SIGWINCH); // Window size change (4.3 BSD); Sun) signalNums.push_back(SIGPOLL); // Pollable event occurred (System V) signalNums.push_back(SIGIO); // I/O now possible (4.2 BSD) signalNums.push_back(SIGPWR); // Power failure restart (System V) signalNums.push_back(SIGSYS); // Bad system call Application application(xT("[app_name]_guid")); Application::setName(xT("[app_name]")); #if 0 application.setName(xT("[app_name]")); application.setDecription(xT("[decription]")); application.setUsage(xT("[usage]")); application.setHelp(xT("[help]")); application.setCopyrightYears(xT("[2008-2014]")); application.setVersionMajor(xT("[1]")); application.setVersionMinor(xT("[0]")); application.setVersionPatch(xT("[0]")); application.setVersionType(xT("[alpha]")); application.setVersionRevision(xT("[develop/970f53b]")); application.setVendorName(xT("[Skynowa Studio]")); application.setVendorDomain(xT("[com]")); application.setVendorAuthor(xT("[skynowa]")); application.setVendorUrl(xT("[http://bitbucket.org/skynowa/xlib]")); application.setVendorEmail(xT("[[email protected]]")); application.setVendorSkype(xT("[skynowa777]")); #endif #if 0 Trace() << xTRACE_VAR(application.name()) << xT("\n") << xTRACE_VAR(application.decription()) << xT("\n") << xTRACE_VAR(application.usage()) << xT("\n") << xTRACE_VAR(application.help()) << xT("\n") << xTRACE_VAR(application.copyrightYears()) << xT("\n") << xTRACE_VAR(application.versionMajor()) << xT("\n") << xTRACE_VAR(application.versionMinor()) << xT("\n") << xTRACE_VAR(application.versionPatch()) << xT("\n") << xTRACE_VAR(application.versionType()) << xT("\n") << xTRACE_VAR(application.versionRevision()) << xT("\n") << xTRACE_VAR(application.vendorName()) << xT("\n") << xTRACE_VAR(application.vendorDomain()) << xT("\n") << xTRACE_VAR(application.vendorAuthor()) << xT("\n") << xTRACE_VAR(application.vendorUrl()) << xT("\n") << xTRACE_VAR(application.vendorEmail()) << xT("\n") << xTRACE_VAR(application.vendorSkype()); #endif application.setOnSignals(signalNums, SignalFunctor::onSignals); application.setOnTerminate(SignalFunctor::onTerminate); application.setOnExit(SignalFunctor::onExit); // test error TestFail testFail; testFail.foo3(); #endif } #if xOPTION_TESTS // checks { #if xENV_UNIX SystemInfo info; xCHECK_MSG_RET(info.isUserAdmin(), xT("xLib_test: Can't run as root"), EXIT_FAILURE); #endif } // options (default) bool_t isUseTracing = true; ulonglong_t allLoops = 1ULL; ulonglong_t unitLoops = 1ULL; ulonglong_t caseLoops = 1ULL; { std::vec_tstring_t args; ProcessInfo info; info.setProcessId(Process::currentId()); info.commandLine(&args); if (a_argsNum == 1) { // OK, run tests with default params } else if (a_argsNum == 2) { // usage bool_t bRv = StringCI::compare(xT("-h"), args.at(1)) || StringCI::compare(xT("--help"), args.at(1)); if (!bRv) { std::tcout << xT("\nxLib_test: unknown switches\n") << std::endl; } else { std::tcout << xT("\nUsage: ./xLib_test [is_tracing] [all_loops] [unit_loops]\n") xT(" - xLib_test (binary file path)\n") xT(" - is_tracing (is tracing)\n") xT(" - all_loops (loops for all tests)\n") xT(" - unit_loops (loops for unit test)\n") xT(" - case_loops (loops for case test)\n") << std::endl; } return EXIT_SUCCESS; } else if (a_argsNum == 5) { // addition params isUseTracing = String::cast<bool_t> ( args.at(1) ); allLoops = String::cast<ulonglong_t>( args.at(2) ); unitLoops = String::cast<ulonglong_t>( args.at(3) ); caseLoops = String::cast<ulonglong_t>( args.at(4) ); } else { // fail std::tcout << xT("\nxLib_test: unknown switches\n") << std::endl; return EXIT_FAILURE; } } // add and run tests { TestManager manager(isUseTracing); // Test #if 1 manager.add(new Test_Test); #endif // Core #if 1 manager.add(new Test_Units); manager.add(new Test_Defines); manager.add(new Test_Limits); manager.add(new Test_Utils); manager.add(new Test_StdStream); manager.add(new Test_HandleT); manager.add(new Test_Type); manager.add(new Test_Flags); manager.add(new Test_Array); manager.add(new Test_AutoReset); manager.add(new Test_Char); manager.add(new Test_Locale); manager.add(new Test_String); manager.add(new Test_DateTime); manager.add(new Test_Com); manager.add(new Test_Application); #endif // Crypt #if 1 manager.add(new Test_Base64); #if xHAVE_OPENSSL_CRYPTO manager.add(new Test_Blowfish); #endif manager.add(new Test_Crc32); manager.add(new Test_Guid); manager.add(new Test_Random); // Db #if xHAVE_MYSQL manager.add(new Test_MySql); #endif #endif // Debug #if 1 manager.add(new Test_Debug); manager.add(new Test_BuildInfo); manager.add(new Test_StdError); manager.add(new Test_NativeError); manager.add(new Test_Exception); manager.add(new Test_StackTrace); manager.add(new Test_Debugger); manager.add(new Test_ErrorReport); manager.add(new Test_Profiler); manager.add(new Test_AutoProfiler); #endif // File system #if 1 manager.add(new Test_Path); manager.add(new Test_FileType); manager.add(new Test_File); manager.add(new Test_FileTemp); manager.add(new Test_Dll); manager.add(new Test_Finder); manager.add(new Test_Dir); manager.add(new Test_Volume); manager.add(new Test_Config); manager.add(new Test_Backup); #endif // Log #if 1 manager.add(new Test_Trace); manager.add(new Test_FileLog); manager.add(new Test_SystemLog); #endif // Net #if 1 manager.add(new Test_CookiePv0); manager.add(new Test_CookiePv1); manager.add(new Test_Cgi); manager.add(new Test_SocketInit); manager.add(new Test_DnsClient); // manager.add(new Test_TcpClient); // manager.add(new Test_TcpServer); manager.add(new Test_HttpClient); #endif // Patterns #if 1 manager.add(new Test_Observer); manager.add(new Test_Raii); manager.add(new Test_Singleton); #endif // Sync #if 1 manager.add(new Test_AtomicLongInt); manager.add(new Test_ThreadStorage); manager.add(new Test_Mutex); manager.add(new Test_AutoMutex); manager.add(new Test_IpcMutex); manager.add(new Test_AutoIpcMutex); // manager.add(new Test_Event); manager.add(new Test_Condition); manager.add(new Test_Semaphore); manager.add(new Test_IpcSemaphore); // manager.add(new Test_Sleeper); // manager.add(new Test_Thread); // manager.add(new Test_ThreadPool); manager.add(new Test_Process); #endif // Gui #if 1 manager.add(new Test_MsgBox); #endif // System #if 1 manager.add(new Test_Environment); manager.add(new Test_SystemInfo); manager.add(new Test_ProcessInfo); manager.add(new Test_Console); manager.add(new Test_Shell); #endif manager.run(allLoops, unitLoops, caseLoops); } #endif // xOPTION_TESTS return EXIT_SUCCESS; }
bool ProcessInfo::operator<(const ProcessInfo& val) { return GetPriority() < val.GetPriority(); }
bool Platform::GetProcessInfo(ProcessId pid, ProcessInfo &info) { HANDLE processHandle; BOOL rc; info.clear(); info.pid = pid; processHandle = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid); if (processHandle == nullptr) { goto error; } // Get process name. { HMODULE firstModuleHandle; DWORD bytesNeeded; WCHAR processName[MAX_PATH]; rc = EnumProcessModules(processHandle, &firstModuleHandle, sizeof(firstModuleHandle), &bytesNeeded); if (!rc) goto error; rc = GetModuleBaseNameW(processHandle, firstModuleHandle, processName, sizeof(processName)); if (!rc) goto error; info.name = WideToNarrowString(processName); } // Get process user ID. { HANDLE processToken; std::vector<char> userInfoBuffer; PTOKEN_USER userInfo; DWORD bytesNeeded; rc = OpenProcessToken(processHandle, TOKEN_QUERY, &processToken); if (!rc) goto error; GetTokenInformation(processToken, TokenUser, userInfoBuffer.data(), userInfoBuffer.size(), &bytesNeeded); userInfoBuffer.resize(bytesNeeded); rc = GetTokenInformation(processToken, TokenUser, userInfoBuffer.data(), userInfoBuffer.size(), &bytesNeeded); if (!rc) { CloseHandle(processToken); goto error; } userInfo = reinterpret_cast<PTOKEN_USER>(userInfoBuffer.data()); DWORD size = GetLengthSid(userInfo->User.Sid); info.realUid = malloc(size); CopySid(size, info.realUid, userInfo->User.Sid); CloseHandle(processToken); } // TODO(sas): Fetch the process group ID. This looks like it's gonna // require some additional work as a process on Windows doesn't have // a single group but a list of group tokens instead. CloseHandle(processHandle); return true; error: if (processHandle != nullptr) CloseHandle(processHandle); return false; }
TEST(ProcessInfo, SysInfoIsInitialized) { ProcessInfo processInfo; if (processInfo.supported()) { ASSERT_FALSE(processInfo.getOsType().empty()); } }
ProcessInfo::Pointer ProcessInfoGetPreviousSolutionStepInfo(ProcessInfo & rProcessInfo) { return rProcessInfo.pGetPreviousSolutionStepInfo(); }
TEST(ProcessInfo, GetNumCoresReturnsNonZeroNumberOfProcessors) { ProcessInfo processInfo; ProcessInfo::initializeSystemInfo(); ASSERT_GREATER_THAN((int)processInfo.getNumCores(), 0); }
RocksEngine::RocksEngine(const std::string& path, bool durable) : _path(path), _durable(durable), _maxPrefix(0) { { // create block cache uint64_t cacheSizeGB = rocksGlobalOptions.cacheSizeGB; if (cacheSizeGB == 0) { ProcessInfo pi; unsigned long long memSizeMB = pi.getMemSizeMB(); if (memSizeMB > 0) { double cacheMB = memSizeMB / 2; cacheSizeGB = static_cast<uint64_t>(cacheMB / 1024); } if (cacheSizeGB < 1) { cacheSizeGB = 1; } } _block_cache = rocksdb::NewLRUCache(cacheSizeGB * 1024 * 1024 * 1024LL, 6); } _maxWriteMBPerSec = rocksGlobalOptions.maxWriteMBPerSec; _rateLimiter.reset( rocksdb::NewGenericRateLimiter(static_cast<int64_t>(_maxWriteMBPerSec) * 1024 * 1024)); // open DB rocksdb::DB* db; auto s = rocksdb::DB::Open(_options(), path, &db); invariantRocksOK(s); _db.reset(db); _counterManager.reset( new RocksCounterManager(_db.get(), rocksGlobalOptions.crashSafeCounters)); _compactionScheduler.reset(new RocksCompactionScheduler(_db.get())); // open iterator boost::scoped_ptr<rocksdb::Iterator> iter(_db->NewIterator(rocksdb::ReadOptions())); // find maxPrefix iter->SeekToLast(); if (iter->Valid()) { // otherwise the DB is empty, so we just keep it at 0 bool ok = extractPrefix(iter->key(), &_maxPrefix); // this is DB corruption here invariant(ok); } // load ident to prefix map. also update _maxPrefix if there's any prefix bigger than // current _maxPrefix { boost::lock_guard<boost::mutex> lk(_identPrefixMapMutex); for (iter->Seek(kMetadataPrefix); iter->Valid() && iter->key().starts_with(kMetadataPrefix); iter->Next()) { invariantRocksOK(iter->status()); rocksdb::Slice ident(iter->key()); ident.remove_prefix(kMetadataPrefix.size()); // this could throw DBException, which then means DB corruption. We just let it fly // to the caller BSONObj identConfig(iter->value().data()); BSONElement element = identConfig.getField("prefix"); if (element.eoo() || !element.isNumber()) { log() << "Mongo metadata in RocksDB database is corrupted."; invariant(false); } uint32_t identPrefix = static_cast<uint32_t>(element.numberInt()); _identPrefixMap[StringData(ident.data(), ident.size())] = identPrefix; _maxPrefix = std::max(_maxPrefix, identPrefix); } } // just to be extra sure. we need this if last collection is oplog -- in that case we // reserve prefix+1 for oplog key tracker ++_maxPrefix; // load dropped prefixes { rocksdb::WriteBatch wb; // we will use this iter to check if prefixes are still alive boost::scoped_ptr<rocksdb::Iterator> prefixIter( _db->NewIterator(rocksdb::ReadOptions())); for (iter->Seek(kDroppedPrefix); iter->Valid() && iter->key().starts_with(kDroppedPrefix); iter->Next()) { invariantRocksOK(iter->status()); rocksdb::Slice prefix(iter->key()); prefix.remove_prefix(kDroppedPrefix.size()); prefixIter->Seek(prefix); invariantRocksOK(iter->status()); if (prefixIter->Valid() && prefixIter->key().starts_with(prefix)) { // prefix is still alive, let's instruct the compaction filter to clear it up uint32_t int_prefix; bool ok = extractPrefix(prefix, &int_prefix); invariant(ok); { boost::lock_guard<boost::mutex> lk(_droppedPrefixesMutex); _droppedPrefixes.insert(int_prefix); } } else { // prefix is no longer alive. let's remove the prefix from our dropped prefixes // list wb.Delete(iter->key()); } } if (wb.Count() > 0) { auto s = _db->Write(rocksdb::WriteOptions(), &wb); invariantRocksOK(s); } } }
WiredTigerKVEngine::WiredTigerKVEngine(const std::string& path, const std::string& extraOpenOptions, bool durable, bool repair) : _eventHandler(WiredTigerUtil::defaultEventHandlers()), _path(path), _durable(durable), _sizeStorerSyncTracker(100000, 60 * 1000) { size_t cacheSizeGB = wiredTigerGlobalOptions.cacheSizeGB; if (cacheSizeGB == 0) { // Since the user didn't provide a cache size, choose a reasonable default value. // We want to reserve 1GB for the system and binaries, but it's not bad to // leave a fair amount left over for pagecache since that's compressed storage. ProcessInfo pi; double memSizeMB = pi.getMemSizeMB(); if (memSizeMB > 0) { double cacheMB = (memSizeMB - 1024) * 0.6; cacheSizeGB = static_cast<size_t>(cacheMB / 1024); if (cacheSizeGB < 1) cacheSizeGB = 1; } } boost::filesystem::path journalPath = path; journalPath /= "journal"; if (_durable) { if (!boost::filesystem::exists(journalPath)) { try { boost::filesystem::create_directory(journalPath); } catch (std::exception& e) { log() << "error creating journal dir " << journalPath.string() << ' ' << e.what(); throw; } } } _previousCheckedDropsQueued = Date_t::now(); std::stringstream ss; ss << "create,"; ss << "cache_size=" << cacheSizeGB << "G,"; ss << "session_max=20000,"; ss << "eviction=(threads_max=4),"; ss << "config_base=false,"; ss << "statistics=(fast),"; // The setting may have a later setting override it if not using the journal. We make it // unconditional here because even nojournal may need this setting if it is a transition // from using the journal. ss << "log=(enabled=true,archive=true,path=journal,compressor="; ss << wiredTigerGlobalOptions.journalCompressor << "),"; ss << "file_manager=(close_idle_time=100000),"; //~28 hours, will put better fix in 3.1.x ss << "checkpoint=(wait=" << wiredTigerGlobalOptions.checkpointDelaySecs; ss << ",log_size=2GB),"; ss << "statistics_log=(wait=" << wiredTigerGlobalOptions.statisticsLogDelaySecs << "),"; ss << WiredTigerCustomizationHooks::get(getGlobalServiceContext())->getOpenConfig("system"); ss << extraOpenOptions; if (!_durable) { // If we started without the journal, but previously used the journal then open with the // WT log enabled to perform any unclean shutdown recovery and then close and reopen in // the normal path without the journal. if (boost::filesystem::exists(journalPath)) { string config = ss.str(); log() << "Detected WT journal files. Running recovery from last checkpoint."; log() << "journal to nojournal transition config: " << config; int ret = wiredtiger_open(path.c_str(), &_eventHandler, config.c_str(), &_conn); if (ret == EINVAL) { fassertFailedNoTrace(28717); } else if (ret != 0) { Status s(wtRCToStatus(ret)); msgassertedNoTrace(28718, s.reason()); } invariantWTOK(_conn->close(_conn, NULL)); } // This setting overrides the earlier setting because it is later in the config string. ss << ",log=(enabled=false),"; } string config = ss.str(); log() << "wiredtiger_open config: " << config; int ret = wiredtiger_open(path.c_str(), &_eventHandler, config.c_str(), &_conn); // Invalid argument (EINVAL) is usually caused by invalid configuration string. // We still fassert() but without a stack trace. if (ret == EINVAL) { fassertFailedNoTrace(28561); } else if (ret != 0) { Status s(wtRCToStatus(ret)); msgassertedNoTrace(28595, s.reason()); } _sessionCache.reset(new WiredTigerSessionCache(this)); if (_durable) { _journalFlusher = stdx::make_unique<WiredTigerJournalFlusher>(_sessionCache.get()); _journalFlusher->go(); } _sizeStorerUri = "table:sizeStorer"; { WiredTigerSession session(_conn); if (repair && _hasUri(session.getSession(), _sizeStorerUri)) { log() << "Repairing size cache"; fassertNoTrace(28577, _salvageIfNeeded(_sizeStorerUri.c_str())); } _sizeStorer.reset(new WiredTigerSizeStorer(_conn, _sizeStorerUri)); _sizeStorer->fillCache(); } }
WiredTigerKVEngine::WiredTigerKVEngine( const std::string& path, const std::string& extraOpenOptions, bool durable ) : _durable( durable ), _epoch( 0 ), _sizeStorerSyncTracker( 100000, 60 * 1000 ) { _eventHandler.handle_error = mdb_handle_error; _eventHandler.handle_message = mdb_handle_message; _eventHandler.handle_progress = mdb_handle_progress; _eventHandler.handle_close = mdb_handle_close; int cacheSizeGB = 1; { ProcessInfo pi; unsigned long long memSizeMB = pi.getMemSizeMB(); if ( memSizeMB > 0 ) { double cacheMB = memSizeMB / 50; cacheSizeGB = static_cast<int>( cacheMB / 1024 ); if ( cacheSizeGB < 1 ) cacheSizeGB = 1; } } if ( _durable ) { boost::filesystem::path journalPath = path; journalPath /= "journal"; if ( !boost::filesystem::exists( journalPath ) ) { try { boost::filesystem::create_directory( journalPath ); } catch( std::exception& e) { log() << "error creating journal dir " << journalPath.string() << ' ' << e.what(); throw; } } } std::stringstream ss; ss << "create,"; ss << "cache_size=" << cacheSizeGB << "G,"; ss << "session_max=20000,"; ss << "extensions=[local=(entry=index_collator_extension)],"; ss << "statistics=(all),"; if ( _durable ) { ss << "log=(enabled=true,archive=true,path=journal),"; } ss << "checkpoint=(wait=60,log_size=2GB),"; ss << extraOpenOptions; string config = ss.str(); log() << "wiredtiger_open config: " << config; invariantWTOK(wiredtiger_open(path.c_str(), &_eventHandler, config.c_str(), &_conn)); _sessionCache.reset( new WiredTigerSessionCache( this ) ); _sizeStorerUri = "table:sizeStorer"; { WiredTigerSession session( _conn, -1 ); WiredTigerSizeStorer* ss = new WiredTigerSizeStorer(); ss->loadFrom( &session, _sizeStorerUri ); _sizeStorer.reset( ss ); } }