The Gaudi Framework  master (9f3f8895)
Loading...
Searching...
No Matches
ProcStats Class Reference

#include </builds/gaudi/Gaudi/GaudiAud/src/ProcStats.h>

Public Member Functions

bool fetch (procInfo &fill_me)
 Fill fill_me with the current memory usage of this process.

Static Public Member Functions

static ProcStats * instance ()

Private Member Functions

 ProcStats ()=default

Detailed Description

Definition at line 27 of file ProcStats.h.

Constructor & Destructor Documentation

◆ ProcStats()

ProcStats::ProcStats ( )
privatedefault

Member Function Documentation

◆ fetch()

bool ProcStats::fetch ( procInfo & fill_me)

Fill fill_me with the current memory usage of this process.

Returns false (and leaves fill_me untouched) if the information could not be retrieved (e.g. unsupported platform).

Definition at line 27 of file ProcStats.cpp.

27 {
28 constexpr double MB = 1.0 / ( 1024 * 1024 );
29#if defined( __linux__ )
30 // see proc(5): /proc/self/statm is "size resident shared text lib data dt" in pages
31 // size and resident are identical to the vsize and rss fields of /proc/self/stat
32 std::ifstream statm{ "/proc/self/statm" };
33 unsigned long size = 0, resident = 0; // in pages
34 if ( !( statm >> size >> resident ) || size == 0 ) { return false; }
35 f.vsize = size * m_pageSize * MB;
36 f.rss = resident * m_pageSize * MB;
37 return true;
38#elif defined( __APPLE__ )
39 task_basic_info_64_data_t info;
40 mach_msg_type_number_t count = TASK_BASIC_INFO_64_COUNT;
41 if ( task_info( mach_task_self(), TASK_BASIC_INFO_64, reinterpret_cast<task_info_t>( &info ), &count ) !=
42 KERN_SUCCESS ) {
43 return false;
44 }
45 f.vsize = info.virtual_size * MB;
46 f.rss = info.resident_size * MB;
47 return true;
48#else
49 return false;
50#endif
51}
constexpr auto size(const T &, Args &&...) noexcept

◆ instance()

ProcStats * ProcStats::instance ( )
static

Definition at line 22 of file ProcStats.cpp.

22 {
23 static ProcStats inst{};
24 return &inst;
25}
ProcStats()=default

The documentation for this class was generated from the following files: