mirror of
https://github.com/matrix-construct/construct
synced 2024-11-29 10:12:39 +01:00
ircd::prof: Add an rusage based profile object.
This commit is contained in:
parent
ab6cf110d5
commit
e752273462
2 changed files with 91 additions and 0 deletions
|
@ -18,6 +18,7 @@ namespace ircd::prof
|
|||
struct event;
|
||||
struct times;
|
||||
struct system;
|
||||
struct resource;
|
||||
enum dpl :uint8_t;
|
||||
enum counter :uint8_t;
|
||||
enum cacheop :uint8_t;
|
||||
|
@ -39,6 +40,11 @@ namespace ircd::prof
|
|||
system operator+(const system &a, const system &b);
|
||||
system operator-(const system &a, const system &b);
|
||||
|
||||
resource &operator+=(resource &a, const resource &b);
|
||||
resource &operator-=(resource &a, const resource &b);
|
||||
resource operator+(const resource &a, const resource &b);
|
||||
resource operator-(const resource &a, const resource &b);
|
||||
|
||||
// Control
|
||||
void stop(group &);
|
||||
void start(group &);
|
||||
|
@ -68,6 +74,28 @@ struct ircd::prof::times
|
|||
times() = default;
|
||||
};
|
||||
|
||||
struct ircd::prof::resource
|
||||
:std::array<uint64_t, 9>
|
||||
{
|
||||
enum
|
||||
{
|
||||
TIME_USER, // microseconds
|
||||
TIME_KERN, // microseconds
|
||||
RSS_MAX,
|
||||
PF_MINOR,
|
||||
PF_MAJOR,
|
||||
BLOCK_IN,
|
||||
BLOCK_OUT,
|
||||
SCHED_YIELD,
|
||||
SCHED_PREEMPT,
|
||||
};
|
||||
|
||||
resource(sample_t);
|
||||
resource()
|
||||
:std::array<uint64_t, 9>{{0}}
|
||||
{}
|
||||
};
|
||||
|
||||
struct ircd::prof::system
|
||||
:std::array<std::array<uint64_t, 2>, 7>
|
||||
{
|
||||
|
|
63
ircd/prof.cc
63
ircd/prof.cc
|
@ -11,6 +11,7 @@
|
|||
#include <RB_INC_SYS_SYSCALL_H
|
||||
#include <RB_INC_SYS_IOCTL_H
|
||||
#include <RB_INC_SYS_MMAN_H
|
||||
#include <RB_INC_SYS_RESOURCE_H
|
||||
#include <linux/perf_event.h>
|
||||
#include <boost/chrono/chrono.hpp>
|
||||
#include <boost/chrono/process_cpu_clocks.hpp>
|
||||
|
@ -173,6 +174,68 @@ catch(const std::exception &e)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
//
|
||||
// resource
|
||||
//
|
||||
|
||||
ircd::prof::resource
|
||||
ircd::prof::operator-(const resource &a,
|
||||
const resource &b)
|
||||
{
|
||||
resource ret;
|
||||
std::transform(begin(a), end(a), begin(b), begin(ret), std::minus<resource::value_type>{});
|
||||
return ret;
|
||||
}
|
||||
|
||||
ircd::prof::resource
|
||||
ircd::prof::operator+(const resource &a,
|
||||
const resource &b)
|
||||
{
|
||||
resource ret;
|
||||
std::transform(begin(a), end(a), begin(b), begin(ret), std::plus<resource::value_type>{});
|
||||
return ret;
|
||||
}
|
||||
|
||||
ircd::prof::resource &
|
||||
ircd::prof::operator-=(resource &a,
|
||||
const resource &b)
|
||||
{
|
||||
for(size_t i(0); i < a.size(); ++i)
|
||||
a[i] -= b[i];
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
ircd::prof::resource &
|
||||
ircd::prof::operator+=(resource &a,
|
||||
const resource &b)
|
||||
{
|
||||
for(size_t i(0); i < a.size(); ++i)
|
||||
a[i] += b[i];
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
//
|
||||
// resource::resource
|
||||
//
|
||||
|
||||
ircd::prof::resource::resource(sample_t)
|
||||
{
|
||||
struct ::rusage ru;
|
||||
syscall(::getrusage, RUSAGE_SELF, &ru);
|
||||
|
||||
at(TIME_USER) = ru.ru_utime.tv_sec * 1000000UL + ru.ru_utime.tv_usec;
|
||||
at(TIME_KERN) = ru.ru_stime.tv_sec * 1000000UL + ru.ru_stime.tv_usec;
|
||||
at(RSS_MAX) = ru.ru_maxrss;
|
||||
at(PF_MINOR) = ru.ru_minflt;
|
||||
at(PF_MAJOR) = ru.ru_majflt;
|
||||
at(BLOCK_IN) = ru.ru_inblock;
|
||||
at(BLOCK_OUT) = ru.ru_oublock;
|
||||
at(SCHED_YIELD) = ru.ru_nvcsw;
|
||||
at(SCHED_PREEMPT) = ru.ru_nivcsw;
|
||||
}
|
||||
|
||||
//
|
||||
// system
|
||||
//
|
||||
|
|
Loading…
Reference in a new issue