From f71cdb4eb8e8e45f19f7ed5b2d6f8a18b10333e3 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Thu, 27 Feb 2020 01:21:45 +0300 Subject: [PATCH] g_fxo: implement logging for object creation/destruction. Only logged at automated phase for initial/final processing. --- rpcs3/Emu/System.cpp | 12 ++++++++++++ rpcs3/util/fixed_typemap.hpp | 16 +++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/rpcs3/Emu/System.cpp b/rpcs3/Emu/System.cpp index 124033b312..d56aba588e 100644 --- a/rpcs3/Emu/System.cpp +++ b/rpcs3/Emu/System.cpp @@ -1762,4 +1762,16 @@ s32 error_code::error_report(const fmt_type_info* sup, u64 arg, const fmt_type_i return static_cast(arg); } +template <> +void stx::manual_fixed_typemap::init_reporter(const char* name, unsigned long long created) +{ + sys_log.notice("Object '%s' was created [%u]", name, created); +} + +template <> +void stx::manual_fixed_typemap::destroy_reporter(const char* name, unsigned long long created) +{ + sys_log.notice("Object '%s' was destroyed [%u]", name, created); +} + Emulator Emu; diff --git a/rpcs3/util/fixed_typemap.hpp b/rpcs3/util/fixed_typemap.hpp index 8aa3274e98..02018f051e 100644 --- a/rpcs3/util/fixed_typemap.hpp +++ b/rpcs3/util/fixed_typemap.hpp @@ -9,7 +9,7 @@ namespace stx { // Typemap with exactly one object of each used type, created on init() and destroyed on clear() - template + template class manual_fixed_typemap { // Save default constructor and destructor @@ -17,6 +17,7 @@ namespace stx { void(*create)(void*& ptr) noexcept; void(*destroy)(void*& ptr) noexcept; + const char* type_name = "__"; template static void call_ctor(void*& ptr) noexcept @@ -45,6 +46,7 @@ namespace stx typeinfo r; r.create = &call_ctor; r.destroy = &call_dtor; + r.type_name = typeid(T).name(); return r; } }; @@ -94,6 +96,7 @@ namespace stx void** object_pointer; unsigned long long created; void(*destroy)(void*& ptr) noexcept; + const char* name; }; auto all_data = std::make_unique(stx::typelist().count()); @@ -113,6 +116,7 @@ namespace stx all_data[_max].object_pointer = &m_list[type.index()]; all_data[_max].created = m_order[type.index()]; all_data[_max].destroy = type.destroy; + all_data[_max].name = type.type_name; // Clear creation order m_order[type.index()] = 0; @@ -129,6 +133,8 @@ namespace stx // Destroy objects in correct order for (unsigned i = 0; i < _max; i++) { + if constexpr (Report) + destroy_reporter(all_data[i].name, all_data[i].created); all_data[i].destroy(*all_data[i].object_pointer); } } @@ -144,6 +150,8 @@ namespace stx if (m_list[type.index()]) { m_order[type.index()] = ++m_init_count; + if constexpr (Report) + init_reporter(type.type_name, m_init_count); } } } @@ -190,5 +198,11 @@ namespace stx { return static_cast(m_list[stx::typeindex>()]); } + + // Body is somewhere else if enabled + void init_reporter(const char* name, unsigned long long created); + + // Body is somewhere else if enabled + void destroy_reporter(const char* name, unsigned long long created); }; }