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

ircd::prof: Add a higher resolution syscall timer.

This commit is contained in:
Jason Volk 2019-04-25 21:09:50 -07:00
parent 30b59f4736
commit cfe4807b77
2 changed files with 47 additions and 0 deletions

View file

@ -106,6 +106,8 @@ struct ircd::prof::vg::disable
/// which returns the value of at() as well.
struct ircd::prof::syscall_timer
{
struct high_resolution;
uint64_t started, stopped;
public:
@ -115,6 +117,21 @@ struct ircd::prof::syscall_timer
syscall_timer() noexcept;
};
/// This is a higher resolution alternative. The sample may be conducted
/// with getrusage() or perf events; the exact method is TBD and may be
/// expensive/intrusive. This device should be used temporarily by developers
/// and not left in place in committed code.
struct ircd::prof::syscall_timer::high_resolution
{
uint64_t started, stopped;
public:
uint64_t at() const;
uint64_t sample();
high_resolution() noexcept;
};
/// Frontend to times(2). This has low resolution in practice, but it's
/// very cheap as far as syscalls go; x-platform implementation courtesy
/// of boost::chrono.

View file

@ -316,6 +316,36 @@ const
return stopped - started;
}
//
// syscall_timer::high_resolution
//
ircd::prof::syscall_timer::high_resolution::high_resolution()
noexcept
:started
{
resource(prof::sample).at(resource::TIME_KERN)
}
,stopped
{
0UL
}
{
}
uint64_t
ircd::prof::syscall_timer::high_resolution::sample()
{
stopped = resource(prof::sample).at(resource::TIME_KERN);
return at();
}
uint64_t
ircd::prof::syscall_timer::high_resolution::at()
const
{
return stopped - started;
}
//
// time_*() suite