A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://www.ncbi.nlm.nih.gov/IEB/ToolBox/CPP_DOC/doxyhtml/ncbi__system_8cpp.html below:

NCBI C++ ToolKit: src/corelib/ncbi_system.cpp File Reference

#include <ncbi_pch.hpp>
#include <windows.h>
#include <crtdbg.h>
#include <stdlib.h>
#include <corelib/ncbimtx.hpp>
#include <corelib/ncbi_system.hpp>
#include <corelib/ncbi_safe_static.hpp>
#include <corelib/error_codes.hpp>
#include <corelib/ncbierror.hpp>
#include "ncbisys.hpp"
#include <array>
#include <sys/mman.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/times.h>
#include <sys/types.h>
#include <dirent.h>
#include <limits.h>
#include <time.h>
#include <unistd.h>
#include <fcntl.h>
#include "ncbi_os_unix_p.hpp"
#include <signal.h>
#include <corelib/ncbidll.hpp>
#include "ncbi_os_mswin_p.hpp"
#include <dbghelp.h>
#include <intrin.h>

Go to the source code of this file.

Go to the SVN repository for this file.

static void  s_DefaultPrintHandler (void)   static void  s_HandlerGuard (void)   static void  s_SignalHandler (int sig)     DEFINE_STATIC_FAST_MUTEX (s_Limits_Handler_Mutex)   static void  s_SetPrintHandler (TLimitsPrintHandler handler, TLimitsPrintParameter parameter)   static void  s_NewHandler (void)   bool  SetMemoryLimit (size_t max_size, TLimitsPrintHandler handler, TLimitsPrintParameter parameter)   [UNIX only] Set memory limit. More...
  bool  SetMemoryLimitSoft (size_t max_size, TLimitsPrintHandler handler, TLimitsPrintParameter parameter)   [UNIX only] Set soft memory limit. More...
  bool  SetMemoryLimitHard (size_t max_size, TLimitsPrintHandler handler, TLimitsPrintParameter parameter)   [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, TLimitsPrintParameter parameter)   [UNIX only] Set CPU time usage limit. 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, int *hard_limit)   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  SleepMicroSec (unsigned long mc_sec, EInterruptOnSignal onsignal)   void  SleepMilliSec (unsigned long ml_sec, EInterruptOnSignal onsignal)   void  SleepSec (unsigned long sec, EInterruptOnSignal onsignal)   Sleep. More...
  static LONG CALLBACK  _SEH_Handler (EXCEPTION_POINTERS *ep)   void  SuppressSystemMessageBox (TSuppressSystemMessageBox mode)   Suppress popup messages on execution errors. More...
  void  DisableSuppressSystemMessageBox (void)   Prevent run of SuppressSystemMessageBox(). More...
  bool  IsSuppressedDebugSystemMessageBox (void)   Check if system message box has been suppressed for debug library. More...
  bool  VerifyCpuCompatibility (string *message)   CPU. More...
  ◆ HAVE_MADVISE ◆ NCBI_USE_ERRCODE_X #define NCBI_USE_ERRCODE_X   Corelib_System

Definition at line 48 of file ncbi_system.cpp.

◆ USE_SETCPULIMIT ◆ USE_SETLIMITS ◆ USE_SETMEMLIMIT ◆ _SEH_Handler() ◆ DEFINE_STATIC_FAST_MUTEX() DEFINE_STATIC_FAST_MUTEX ( s_Limits_Handler_Mutex  ) ◆ DisableSuppressSystemMessageBox() void DisableSuppressSystemMessageBox ( ) ◆ GetCurrentProcessTimes() bool GetCurrentProcessTimes ( double *  user_time, double *  system_time  ) ◆ GetMemoryUsage() bool GetMemoryUsage ( size_t *  total, size_t *  resident, size_t *  shared  )
Deprecated:
Please use C[Current]Process::GetMemoryUsage()

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().

◆ GetProcessFDCount() int GetProcessFDCount ( intsoft_limit, inthard_limit  ) ◆ GetProcessThreadCount() int GetProcessThreadCount ( void  ) ◆ GetVirtualMemoryLimitHard() size_t GetVirtualMemoryLimitHard ( void  )

[UNIX only] Get "hard" memory limit of the virtual memory (address space) in bytes for a current process.

Returns
Returns "hard" value set by setrlimit(), SetMemoryLimit() or ulimit command line utility for virtual memory address space. 0 - if an error occurs and CNcbiError is set, or the memory limit is set to "unlimited".
Note
The implementation of malloc() can be different on many flavors of UNIX, and we usually don't know how exactly it is implemented on the current system. Some systems use sbrk()-based implementation (heap), other use mmap() system call and virtual memory (address space) to allocate memory, some other use hybrid approach and may allocate memory in two different ways depending on requested memory size and certain parameters. Almost all modern Unix versions uses mmap()-based approach for all memory allocations or at least for big chunks of memory, so probably virtual memory limits is more important nowadays.
See also
SetMemoryLimit, GetVirtualMemoryLimitSoft

Definition at line 453 of file ncbi_system.cpp.

References CNcbiError::eNotSupported, CNcbiError::Set(), and CNcbiError::SetFromErrno().

◆ GetVirtualMemoryLimitSoft() size_t GetVirtualMemoryLimitSoft ( void  )

[UNIX only] Get "soft" memory limit of the virtual memory (address space) in bytes for a current process.

Returns
Returns "soft" value set by setrlimit(), SetMemoryLimit() or ulimit command line utility for virtual memory address space. 0 - if an error occurs and CNcbiError is set, or the memory limit is set to "unlimited".
Note
The implementation of malloc() can be different on many flavors of UNIX, and we usually don't know how exactly it is implemented on the current system. Some systems use sbrk()-based implementation (heap), other use mmap() system call and virtual memory (address space) to allocate memory, some other use hybrid approach and may allocate memory in two different ways depending on requested memory size and certain parameters. Almost all modern Unix versions uses mmap()-based approach for all memory allocations or at least for big chunks of memory, so probably virtual memory limits is more important nowadays.
See also
SetMemoryLimit, GetVirtualMemoryLimitHard

Definition at line 434 of file ncbi_system.cpp.

References CNcbiError::eNotSupported, CNcbiError::Set(), and CNcbiError::SetFromErrno().

◆ IsSuppressedDebugSystemMessageBox() bool IsSuppressedDebugSystemMessageBox ( ) ◆ MemoryAdvise()

[UNIX only] Advise on memory usage for specified memory region.

Parameters
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.
Returns
See also
EMemoryAdvise

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().

◆ s_DefaultPrintHandler() static void s_DefaultPrintHandler ( void  ) static ◆ s_HandlerGuard() static void s_HandlerGuard ( void  ) static

Definition at line 201 of file ncbi_system.cpp.

References eLEC_Cpu, eLEC_Memory, s_CpuTimeLimit, s_DefaultPrintHandler(), s_IsHandlerActive, s_MemoryLimitSoft, s_PrintHandler, s_PrintHandlerParam, s_Reason, s_ReservedMemory, and s_TimeSet.

Referenced by s_NewHandler(), and s_SignalHandler().

◆ s_NewHandler() static void s_NewHandler ( void  ) static ◆ s_SetPrintHandler() ◆ s_SignalHandler() ◆ SetCpuTimeLimit()

[UNIX only] Set CPU time usage limit.

Set the limit for the CPU time that can be consumed by current process.

Parameters
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.
Returns
Completion status.
Note
Setting a low CPU time limit cannot be generally undone to a value higher than "max_cpu_time + terminate_delay_time" at a later time.
Attention
The exit print handler can be registered only once at first call to SetCpuTimeLimit() or SetMemoryLimit(), even if you don't specify handler directly and passed it as NULL! Be aware. All subsequent attempts to set new handler will be ignored, but limits will be changed anyway.
Only async-safe library functions and system calls can be used in the print handler. For example, you cannot use C++ streams (cout/cerr) and printf() calls here, but write() is allowed... You can find a list of such functions in the C++ documentation (see man, Internet and etc). Also, avoid to alter any shared (global) variables, except that are declared to be of storage class and type "volatile sig_atomic_t".
See also
SetMemoryLimit, TLimitsPrintHandler

Definition at line 534 of file ncbi_system.cpp.

References s_CpuTimeLimit, s_SetPrintHandler(), and s_SignalHandler().

Referenced by CNcbiApplicationAPI::x_HonorStandardSettings().

◆ SetMemoryLimit()

[UNIX only] Set memory limit.

Set the limit for the size of used memory allocated by the process.

Parameters
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().
Returns
Completion status. It returns TRUE if both, the memory limits for the data segment and virtual memory, limitations were set. It can return FALSE if the limits for the data segment has changed, but setting new values for the virtual memory fails.
Note
By default it sets soft and hard memory limits to the same value.
Setting a limits may not work on some systems, depends on OS, compilation options and etc. Some systems enforce memory limits, other didn't. Also, only privileged process can set hard memory limit.
If the memory limit is reached, any subsequent memory allocations fails.
Attention
The exit print handler can be registered only once at first call to SetCpuTimeLimit() or SetMemoryLimit(), even if you don't specify handler directly and passed it as NULL. Be aware. All subsequent attempts to set new handler will be ignored, but limits will be changed anyway.
if you use std::set_new_handler(), it should be called after SetMemoryLimit(). It override any memory related print handler set previously.
See also
SetCpuTimeLimit, TLimitsPrintHandler, SetMemoryLimitSoft, SetMemoryLimitHard

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().

◆ SetMemoryLimitHard() ◆ SetMemoryLimitSoft() ◆ SleepMicroSec() ◆ SleepMilliSec()

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(), s_SimulateDelay(), 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().

◆ SleepSec()

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().

◆ SuppressSystemMessageBox()

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().

◆ VerifyCpuCompatibility() ◆ s_CpuTimeLimit size_t s_CpuTimeLimit = 0 static ◆ s_DoneSuppressSystemMessageBox ◆ s_EnableSuppressSystemMessageBox bool s_EnableSuppressSystemMessageBox = true static ◆ s_IsHandlerActive std::atomic<bool> s_IsHandlerActive { false } ◆ s_IsHandlerSet ◆ s_MemoryLimitHard size_t s_MemoryLimitHard = 0 static ◆ s_MemoryLimitSoft size_t s_MemoryLimitSoft = 0 static ◆ s_PrintHandler ◆ s_PrintHandlerParam ◆ s_Reason ◆ s_ReservedMemory ◆ s_SuppressedDebugSystemMessageBox bool s_SuppressedDebugSystemMessageBox = false static ◆ s_TimeSet

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4