mirror of
https://github.com/cemu-project/Cemu.git
synced 2025-07-07 23:41:18 +12:00
Add check to std::ifstream.
This commit is contained in:
parent
1b88a5d149
commit
5c058ac6dd
1 changed files with 27 additions and 13 deletions
|
@ -12,11 +12,18 @@ uint64 QueryRamUsage()
|
|||
long page_size = sysconf(_SC_PAGESIZE);
|
||||
|
||||
std::ifstream file("/proc/self/statm");
|
||||
if (file)
|
||||
{
|
||||
file.ignore(std::numeric_limits<std::streamsize>::max(), ' ');
|
||||
uint64 no_pages;
|
||||
file >> no_pages;
|
||||
|
||||
return no_pages * page_size;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void QueryProcTime(uint64 &out_now, uint64 &out_user, uint64 &out_kernel)
|
||||
|
@ -33,6 +40,8 @@ void QueryProcTime(uint64 &out_now, uint64 &out_user, uint64 &out_kernel)
|
|||
void QueryCoreTimes(uint32 count, ProcessorTime out[])
|
||||
{
|
||||
std::ifstream file("/proc/stat");
|
||||
if (file)
|
||||
{
|
||||
file.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
|
||||
|
||||
for (auto i = 0; i < count; ++i)
|
||||
|
@ -46,6 +55,11 @@ void QueryCoreTimes(uint32 count, ProcessorTime out[])
|
|||
out[i].kernel = kernel;
|
||||
out[i].user = user + nice;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (auto i = 0; i < count; ++i) out[i] = { }
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue