mirror of
https://github.com/matrix-construct/construct
synced 2025-02-16 16:50:12 +01:00
ircd::prof: Add a higher resolution syscall timer.
This commit is contained in:
parent
30b59f4736
commit
cfe4807b77
2 changed files with 47 additions and 0 deletions
|
@ -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.
|
||||
|
|
30
ircd/prof.cc
30
ircd/prof.cc
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue