22 return s_AliveCount.load(std::memory_order_relaxed);
32 return s_TotalCreatedCount.load(std::memory_order_relaxed);
43 for (
const auto& val : s_DerivedMetricsProviders | std::views::values) {
44 totalAlive += val().first;
57 for (
const auto& val : s_DerivedMetricsProviders | std::views::values) {
58 totalCreatedSum += val().second;
60 return totalCreatedSum;
69 static void Report(
const std::string& indent =
"") {
77 if (!s_DerivedMetricsReporters.empty()) {
79 for (
const auto& val : s_DerivedMetricsReporters | std::views::values) {
94 std::vector<std::pair<std::string, int64_t>> counts;
100 for (
const auto& [type, func] : s_DerivedMetricsProviders) {
101 auto [createdCount, _] = func();
102 if (createdCount > 0) {
103 counts.push_back({ type.name(), createdCount });
116 std::vector<std::pair<std::string, int64_t>> counts;
122 for (
const auto& [type, func] : s_DerivedMetricsProviders) {
123 auto [_, aliveCount] = func();
124 if (aliveCount > 0) {
125 counts.push_back({ type.name(), aliveCount });
132 template<
typename DerivedType,
typename... BasePack>
136 s_AliveCount.fetch_add(1, std::memory_order_relaxed);
137 s_TotalCreatedCount.fetch_add(1, std::memory_order_relaxed);
141 s_AliveCount.fetch_sub(1, std::memory_order_relaxed);
145 if (!s_DerivedMetricsProviders.contains(derivedTypeId)) {
146 s_DerivedMetricsProviders.insert({ derivedTypeId, provider });
152 if (!s_DerivedMetricsReporters.contains(derivedTypeId)) {
153 s_DerivedMetricsReporters.insert({ derivedTypeId, reporter });
160 inline static std::atomic<int64_t> s_AliveCount{ 0 };
161 inline static std::atomic<int64_t> s_TotalCreatedCount{ 0 };
163 inline static std::map<std::type_index, DerivedMetricsReporter> s_DerivedMetricsReporters;
164 inline static std::map<std::type_index, DerivedMetricsProvider> s_DerivedMetricsProviders;
#define CORI_DEMANGLE(name)
#define CORI_CLEAN_TYPE_NAME(tn)
#define CORI_CORE_DEBUG_TAGGED(...)
#define CORI_CORE_INFO_TAGGED(...)
This utility lets you count class instances in various ways. @detials You can see how much instances ...
static void RegisterDerivedReporter(const std::type_index &derivedTypeId, DerivedMetricsReporter reporter)
static std::vector< std::pair< std::string, int64_t > > GetAliveCountData()
Retries the data about alive instances of type T including derived instances.
static int64_t GetDirectAliveCount()
Checks how many instances of type T is alive, not including derived classes.
std::function< void()> DerivedMetricsReporter
static int64_t GetTotalCreatedCount()
Checks how many instances of type T were created, including derived classes.
std::function< std::pair< int64_t, int64_t >()> DerivedMetricsProvider
static int64_t GetAliveCount()
Checks how many instances of type T is alive, including derived classes.
static int64_t GetDirectTotalCreatedCount()
Checks how many instances of type T were created, not including derived classes.
static std::vector< std::pair< std::string, int64_t > > GetTotalCreatedCountData()
Retries the data about created instances of type T including derived instances.
static void RegisterDerivedMetricsProvider(const std::type_index &derivedTypeId, DerivedMetricsProvider provider)
static void Report(const std::string &indent="")
Will report the data about type T instances.
Profiling tools are in this namespace.