mirror of
https://github.com/matrix-construct/construct
synced 2024-09-30 04:38:52 +02:00
ircd::ctx: Add a syscall_usage_warning to suite.
This commit is contained in:
parent
9f07790b41
commit
d8bf5b9fff
3 changed files with 89 additions and 0 deletions
|
@ -74,6 +74,7 @@ namespace ircd::ctx
|
|||
#include "this_ctx.h"
|
||||
#include "stack_usage_assertion.h"
|
||||
#include "slice_usage_warning.h"
|
||||
#include "syscall_usage_warning.h"
|
||||
#include "critical_assertion.h"
|
||||
#include "critical_indicator.h"
|
||||
#include "exception_handler.h"
|
||||
|
|
47
include/ircd/ctx/syscall_usage_warning.h
Normal file
47
include/ircd/ctx/syscall_usage_warning.h
Normal file
|
@ -0,0 +1,47 @@
|
|||
// 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_CTX_SYSCALL_USAGE_WARNING_H
|
||||
|
||||
namespace ircd::ctx::this_ctx
|
||||
{
|
||||
struct syscall_usage_warning;
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
struct ircd::ctx::this_ctx::syscall_usage_warning
|
||||
{
|
||||
const string_view fmt;
|
||||
const va_rtti ap;
|
||||
ircd::prof::syscall_timer timer;
|
||||
|
||||
template<class... args>
|
||||
syscall_usage_warning(const string_view &fmt, args&&... a)
|
||||
:syscall_usage_warning{fmt, va_rtti{std::forward<args>(a)...}}
|
||||
{}
|
||||
|
||||
explicit syscall_usage_warning(const string_view &fmt, va_rtti &&ap)
|
||||
:fmt{fmt}
|
||||
,ap{std::move(ap)}
|
||||
{}
|
||||
|
||||
~syscall_usage_warning() noexcept;
|
||||
};
|
||||
#else
|
||||
struct ircd::ctx::this_ctx::syscall_usage_warning
|
||||
{
|
||||
syscall_usage_warning(const string_view &fmt, ...)
|
||||
{
|
||||
// In at least gcc 6.3.0 20170519, template param packs are not DCE'ed
|
||||
// so legacy varargs are used here.
|
||||
}
|
||||
};
|
||||
#endif
|
41
ircd/ctx.cc
41
ircd/ctx.cc
|
@ -854,6 +854,47 @@ noexcept
|
|||
}
|
||||
#endif
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// ctx/syscall_usage_warning.h
|
||||
//
|
||||
|
||||
#ifndef NDEBUG
|
||||
ircd::ctx::this_ctx::syscall_usage_warning::~syscall_usage_warning()
|
||||
noexcept
|
||||
{
|
||||
const uint64_t total
|
||||
{
|
||||
timer.stopped?
|
||||
timer.at():
|
||||
timer.stop()
|
||||
};
|
||||
|
||||
if(likely(!total))
|
||||
return;
|
||||
|
||||
thread_local char buf[512];
|
||||
const string_view reason
|
||||
{
|
||||
fmt::vsprintf{buf, fmt, ap}
|
||||
};
|
||||
|
||||
thread_local char tmbuf[64];
|
||||
log::dwarning
|
||||
{
|
||||
log, "context '%s' id:%lu watchdog: system call took %s :%s",
|
||||
current?
|
||||
name(cur()):
|
||||
ios::handler::current?
|
||||
name(*ios::handler::current):
|
||||
"*"_sv,
|
||||
current? id(cur()) : 0,
|
||||
pretty_nanoseconds(tmbuf, total, true),
|
||||
reason
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// ctx/slice_usage_warning.h
|
||||
|
|
Loading…
Reference in a new issue