NCBI C++ ToolKit
|
#include <corelib/ncbitime.hpp>
#include <time.h>
#include <vector>
#include <bitset>
#include <corelib/ncbi_os_mswin.hpp>
Go to the source code of this file.
Go to the SVN repository for this file.
Classes | |
class | CCpuFeatures |
CCpuFeatures –. More... | |
class | CCpuFeatures::InstructionSet |
class | CSystemInfo |
CSystemInfo –. More... | |
Typedefs | |
typedef void * | TLimitsPrintParameter |
Type of parameter for print handler. More... | |
typedef void(* | TLimitsPrintHandler) (ELimitsExitCode, size_t, CTime &, TLimitsPrintParameter) |
Type of handler for printing a dump information after generating any limitation event. More... | |
typedef int | TSuppressSystemMessageBox |
Binary OR of "ESuppressSystemMessageBox". More... | |
Enumerations | |
enum | ELimitsExitCode { eLEC_None , eLEC_Memory , eLEC_Cpu } |
Process limits. More... | |
enum | EMemoryAdvise { eMADV_Normal , eMADV_Random , eMADV_Sequential , eMADV_WillNeed , eMADV_DontNeed , eMADV_DoFork , eMADV_DontFork , eMADV_Mergeable , eMADV_Unmergeable } |
Memory advise. More... | |
enum | ESuppressSystemMessageBox { fSuppress_System = (1<<0) , fSuppress_Runtime = (1<<1) , fSuppress_Debug = (1<<2) , fSuppress_Exception = (1<<3) , fSuppress_All , fSuppress_Default = fSuppress_All } |
Suppress Diagnostic Popup Messages. More... | |
Functions | |
bool | SetMemoryLimit (size_t max_size, TLimitsPrintHandler handler=NULL, TLimitsPrintParameter parameter=NULL) |
[UNIX only] Set memory limit. More... | |
bool | SetMemoryLimitSoft (size_t max_size, TLimitsPrintHandler handler=NULL, TLimitsPrintParameter parameter=NULL) |
[UNIX only] Set soft memory limit. More... | |
bool | SetMemoryLimitHard (size_t max_size, TLimitsPrintHandler handler=NULL, TLimitsPrintParameter parameter=NULL) |
[UNIX only] Set hard memory limit. More... | |
size_t | GetVirtualMemoryLimitSoft (void) |
[UNIX only] Get "soft" memory limit of the virtual memory (address space) in bytes for a current process. More... | |
size_t | GetVirtualMemoryLimitHard (void) |
[UNIX only] Get "hard" memory limit of the virtual memory (address space) in bytes for a current process. More... | |
bool | SetCpuTimeLimit (unsigned int max_cpu_time, unsigned int terminate_delay_time, TLimitsPrintHandler handler=NULL, TLimitsPrintParameter parameter=NULL) |
[UNIX only] Set CPU time usage limit. More... | |
bool | VerifyCpuCompatibility (string *message=nullptr) |
Verify that the CPU, where an application run, is compatible with flags it compiled for. More... | |
string | GetProcessUserName (void) |
System/memory information (deprecated, please use CSystemInfo class) More... | |
unsigned int | GetCpuCount (void) |
Return number of active CPUs (never less than 1). More... | |
unsigned long | GetVirtualMemoryPageSize (void) |
Return virtual memory page size. More... | |
unsigned long | GetVirtualMemoryAllocationGranularity (void) |
Return size of an allocation unit (usually it is a multiple of page size). More... | |
Uint8 | GetPhysicalMemorySize (void) |
Return the amount of physical memory available in the system. More... | |
bool | GetMemoryUsage (size_t *total, size_t *resident, size_t *shared) |
bool | GetCurrentProcessTimes (double *user_time, double *system_time) |
int | GetProcessFDCount (int *soft_limit=NULL, int *hard_limit=NULL) |
int | GetProcessThreadCount (void) |
[Linux only] Provides the number of threads in the current process. More... | |
bool | MemoryAdvise (void *addr, size_t len, EMemoryAdvise advise) |
[UNIX only] Advise on memory usage for specified memory region. More... | |
void | SleepSec (unsigned long sec, EInterruptOnSignal onsignal=eRestartOnSignal) |
Sleep. More... | |
void | SleepMilliSec (unsigned long ml_sec, EInterruptOnSignal onsignal=eRestartOnSignal) |
void | SleepMicroSec (unsigned long mc_sec, EInterruptOnSignal onsignal=eRestartOnSignal) |
void | SuppressSystemMessageBox (TSuppressSystemMessageBox mode=fSuppress_Default) |
Suppress popup messages on execution errors. More... | |
void | DisableSuppressSystemMessageBox () |
Prevent run of SuppressSystemMessageBox(). More... | |
bool | IsSuppressedDebugSystemMessageBox () |
Check if system message box has been suppressed for debug library. More... | |
typedef void(* TLimitsPrintHandler) (ELimitsExitCode, size_t, CTime &, TLimitsPrintParameter) |
Type of handler for printing a dump information after generating any limitation event.
Definition at line 84 of file ncbi_system.hpp.
typedef void* TLimitsPrintParameter |
Type of parameter for print handler.
Definition at line 70 of file ncbi_system.hpp.
typedef int TSuppressSystemMessageBox |
Binary OR of "ESuppressSystemMessageBox".
Definition at line 591 of file ncbi_system.hpp.
enum ELimitsExitCode |
Process limits.
If, during the program execution, the process exceed any from limits (see ELimitsExitCodeMemory) then: 1) Dump info about current program's state to log-stream.
Enumerator | |
---|---|
eLEC_None | Normal exit. |
eLEC_Memory | Memory limit. |
eLEC_Cpu | CPU time usage limit. |
Definition at line 63 of file ncbi_system.hpp.
enum EMemoryAdvise |
Memory advise.
What type of data access pattern will be used for specified memory region.
Advises the VM system that the a certain region of memory will be accessed following a type of pattern. The VM system uses this information to optimize work with mapped memory.
NOTE: Works on UNIX platform only.
Definition at line 513 of file ncbi_system.hpp.
Suppress Diagnostic Popup Messages.
Suppress modes
Enumerator | |
---|---|
fSuppress_System | System errors. |
fSuppress_Runtime | Runtime library. |
fSuppress_Debug | Debug library. |
fSuppress_Exception | Unhandled exceptions. |
fSuppress_All | |
fSuppress_Default |
Definition at line 581 of file ncbi_system.hpp.
void DisableSuppressSystemMessageBox | ( | ) |
Prevent run of SuppressSystemMessageBox().
NOTE: MS Windows-specific. If this function is called, all following calls of SuppressSystemMessageBox() will be ignored. If SuppressSystemMessageBox() was executed before, that this function print out a critical error message. For example can be used in CGI applications where SuppressSystemMessageBox always calls in the CCgiApplication constructor.
Definition at line 1423 of file ncbi_system.cpp.
References Critical(), ERR_POST_X, s_DoneSuppressSystemMessageBox, and s_EnableSuppressSystemMessageBox.
|
inline |
Return number of active CPUs (never less than 1).
Definition at line 445 of file ncbi_system.hpp.
References CSystemInfo::GetCpuCount().
Referenced by CMapperMTArgs::ExtractAlgorithmOptions(), COMSSABase::SetThreadCount(), and CWriteDB_LMDB::x_CommitTransaction().
bool GetCurrentProcessTimes | ( | double * | user_time, |
double * | system_time | ||
) |
Definition at line 1032 of file ncbi_system.cpp.
References buf, CLOCKS_PER_SEC, and t.
bool GetMemoryUsage | ( | size_t * | total, |
size_t * | resident, | ||
size_t * | shared | ||
) |
Definition at line 926 of file ncbi_system.cpp.
References BOOL, CDll::eAutoUnload, CDll::eLoadNow, CNcbiError::eNotSupported, FAR, CDll::GetEntryPoint_Func(), CFile::GetLength(), CSystemInfo::GetVirtualMemoryPageSize(), HANDLE, len, CNcbiError::Set(), ncbi::grid::netcache::search::fields::size, and t.
Referenced by CCurrentProcess::GetMemoryUsage(), and CProcess::GetMemoryUsage().
|
inline |
Return the amount of physical memory available in the system.
Definition at line 469 of file ncbi_system.hpp.
References CSystemInfo::GetTotalPhysicalMemorySize().
Referenced by CContigAssembly::BandedGlobalAlignment().
Definition at line 1080 of file ncbi_system.cpp.
References NULL.
int GetProcessThreadCount | ( | void | ) |
[Linux only] Provides the number of threads in the current process.
Definition at line 1152 of file ncbi_system.cpp.
References NULL.
|
inline |
System/memory information (deprecated, please use CSystemInfo class)
Get process owner actual user name
Definition at line 437 of file ncbi_system.hpp.
References CSystemInfo::GetUserName().
|
inline |
Return size of an allocation unit (usually it is a multiple of page size).
Definition at line 461 of file ncbi_system.hpp.
References CSystemInfo::GetVirtualMemoryAllocationGranularity().
size_t GetVirtualMemoryLimitHard | ( | void | ) |
[UNIX only] Get "hard" memory limit of the virtual memory (address space) in bytes for a current process.
Definition at line 453 of file ncbi_system.cpp.
References CNcbiError::eNotSupported, CNcbiError::Set(), and CNcbiError::SetFromErrno().
size_t GetVirtualMemoryLimitSoft | ( | void | ) |
[UNIX only] Get "soft" memory limit of the virtual memory (address space) in bytes for a current process.
Definition at line 434 of file ncbi_system.cpp.
References CNcbiError::eNotSupported, CNcbiError::Set(), and CNcbiError::SetFromErrno().
|
inline |
Return virtual memory page size.
Definition at line 453 of file ncbi_system.hpp.
References CSystemInfo::GetVirtualMemoryPageSize().
bool IsSuppressedDebugSystemMessageBox | ( | ) |
Check if system message box has been suppressed for debug library.
NOTE: MS Windows-specific.
Definition at line 1434 of file ncbi_system.cpp.
References s_DoneSuppressSystemMessageBox, and s_SuppressedDebugSystemMessageBox.
Referenced by CNcbiDiag::DiagAssertIfSuppressedSystemMessageBox().
bool MemoryAdvise | ( | void * | addr, |
size_t | len, | ||
EMemoryAdvise | advise | ||
) |
[UNIX only] Advise on memory usage for specified memory region.
addr | Address of memory region whose usage is being advised. Some implementation requires that the address start be page-aligned. |
len | Length of memory region whose usage is being advised. |
advise | Advise on expected memory usage pattern. |
Definition at line 1188 of file ncbi_system.cpp.
References _T_STDSTRING, _TROUBLE, CNcbiError::eBadAddress, eMADV_DoFork, eMADV_DontFork, eMADV_DontNeed, eMADV_Mergeable, eMADV_Normal, eMADV_Random, eMADV_Sequential, eMADV_Unmergeable, eMADV_WillNeed, CNcbiError::eNotSupported, ERR_POST_X, ERR_POST_X_ONCE, len, NcbiSys_strerror, CNcbiError::Set(), CNcbiError::SetErrno(), and Warning().
Referenced by CMemoryFile_Base::MemMapAdviseAddr().
bool SetCpuTimeLimit | ( | unsigned int | max_cpu_time, |
unsigned int | terminate_delay_time, | ||
TLimitsPrintHandler | handler = NULL , |
||
TLimitsPrintParameter | parameter = NULL |
||
) |
[UNIX only] Set CPU time usage limit.
Set the limit for the CPU time that can be consumed by current process.
max_cpu_time | The maximal amount of seconds of CPU time can be consumed by the process. The 0 value lifts off the CPU time restrictions if allowed to do so. For multi-threaded applications this can be a sum of time for all threads (OS dependent). |
terminate_delay_time | The time in seconds that the process will have to terminate itself after receiving a signal about exceeding CPU usage limit. After that it can be killed by OS. |
handler | Pointer to a print handler used for dump output in the case of reaching CPU usage limit. Use default handler if passed as NULL. Note, that default handler is not async-safe (see attention below), and can lead to coredump and application crash instead of program termination, so use it on your own risk. |
parameter | Parameter carried into the print handler. Can be passed as NULL. |
Definition at line 534 of file ncbi_system.cpp.
References s_CpuTimeLimit, s_SetPrintHandler(), and s_SignalHandler().
Referenced by CNcbiApplicationAPI::x_HonorStandardSettings().
bool SetMemoryLimit | ( | size_t | max_size, |
TLimitsPrintHandler | handler = NULL , |
||
TLimitsPrintParameter | parameter = NULL |
||
) |
[UNIX only] Set memory limit.
Set the limit for the size of used memory allocated by the process.
max_size | The maximal amount of memory in bytes that can be allocated by the process. Use the same limits for process's data segment (including heap) and virtual memory (address space). On 32-bit systems limit is at most 2 GiB, or this resource is unlimited. The 0 value lift off the heap restrictions. This value cannot exceed current hard limit set for the process. |
handler | Pointer to a print handler used for dump output in the case of reaching memory limit. Use default handler if passed as NULL. |
parameter | Parameter carried into the print handler. Can be passed as NULL. Useful if singular handler is used for setting some limits. See also SetCpuTimeLimit(). |
Definition at line 282 of file ncbi_system.cpp.
References s_MemoryLimitHard, s_MemoryLimitSoft, s_NewHandler(), s_SetPrintHandler(), and CNcbiError::SetFromErrno().
Referenced by CNcbiApplicationAPI::x_HonorStandardSettings().
bool SetMemoryLimitHard | ( | size_t | max_size, |
TLimitsPrintHandler | handler = NULL , |
||
TLimitsPrintParameter | parameter = NULL |
||
) |
[UNIX only] Set hard memory limit.
Definition at line 369 of file ncbi_system.cpp.
References s_MemoryLimitHard, s_MemoryLimitSoft, s_NewHandler(), s_SetPrintHandler(), and CNcbiError::SetFromErrno().
bool SetMemoryLimitSoft | ( | size_t | max_size, |
TLimitsPrintHandler | handler = NULL , |
||
TLimitsPrintParameter | parameter = NULL |
||
) |
[UNIX only] Set soft memory limit.
Definition at line 322 of file ncbi_system.cpp.
References s_MemoryLimitSoft, s_NewHandler(), s_SetPrintHandler(), and CNcbiError::SetFromErrno().
void SleepMicroSec | ( | unsigned long | mc_sec, |
EInterruptOnSignal | onsignal = eRestartOnSignal |
||
) |
Definition at line 1266 of file ncbi_system.cpp.
References eInterruptOnSignal, kMicroSecondsPerSecond, kMilliSecondsPerSecond, and kNanoSecondsPerSecond.
Referenced by CRequestRateControl::Sleep(), SleepMilliSec(), SleepSec(), CReader::WaitBeforeNewConnection(), CReader::x_AllocConnection(), CRPCClient_Base::x_Ask(), and CSnpPtisClient_Impl::x_GetPrimarySnpTrack().
void SleepMilliSec | ( | unsigned long | ml_sec, |
EInterruptOnSignal | onsignal = eRestartOnSignal |
||
) |
Definition at line 1323 of file ncbi_system.cpp.
References kMicroSecondsPerSecond, kMilliSecondsPerSecond, and SleepMicroSec().
Referenced by CEutilsClient::CallWithRetry(), CPSGDataLoader_Impl::CallWithRetry(), CallWithRetry(), CCSRADataLoader_Impl::CallWithRetry(), CSNPDataLoader_Impl::CallWithRetry(), CVDBGraphDataLoader_Impl::CallWithRetry(), CWGSDataLoader_Impl::CallWithRetry(), CGridCommandLineInterfaceApp::Cmd_Suspend(), SNetServerImpl::ConnectAndExec(), CBamUtils::CreateCoverageGraphs(), CServiceDiscovery::DiscoverImpl(), CLockVectorGuard< TLockVect >::DoLock(), CPipe::ExecWait(), CTestThread::GlobalSyncPoint(), SNetServiceImpl::IterateUntilExecOK(), CProcess::Kill(), CProcess::KillGroupById(), CNamedPipeHandle::Listen(), CInterProcessLock::Lock(), CWeakExecuteGuard::Lock(), CMainLoopThread::Main(), SGridWorkerNodeImpl::OfflineRun(), CAppJobDispatcher::OnEngineJobStateChanged(), CNamedPipeHandle::Open(), SRetryProcessing::operator()(), CObjectManagerEngine::PrefetchNotify(), CGridCgiApplication::ProcessRequest(), CPipeHandle::Read(), CProjectServiceTestJob::Run(), CPrimeNumbersJob::Run(), CPeriodicTestJob::Run(), CGetAssembliesJob::Run(), CSeqDBDemo_Threaded::Run(), SGridWorkerNodeImpl::Run(), CAppJobTestApplication::Run(), CGridClientSampleApp::Run(), CSampleNetScheduleClient::Run(), CSampleNetScheduleNode::Run(), CRemoteAppClientSampleApp::Run(), s_ConnectToNamedPipe(), s_GetObject(), s_PeekStdin(), s_ProcessErrorCode(), CPrimeNumberClient::StartJobs(), CThreadGroup::SyncPoint(), CExec::Wait(), CProcess::Wait(), CThread::WaitForAllThreads(), CNamedPipeHandle::Write(), CPipeHandle::Write(), CThreadPoolEngine::x_OnTaskStatusChange(), CPipeHandle::x_Poll(), CNSTDatabase::x_PreCheckConnection(), CAppJobDispatcher::x_StartJob(), CNamedPipeHandle::x_WaitForRead(), and CAsyncWriteCache::~CAsyncWriteCache().
void SleepSec | ( | unsigned long | sec, |
EInterruptOnSignal | onsignal = eRestartOnSignal |
||
) |
Sleep.
Suspend execution for a time.
Sleep for at least the specified number of microsec/millisec/seconds. Time slice restrictions are imposed by platform/OS. On UNIX the sleep can be interrupted by a signal. Sleep*Sec(0) have no effect (but may cause context switches).
[UNIX & Windows]
Definition at line 1333 of file ncbi_system.cpp.
References kMicroSecondsPerSecond, and SleepMicroSec().
Referenced by BOOST_AUTO_TEST_CASE(), CheckWrittenFile(), CSampleJob::Do(), CEUtilsUpdater::DoPubSearch(), fta_get_gi_for_seq_id(), CGenomicCollectionsService::GetEquivalentAssemblies(), CPMCIDConverterServer::GetPmids(), CFastCgiMTSampleRequestProcessor::ProcessRequest(), PromoteIfDifferent(), CSampleIdleTask::Run(), SGridWorkerNodeImpl::Run(), CDemoApp::Run(), CHydraServer::RunHydraSearch(), fix_pub::s_GetESearchIds(), fix_pub::s_IsIndexed(), CRequestRateControl::Sleep(), TestDelay(), CEUtilsGeneric::TryQuery(), CGenomicCollectionsService::ValidateChrType(), CRPCClient_Base::x_Ask(), CRemoteBlast::x_CheckResults(), CRemoteBlast::x_CheckResultsDC(), CGenomicCollectionsService::x_FindAssembliesBySequences(), CMainLoopThread::x_GetNextJob(), CRemoteBlast::x_PollUntilDone(), and FileMessenger::~FileMessenger().
void SuppressSystemMessageBox | ( | TSuppressSystemMessageBox | mode = fSuppress_Default | ) |
Suppress popup messages on execution errors.
NOTE: MS Windows-specific. Suppresses all error message boxes in both runtime and in debug libraries, as well as all General Protection Fault messages.
Definition at line 1383 of file ncbi_system.cpp.
References _SEH_Handler(), fSuppress_Debug, fSuppress_Exception, fSuppress_Runtime, fSuppress_System, s_DoneSuppressSystemMessageBox, s_EnableSuppressSystemMessageBox, and s_SuppressedDebugSystemMessageBox.
Referenced by CNcbiApplicationAPI::AppMain(), CCgiApplication::CCgiApplication(), InitDiagHandler(), main(), and CNcbiTestApplication::x_SetupBoostReporters().
Verify that the CPU, where an application run, is compatible with flags it compiled for.
Right now it checks on SSE 4.2 only.
message | Optional pointer to a string that will receive a description of the problem if function returns FALSE. |
Verify that the CPU, where an application run, is compatible with flags it compiled for.
Definition at line 1453 of file ncbi_system.cpp.
Referenced by CNcbiApplicationAPI::CNcbiApplicationAPI(), and CNcbiApplicationAPI::x_TryInit().