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,12 +12,19 @@ uint64 QueryRamUsage()
|
||||||
long page_size = sysconf(_SC_PAGESIZE);
|
long page_size = sysconf(_SC_PAGESIZE);
|
||||||
|
|
||||||
std::ifstream file("/proc/self/statm");
|
std::ifstream file("/proc/self/statm");
|
||||||
|
if (file)
|
||||||
|
{
|
||||||
file.ignore(std::numeric_limits<std::streamsize>::max(), ' ');
|
file.ignore(std::numeric_limits<std::streamsize>::max(), ' ');
|
||||||
uint64 no_pages;
|
uint64 no_pages;
|
||||||
file >> no_pages;
|
file >> no_pages;
|
||||||
|
|
||||||
return no_pages * page_size;
|
return no_pages * page_size;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void QueryProcTime(uint64 &out_now, uint64 &out_user, uint64 &out_kernel)
|
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[])
|
void QueryCoreTimes(uint32 count, ProcessorTime out[])
|
||||||
{
|
{
|
||||||
std::ifstream file("/proc/stat");
|
std::ifstream file("/proc/stat");
|
||||||
|
if (file)
|
||||||
|
{
|
||||||
file.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
|
file.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
|
||||||
|
|
||||||
for (auto i = 0; i < count; ++i)
|
for (auto i = 0; i < count; ++i)
|
||||||
|
@ -47,5 +56,10 @@ void QueryCoreTimes(uint32 count, ProcessorTime out[])
|
||||||
out[i].user = user + nice;
|
out[i].user = user + nice;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (auto i = 0; i < count; ++i) out[i] = { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
Add table
Add a link
Reference in a new issue