0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-26 15:33:54 +01:00

ircd: Move definitions for various valgrind suites to vg.cc for header isolation.

This commit is contained in:
Jason Volk 2019-07-03 14:45:23 -07:00
parent 15e06e4d2e
commit f88cc51e37
5 changed files with 142 additions and 125 deletions

View file

@ -41,6 +41,7 @@ namespace ircd::allocator
}; };
/// Valgrind memcheck hypercall suite /// Valgrind memcheck hypercall suite
/// note: definitions located in ircd/vg.cc
namespace ircd::allocator::vg namespace ircd::allocator::vg
{ {
bool defined(const const_buffer &); bool defined(const const_buffer &);
@ -50,6 +51,7 @@ namespace ircd::allocator::vg
} }
/// Valgrind hypercall suite /// Valgrind hypercall suite
/// note: definitions located in ircd/vg.cc
namespace ircd::vg namespace ircd::vg
{ {
size_t errors(); size_t errors();

View file

@ -113,6 +113,7 @@ libircd_la_SOURCES =#
libircd_la_SOURCES += assert.cc libircd_la_SOURCES += assert.cc
libircd_la_SOURCES += info.cc libircd_la_SOURCES += info.cc
libircd_la_SOURCES += allocator.cc libircd_la_SOURCES += allocator.cc
libircd_la_SOURCES += vg.cc
libircd_la_SOURCES += exception.cc libircd_la_SOURCES += exception.cc
libircd_la_SOURCES += util.cc libircd_la_SOURCES += util.cc
libircd_la_SOURCES += demangle.cc libircd_la_SOURCES += demangle.cc

View file

@ -9,8 +9,6 @@
// full license for this software is available in the LICENSE file. // full license for this software is available in the LICENSE file.
#include <RB_INC_MALLOC_H #include <RB_INC_MALLOC_H
#include <RB_INC_VALGRIND_VALGRIND_H
#include <RB_INC_VALGRIND_MEMCHECK_H
// Uncomment or -D this #define to enable our own crude but simple ability to // Uncomment or -D this #define to enable our own crude but simple ability to
// profile dynamic memory usage. Global `new` and `delete` will be captured // profile dynamic memory usage. Global `new` and `delete` will be captured
@ -69,68 +67,6 @@ ircd::allocator::trim(const size_t &pad)
} }
#endif #endif
//
// valgrind
//
bool
ircd::vg::active()
{
#ifdef HAVE_VALGRIND_VALGRIND_H
return RUNNING_ON_VALGRIND;
#else
return false;
#endif
}
size_t
ircd::vg::errors()
{
#ifdef HAVE_VALGRIND_VALGRIND_H
return VALGRIND_COUNT_ERRORS;
#else
return 0;
#endif
}
//
// valgrind memcheck
//
void
ircd::allocator::vg::set_noaccess(const const_buffer &buf)
{
#ifdef HAVE_VALGRIND_MEMCHECK_H
VALGRIND_MAKE_MEM_NOACCESS(data(buf), size(buf));
#endif
}
void
ircd::allocator::vg::set_undefined(const const_buffer &buf)
{
#ifdef HAVE_VALGRIND_MEMCHECK_H
VALGRIND_MAKE_MEM_UNDEFINED(data(buf), size(buf));
#endif
}
void
ircd::allocator::vg::set_defined(const const_buffer &buf)
{
#ifdef HAVE_VALGRIND_MEMCHECK_H
VALGRIND_MAKE_MEM_DEFINED(data(buf), size(buf));
#endif
}
bool
ircd::allocator::vg::defined(const const_buffer &buf)
{
#ifdef HAVE_VALGRIND_MEMCHECK_H
return VALGRIND_CHECK_MEM_IS_DEFINED(data(buf), size(buf)) == 0;
#else
return true;
#endif
}
// //
// allocator::state // allocator::state
// //

View file

@ -205,11 +205,7 @@ catch(const std::exception &e)
// //
// prof::vg // prof::vg
// //
// note: further definitions calling valgrind isolated to ircd/vg.cc
namespace ircd::prof::vg
{
static bool _enabled;
}
// //
// prof::vg::enable // prof::vg::enable
@ -243,62 +239,6 @@ noexcept
start(); start();
} }
//
// prof::vg util
//
void
ircd::prof::vg::stop()
noexcept
{
#ifdef HAVE_VALGRIND_CALLGRIND_H
CALLGRIND_STOP_INSTRUMENTATION;
assert(_enabled);
_enabled = false;
#endif
}
void
ircd::prof::vg::start()
noexcept
{
#ifdef HAVE_VALGRIND_CALLGRIND_H
assert(!_enabled);
_enabled = true;
CALLGRIND_START_INSTRUMENTATION;
#endif
}
void
ircd::prof::vg::reset()
{
#ifdef HAVE_VALGRIND_CALLGRIND_H
CALLGRIND_ZERO_STATS;
#endif
}
void
ircd::prof::vg::toggle()
{
#ifdef HAVE_VALGRIND_CALLGRIND_H
CALLGRIND_TOGGLE_COLLECT;
#endif
}
void
ircd::prof::vg::dump(const char *const reason)
{
#ifdef HAVE_VALGRIND_CALLGRIND_H
CALLGRIND_DUMP_STATS_AT(reason);
#endif
}
bool
ircd::prof::vg::enabled()
{
return _enabled;
}
// //
// instructions // instructions
// //

138
ircd/vg.cc Normal file
View file

@ -0,0 +1,138 @@
// 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.
#include <RB_INC_VALGRIND_VALGRIND_H
#include <RB_INC_VALGRIND_MEMCHECK_H
#include <RB_INC_VALGRIND_CALLGRIND_H
///////////////////////////////////////////////////////////////////////////////
//
// ircd/allocator.h
//
bool
ircd::vg::active()
{
#ifdef HAVE_VALGRIND_VALGRIND_H
return RUNNING_ON_VALGRIND;
#else
return false;
#endif
}
size_t
ircd::vg::errors()
{
#ifdef HAVE_VALGRIND_VALGRIND_H
return VALGRIND_COUNT_ERRORS;
#else
return 0;
#endif
}
//
// valgrind memcheck
//
void
ircd::allocator::vg::set_noaccess(const const_buffer &buf)
{
#ifdef HAVE_VALGRIND_MEMCHECK_H
VALGRIND_MAKE_MEM_NOACCESS(data(buf), size(buf));
#endif
}
void
ircd::allocator::vg::set_undefined(const const_buffer &buf)
{
#ifdef HAVE_VALGRIND_MEMCHECK_H
VALGRIND_MAKE_MEM_UNDEFINED(data(buf), size(buf));
#endif
}
void
ircd::allocator::vg::set_defined(const const_buffer &buf)
{
#ifdef HAVE_VALGRIND_MEMCHECK_H
VALGRIND_MAKE_MEM_DEFINED(data(buf), size(buf));
#endif
}
bool
ircd::allocator::vg::defined(const const_buffer &buf)
{
#ifdef HAVE_VALGRIND_MEMCHECK_H
return VALGRIND_CHECK_MEM_IS_DEFINED(data(buf), size(buf)) == 0;
#else
return true;
#endif
}
///////////////////////////////////////////////////////////////////////////////
//
// ircd/prof.h
//
namespace ircd::prof::vg
{
static bool _enabled;
}
void
ircd::prof::vg::stop()
noexcept
{
#ifdef HAVE_VALGRIND_CALLGRIND_H
CALLGRIND_STOP_INSTRUMENTATION;
assert(_enabled);
_enabled = false;
#endif
}
void
ircd::prof::vg::start()
noexcept
{
#ifdef HAVE_VALGRIND_CALLGRIND_H
assert(!_enabled);
_enabled = true;
CALLGRIND_START_INSTRUMENTATION;
#endif
}
void
ircd::prof::vg::reset()
{
#ifdef HAVE_VALGRIND_CALLGRIND_H
CALLGRIND_ZERO_STATS;
#endif
}
void
ircd::prof::vg::toggle()
{
#ifdef HAVE_VALGRIND_CALLGRIND_H
CALLGRIND_TOGGLE_COLLECT;
#endif
}
void
ircd::prof::vg::dump(const char *const reason)
{
#ifdef HAVE_VALGRIND_CALLGRIND_H
CALLGRIND_DUMP_STATS_AT(reason);
#endif
}
bool
ircd::prof::vg::enabled()
{
return _enabled;
}