17 # pragma warning( disable : 2259 )
23 #if defined( __linux__ ) or defined( __APPLE__ )
26 # include <sys/signal.h>
27 # include <sys/syscall.h>
29 # include <sys/procfs.h>
209 unsigned long flags{ 0 };
210 unsigned long minflt{ 0 };
212 unsigned long majflt{ 0 };
214 unsigned long utime{ 0 };
215 unsigned long stime{ 0 };
223 unsigned long vsize{ 0 };
225 unsigned long rlim{ 0 };
231 unsigned long signal{ 0 };
235 unsigned long wchan{ 0 };
237 #endif // __linux__ or __APPLE__
246 #if defined( __linux__ ) or defined( __APPLE__ )
249 const auto fname =
"/proc/" + std::to_string( getpid() ) +
"/stat";
252 std::cerr <<
"ProcStats : Failed to open " << fname << std::endl;
256 #endif // __linux__ or __APPLE__
260 if ( !
m_valid ) {
return false; }
262 std::scoped_lock lock{
m_mutex };
264 #if defined( __linux__ ) or defined( __APPLE__ )
266 auto read_proc = [&]() {
271 m_ufd.lseek( 0, SEEK_SET );
272 if ( ( cnt =
m_ufd.read( buf,
sizeof( buf ) ) ) < 0 ) { ok =
false; }
274 buf[std::min(
static_cast<std::size_t
>( cnt ),
sizeof( buf ) - 1 )] =
'\0';
279 "%d %s %c %d %d %d %d %d %lu %lu %lu %lu %lu %lu %lu %ld %ld %ld %ld %ld %ld %llu %lu %ld %lu %lu %lu %lu "
280 "%lu %lu %lu %lu %lu %lu %lu",
288 const auto pr_size =
static_cast<double>( pinfo.
vsize );
289 const auto pr_rssize =
static_cast<double>( pinfo.
rss );
290 constexpr
double MB = 1.0 / ( 1024 * 1024 );
293 if ( 0 == pinfo.
vsize ) { ok =
false; }
299 if ( !read_proc() ) {
300 std::cerr <<
"ProcStats : -> Problems reading proc file. Will try reopening..." << std::endl;
302 if ( !read_proc() ) {
return false; }
309 #endif // __linux__ or __APPLE__