mirror of
https://github.com/matrix-construct/construct
synced 2024-11-15 14:31:11 +01:00
ircd::perf: Start a perf profiling subsystem; move ctx::prof counter utils.
This commit is contained in:
parent
9b54f4e4a2
commit
403bf52867
9 changed files with 144 additions and 72 deletions
|
@ -118,6 +118,4 @@ namespace ircd
|
|||
|
||||
using ctx::critical_assertion;
|
||||
using ctx::critical_indicator;
|
||||
|
||||
using ctx::prof::cycles;
|
||||
}
|
||||
|
|
|
@ -32,12 +32,6 @@ namespace ircd::ctx::prof
|
|||
enum class event :uint8_t;
|
||||
struct ticker;
|
||||
|
||||
// util
|
||||
unsigned long long rdpmc(const uint &);
|
||||
unsigned long long rdtscp();
|
||||
unsigned long long rdtsc();
|
||||
uint64_t cycles();
|
||||
|
||||
string_view reflect(const event &);
|
||||
|
||||
// totals
|
||||
|
@ -101,59 +95,3 @@ struct ircd::ctx::prof::ticker
|
|||
// monotonic counters for events
|
||||
std::array<uint64_t, num_of<prof::event>()> event {{0}};
|
||||
};
|
||||
|
||||
inline uint64_t
|
||||
__attribute__((flatten, always_inline, gnu_inline, artificial))
|
||||
ircd::ctx::prof::cycles()
|
||||
{
|
||||
return rdtsc();
|
||||
}
|
||||
|
||||
#if defined(__x86_64__) || defined(__i386__)
|
||||
inline unsigned long long
|
||||
__attribute__((always_inline, gnu_inline, artificial))
|
||||
ircd::ctx::prof::rdtsc()
|
||||
{
|
||||
return __builtin_ia32_rdtsc();
|
||||
}
|
||||
#else
|
||||
inline unsigned long long
|
||||
ircd::ctx::prof::rdtsc()
|
||||
{
|
||||
static_assert(false, "TODO: Implement fallback here");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(__x86_64__) || defined(__i386__)
|
||||
inline unsigned long long
|
||||
__attribute__((always_inline, gnu_inline, artificial))
|
||||
ircd::ctx::prof::rdtscp()
|
||||
{
|
||||
uint32_t ia32_tsc_aux;
|
||||
return __builtin_ia32_rdtscp(&ia32_tsc_aux);
|
||||
}
|
||||
#else
|
||||
inline unsigned long long
|
||||
ircd::ctx::prof::rdtscp()
|
||||
{
|
||||
static_assert(false, "TODO: Implement fallback here");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(__x86_64__) || defined(__i386__)
|
||||
inline unsigned long long
|
||||
__attribute__((always_inline, gnu_inline, artificial))
|
||||
ircd::ctx::prof::rdpmc(const uint &c)
|
||||
{
|
||||
return __builtin_ia32_rdpmc(c);
|
||||
}
|
||||
#else
|
||||
inline unsigned long long
|
||||
ircd::ctx::prof::rdpmc(const uint &c)
|
||||
{
|
||||
static_assert(false, "TODO: Implement fallback here");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
#include "magics.h"
|
||||
#include "conf.h"
|
||||
#include "stats.h"
|
||||
#include "perf.h"
|
||||
#include "fs/fs.h"
|
||||
#include "ios.h"
|
||||
#include "ctx/ctx.h"
|
||||
|
|
92
include/ircd/perf.h
Normal file
92
include/ircd/perf.h
Normal file
|
@ -0,0 +1,92 @@
|
|||
// Matrix Construct
|
||||
//
|
||||
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
||||
// Copyright (C) 2016-2019 Jason Volk <jason@zemos.net>
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice is present in all copies. The
|
||||
// full license for this software is available in the LICENSE file.
|
||||
|
||||
#pragma once
|
||||
#define HAVE_IRCD_PERF_H
|
||||
|
||||
namespace ircd::perf
|
||||
{
|
||||
struct init;
|
||||
|
||||
IRCD_EXCEPTION(ircd::error, error)
|
||||
|
||||
unsigned long long rdpmc(const uint &);
|
||||
unsigned long long rdtscp();
|
||||
unsigned long long rdtsc();
|
||||
|
||||
uint64_t cycles();
|
||||
}
|
||||
|
||||
namespace ircd
|
||||
{
|
||||
using perf::cycles;
|
||||
}
|
||||
|
||||
struct ircd::perf::init
|
||||
{
|
||||
init();
|
||||
~init() noexcept;
|
||||
};
|
||||
|
||||
inline uint64_t
|
||||
__attribute__((flatten, always_inline, gnu_inline, artificial))
|
||||
ircd::perf::cycles()
|
||||
{
|
||||
return perf::rdtsc();
|
||||
}
|
||||
|
||||
#if defined(__x86_64__) || defined(__i386__)
|
||||
inline unsigned long long
|
||||
__attribute__((always_inline, gnu_inline, artificial))
|
||||
ircd::perf::rdtsc()
|
||||
{
|
||||
return __builtin_ia32_rdtsc();
|
||||
}
|
||||
#else
|
||||
inline unsigned long long
|
||||
ircd::perf::rdtsc()
|
||||
{
|
||||
static_assert(false, "TODO: Implement fallback here");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(__x86_64__) || defined(__i386__)
|
||||
inline unsigned long long
|
||||
__attribute__((always_inline, gnu_inline, artificial))
|
||||
ircd::perf::rdtscp()
|
||||
{
|
||||
uint32_t ia32_tsc_aux;
|
||||
return __builtin_ia32_rdtscp(&ia32_tsc_aux);
|
||||
}
|
||||
#else
|
||||
inline unsigned long long
|
||||
ircd::perf::rdtscp()
|
||||
{
|
||||
static_assert(false, "TODO: Implement fallback here");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(__x86_64__) || defined(__i386__)
|
||||
inline unsigned long long
|
||||
__attribute__((always_inline, gnu_inline, artificial))
|
||||
ircd::perf::rdpmc(const uint &c)
|
||||
{
|
||||
return __builtin_ia32_rdpmc(c);
|
||||
}
|
||||
#else
|
||||
inline unsigned long long
|
||||
ircd::perf::rdpmc(const uint &c)
|
||||
{
|
||||
static_assert(false, "TODO: Implement fallback here");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
|
@ -116,6 +116,7 @@ libircd_la_SOURCES = \
|
|||
logger.cc \
|
||||
magic.cc \
|
||||
stats.cc \
|
||||
perf.cc \
|
||||
fs.cc \
|
||||
sodium.cc \
|
||||
openssl.cc \
|
||||
|
|
10
ircd/ctx.cc
10
ircd/ctx.cc
|
@ -872,7 +872,7 @@ ircd::ctx::this_ctx::slice_usage_warning::slice_usage_warning(const string_view
|
|||
// Set the start value to the total number of cycles accrued by this
|
||||
// context including the current time slice.
|
||||
!current?
|
||||
prof::cycles():
|
||||
perf::cycles():
|
||||
~cur().flags & context::SLICE_EXEMPT?
|
||||
cur().profile.cycles + prof::cur_slice_cycles():
|
||||
0
|
||||
|
@ -898,7 +898,7 @@ noexcept
|
|||
{
|
||||
current?
|
||||
cur().profile.cycles + prof::cur_slice_cycles():
|
||||
prof::cycles()
|
||||
perf::cycles()
|
||||
};
|
||||
|
||||
assert(stop >= start);
|
||||
|
@ -1663,13 +1663,13 @@ ircd::ctx::prof::handle_cur_continue()
|
|||
void
|
||||
ircd::ctx::prof::slice_enter()
|
||||
{
|
||||
_slice_start = cycles();
|
||||
_slice_start = perf::cycles();
|
||||
}
|
||||
|
||||
void
|
||||
ircd::ctx::prof::slice_leave()
|
||||
{
|
||||
_slice_stop = cycles();
|
||||
_slice_stop = perf::cycles();
|
||||
|
||||
auto &c(cur());
|
||||
assert(_slice_stop >= _slice_start);
|
||||
|
@ -1811,7 +1811,7 @@ ircd::ctx::prof::slice_exceeded_warning(const ulong &cycles)
|
|||
ulong
|
||||
ircd::ctx::prof::cur_slice_cycles()
|
||||
{
|
||||
return cycles() - cur_slice_start();
|
||||
return perf::cycles() - cur_slice_start();
|
||||
}
|
||||
|
||||
const ulong &
|
||||
|
|
|
@ -208,7 +208,7 @@ ircd::ios::handler::fault(handler *const &handler)
|
|||
// needs to be tied off here instead.
|
||||
if(!ret)
|
||||
{
|
||||
stats.slice_last = cycles() - handler->slice_start;
|
||||
stats.slice_last = perf::cycles() - handler->slice_start;
|
||||
stats.slice_total += stats.slice_last;
|
||||
|
||||
assert(handler::current == handler);
|
||||
|
@ -226,7 +226,7 @@ ircd::ios::handler::leave(handler *const &handler)
|
|||
|
||||
assert(descriptor.stats);
|
||||
auto &stats(*descriptor.stats);
|
||||
stats.slice_last = cycles() - handler->slice_start;
|
||||
stats.slice_last = perf::cycles() - handler->slice_start;
|
||||
stats.slice_total += stats.slice_last;
|
||||
|
||||
assert(handler::current == handler);
|
||||
|
@ -245,7 +245,7 @@ ircd::ios::handler::enter(handler *const &handler)
|
|||
|
||||
assert(!handler::current);
|
||||
handler::current = handler;
|
||||
handler->slice_start = cycles();
|
||||
handler->slice_start = perf::cycles();
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
|
@ -202,6 +202,7 @@ noexcept try
|
|||
// more appropriate.
|
||||
|
||||
fs::init _fs_; // Local filesystem
|
||||
perf::init _perf_; // Profiling related
|
||||
magic::init _magic_; // libmagic
|
||||
ctx::ole::init _ole_; // Thread OffLoad Engine
|
||||
nacl::init _nacl_; // nacl crypto
|
||||
|
|
41
ircd/perf.cc
Normal file
41
ircd/perf.cc
Normal file
|
@ -0,0 +1,41 @@
|
|||
// Matrix Construct
|
||||
//
|
||||
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
||||
// Copyright (C) 2016-2019 Jason Volk <jason@zemos.net>
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice is present in all copies. The
|
||||
// full license for this software is available in the LICENSE file.
|
||||
|
||||
#ifdef HAVE_LINUX_PERF_EVENT_H
|
||||
#include <linux/perf_event.h>
|
||||
#endif
|
||||
|
||||
//
|
||||
// init
|
||||
//
|
||||
|
||||
#ifdef HAVE_LINUX_PERF_EVENT_H
|
||||
ircd::perf::init::init()
|
||||
{
|
||||
|
||||
}
|
||||
#else
|
||||
ircd::perf::init::init()
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LINUX_PERF_EVENT_H
|
||||
ircd::perf::init::~init()
|
||||
noexcept
|
||||
{
|
||||
|
||||
}
|
||||
#else
|
||||
ircd::perf::init::~init()
|
||||
noexcept
|
||||
{
|
||||
}
|
||||
#endif
|
Loading…
Reference in a new issue