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);
|
long page_size = sysconf(_SC_PAGESIZE);
|
||||||
|
|
||||||
std::ifstream file("/proc/self/statm");
|
std::ifstream file("/proc/self/statm");
|
||||||
file.ignore(std::numeric_limits<std::streamsize>::max(), ' ');
|
if (file)
|
||||||
uint64 no_pages;
|
{
|
||||||
file >> no_pages;
|
file.ignore(std::numeric_limits<std::streamsize>::max(), ' ');
|
||||||
|
uint64 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,18 +40,25 @@ 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");
|
||||||
file.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
|
if (file)
|
||||||
|
|
||||||
for (auto i = 0; i < count; ++i)
|
|
||||||
{
|
{
|
||||||
uint64 user, nice, kernel, idle;
|
|
||||||
file.ignore(std::numeric_limits<std::streamsize>::max(), ' ');
|
|
||||||
file >> user >> nice >> kernel >> idle;
|
|
||||||
file.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
|
file.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
|
||||||
|
|
||||||
out[i].idle = idle;
|
for (auto i = 0; i < count; ++i)
|
||||||
out[i].kernel = kernel;
|
{
|
||||||
out[i].user = user + nice;
|
uint64 user, nice, kernel, idle;
|
||||||
|
file.ignore(std::numeric_limits<std::streamsize>::max(), ' ');
|
||||||
|
file >> user >> nice >> kernel >> idle;
|
||||||
|
file.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
|
||||||
|
|
||||||
|
out[i].idle = idle;
|
||||||
|
out[i].kernel = kernel;
|
||||||
|
out[i].user = user + nice;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (auto i = 0; i < count; ++i) out[i] = { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue