diff --git a/include/ircd/prof.h b/include/ircd/prof.h index c5c313e03..d4d9e8df4 100644 --- a/include/ircd/prof.h +++ b/include/ircd/prof.h @@ -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 +{ + 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{{0}} + {} +}; + struct ircd::prof::system :std::array, 7> { diff --git a/ircd/prof.cc b/ircd/prof.cc index 4849f8eb9..a92a375c8 100644 --- a/ircd/prof.cc +++ b/ircd/prof.cc @@ -11,6 +11,7 @@ #include #include #include @@ -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{}); + 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{}); + 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 //