0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-10 22:18:54 +02:00

ircd::prof::psi: Add interface to poll for PSI linux>=5.2. (#144)

This commit is contained in:
Jason Volk 2020-05-08 17:58:49 -07:00
parent a0476b8a9c
commit 05e384d315
3 changed files with 72 additions and 3 deletions

View file

@ -17,8 +17,12 @@ namespace ircd::prof::psi
struct metric;
struct refresh;
// Read and update the referenced extern.
bool refresh(file &) noexcept;
// Yield ircd::ctx until event; returns unrefreshed
file &wait();
extern const bool supported;
extern file cpu, mem, io;
}

View file

@ -188,6 +188,47 @@ ircd::prof::psi::io
// prof::psi::metric::refresh
//
ircd::prof::psi::file &
ircd::prof::psi::wait()
try
{
const fs::fd fd[3]
{
{ "/proc/pressure/cpu", std::ios::in },
{ "/proc/pressure/memory", std::ios::in },
{ "/proc/pressure/io", std::ios::in },
};
const size_t n
{
fs::select(fd)
};
switch(n)
{
case 0: return cpu;
case 1: return mem;
case 2: return io;
default:
always_assert(false);
__builtin_unreachable();
}
}
catch(const ctx::interrupted &)
{
throw;
}
catch(const std::exception &e)
{
log::error
{
"Failed to poll pressure stall information :%s",
e.what(),
};
throw;
}
bool
ircd::prof::psi::refresh(file &file)
noexcept try

View file

@ -1278,9 +1278,33 @@ console_cmd__prof__psi(opt &out, const string_view &line)
out << std::endl;
}};
show_file("cpu", prof::psi::cpu);
show_file("mem", prof::psi::mem);
show_file("io ", prof::psi::io);
const params param{line, " ",
{
"file",
}};
string_view filename
{
param["file"]
};
if(filename == "wait")
{
auto &file(prof::psi::wait());
out << "Got: " << file.name;
out << std::endl << std::endl;
filename = file.name;
}
if(!filename || filename == "cpu")
show_file("cpu", prof::psi::cpu);
if(!filename || filename == "mem")
show_file("mem", prof::psi::mem);
if(!filename || filename == "io")
show_file("io ", prof::psi::io);
return true;
}