143 lines
6.1 KiB
C++
143 lines
6.1 KiB
C++
/*
|
||
PIP - Platform Independent Primitives
|
||
Introspection module - interface for containers
|
||
Ivan Pelipenko peri4ko@yandex.ru
|
||
|
||
This program is free software: you can redistribute it and/or modify
|
||
it under the terms of the GNU Lesser General Public License as published by
|
||
the Free Software Foundation, either version 3 of the License, or
|
||
(at your option) any later version.
|
||
|
||
This program is distributed in the hope that it will be useful,
|
||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
GNU Lesser General Public License for more details.
|
||
|
||
You should have received a copy of the GNU Lesser General Public License
|
||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
*/
|
||
//! \addtogroup Introspection
|
||
//! \{
|
||
//! \file piintrospection_containers.h
|
||
//! \brief Container introspection
|
||
//! \~english Interface for container introspection and memory tracking
|
||
//! \~russian Интерфейс для интроспекции контейнеров и отслеживания памяти
|
||
//! \details
|
||
//! \~english Provides interface for tracking container memory allocations and usage
|
||
//! \~russian Предоставляет интерфейс для отслеживания выделения и использования памяти контейнерами
|
||
|
||
#ifndef PIINTROSPECTION_CONTAINERS_H
|
||
# define PIINTROSPECTION_CONTAINERS_H
|
||
|
||
# include "pibase.h"
|
||
|
||
//! \~english Container type information structure
|
||
//! \~russian Структура информации о типе контейнера
|
||
struct PIP_EXPORT PIIntrospectionContainersType {
|
||
~PIIntrospectionContainersType();
|
||
void finish();
|
||
//! \~english Type identifier
|
||
//! \~russian Идентификатор типа
|
||
uint id = 0;
|
||
//! \~english Type name
|
||
//! \~russian Имя типа
|
||
const char * name = nullptr;
|
||
//! \~english Demangled type name
|
||
//! \~russian Демангл-имя типа
|
||
const char * demangled = "?";
|
||
//! \~english Initialization flag
|
||
//! \~russian Флаг инициализации
|
||
bool inited = false;
|
||
//! \~english Has demangled name flag
|
||
//! \~russian Флаг наличия demangled имени
|
||
bool has_demangled = false;
|
||
};
|
||
|
||
# if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION)
|
||
|
||
# include "piintrospection_base.h"
|
||
|
||
//! \~english Container type information template
|
||
//! \~russian Шаблон информации о типе контейнера
|
||
template<typename T>
|
||
class PIIntrospectionContainersTypeInfo {
|
||
public:
|
||
//! \~english Get container type information
|
||
//! \~russian Получить информацию о типе контейнера
|
||
static const PIIntrospectionContainersType & get() {
|
||
static PIIntrospectionContainersType ret = create();
|
||
return ret;
|
||
}
|
||
|
||
private:
|
||
static PIIntrospectionContainersType create() {
|
||
PIIntrospectionContainersType ret;
|
||
ret.name = __PIP_TYPENAME__(T);
|
||
ret.finish();
|
||
return ret;
|
||
}
|
||
};
|
||
|
||
# define PIINTROSPECTION_CONTAINERS (PIIntrospectionContainersInterface::instance())
|
||
|
||
// clang-format off
|
||
# define PIINTROSPECTION_CONTAINER_NEW(t, isz) PIINTROSPECTION_CONTAINERS->containerNew (PIIntrospectionContainersTypeInfo<t>::get(), isz);
|
||
# define PIINTROSPECTION_CONTAINER_DELETE(t) PIINTROSPECTION_CONTAINERS->containerDelete(PIIntrospectionContainersTypeInfo<t>::get() );
|
||
# define PIINTROSPECTION_CONTAINER_ALLOC(t, cnt) PIINTROSPECTION_CONTAINERS->containerAlloc (PIIntrospectionContainersTypeInfo<t>::get(), cnt);
|
||
# define PIINTROSPECTION_CONTAINER_FREE(t, cnt) PIINTROSPECTION_CONTAINERS->containerFree (PIIntrospectionContainersTypeInfo<t>::get(), cnt);
|
||
# define PIINTROSPECTION_CONTAINER_USED(t, cnt) PIINTROSPECTION_CONTAINERS->containerUsed (PIIntrospectionContainersTypeInfo<t>::get(), cnt);
|
||
# define PIINTROSPECTION_CONTAINER_UNUSED(t, cnt) PIINTROSPECTION_CONTAINERS->containerUnused(PIIntrospectionContainersTypeInfo<t>::get(), cnt);
|
||
// clang-format on
|
||
|
||
|
||
//! \~english Container introspection interface
|
||
//! \~russian Интерфейс интроспекции контейнеров
|
||
class PIP_EXPORT PIIntrospectionContainersInterface {
|
||
friend class PIIntrospection;
|
||
friend class PIIntrospectionServer;
|
||
|
||
public:
|
||
__PIINTROSPECTION_SINGLETON_H__(Containers)
|
||
|
||
// clang-format off
|
||
//! \~english Notify about new container allocation
|
||
//! \~russian Уведомить о новом выделении контейнера
|
||
void containerNew (const PIIntrospectionContainersType & ti, uint isz);
|
||
//! \~english Notify about container deletion
|
||
//! \~russian Уведомить об удалении контейнера
|
||
void containerDelete(const PIIntrospectionContainersType & ti);
|
||
//! \~english Notify about container memory allocation
|
||
//! \~russian Уведомить о выделении памяти контейнером
|
||
void containerAlloc (const PIIntrospectionContainersType & ti, ullong cnt);
|
||
//! \~english Notify about container memory freeing
|
||
//! \~russian Уведомить об освобождении памяти контейнером
|
||
void containerFree (const PIIntrospectionContainersType & ti, ullong cnt);
|
||
//! \~english Notify about container memory usage
|
||
//! \~russian Уведомить об использовании памяти контейнером
|
||
void containerUsed (const PIIntrospectionContainersType & ti, ullong cnt);
|
||
//! \~english Notify about container unused memory
|
||
//! \~russian Уведомить о неиспользуемой памяти контейнера
|
||
void containerUnused(const PIIntrospectionContainersType & ti, ullong cnt);
|
||
// clang-format on
|
||
|
||
PIIntrospectionContainers * p;
|
||
|
||
private:
|
||
PIIntrospectionContainersInterface();
|
||
~PIIntrospectionContainersInterface();
|
||
};
|
||
|
||
|
||
# else
|
||
# define PIINTROSPECTION_CONTAINER_NEW(t, isz)
|
||
# define PIINTROSPECTION_CONTAINER_DELETE(t)
|
||
# define PIINTROSPECTION_CONTAINER_ALLOC(t, cnt)
|
||
# define PIINTROSPECTION_CONTAINER_FREE(t, cnt)
|
||
# define PIINTROSPECTION_CONTAINER_USED(t, cnt)
|
||
# define PIINTROSPECTION_CONTAINER_UNUSED(t, cnt)
|
||
# endif // defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION)
|
||
|
||
|
||
#endif // PIINTROSPECTION_CONTAINERS_H
|
||
//! \}
|