From fa7a1215390b54d91bd5b46c41ab7ed686f612d6 Mon Sep 17 00:00:00 2001 From: narknon <73571427+narknon@users.noreply.github.com> Date: Mon, 30 Oct 2023 18:52:12 -0400 Subject: [PATCH] Remove unused FunctionTimer functionality Remove function timer includes Remove functiontimer from root cmake --- UE4SS/CMakeLists.txt | 4 +- UE4SS/src/Mod/LuaMod.cpp | 2 - UE4SS/src/Mod/Mod.cpp | 1 - UE4SS/src/UE4SSProgram.cpp | 8 +- deps/first/CMakeLists.txt | 1 - deps/first/FunctionTimer/CMakeLists.txt | 33 --- deps/first/FunctionTimer/LICENSE | 21 -- .../FunctionTimer/include/Timer/Common.hpp | 17 -- .../include/Timer/FunctionTimer.hpp | 273 ------------------ .../first/FunctionTimer/src/FunctionTimer.cpp | 55 ---- 10 files changed, 3 insertions(+), 412 deletions(-) delete mode 100644 deps/first/FunctionTimer/CMakeLists.txt delete mode 100644 deps/first/FunctionTimer/LICENSE delete mode 100644 deps/first/FunctionTimer/include/Timer/Common.hpp delete mode 100644 deps/first/FunctionTimer/include/Timer/FunctionTimer.hpp delete mode 100644 deps/first/FunctionTimer/src/FunctionTimer.cpp diff --git a/UE4SS/CMakeLists.txt b/UE4SS/CMakeLists.txt index 39948df53..fcd119b4b 100644 --- a/UE4SS/CMakeLists.txt +++ b/UE4SS/CMakeLists.txt @@ -153,8 +153,8 @@ target_compile_definitions(${TARGET} PRIVATE # First party static build -> END target_link_libraries(${TARGET} PUBLIC - File glaze::glaze DynamicOutput Unreal - SinglePassSigScanner LuaMadeSimple FunctionTimer + File glaze::glaze DynamicOutput + Unreal SinglePassSigScanner LuaMadeSimple Function IniParser JSON Input Constructs Helpers MProgram ScopedTimer) diff --git a/UE4SS/src/Mod/LuaMod.cpp b/UE4SS/src/Mod/LuaMod.cpp index fd6c4507e..23f55c55e 100644 --- a/UE4SS/src/Mod/LuaMod.cpp +++ b/UE4SS/src/Mod/LuaMod.cpp @@ -58,7 +58,6 @@ #include #pragma warning(default : 4005) -#include namespace RC { @@ -108,7 +107,6 @@ namespace RC static auto lua_unreal_script_function_hook_pre(Unreal::UnrealScriptFunctionCallableContext context, void* custom_data) -> void { - TIME_FUNCTION() // Fetch the data corresponding to this UFunction auto& lua_data = *static_cast(custom_data); diff --git a/UE4SS/src/Mod/Mod.cpp b/UE4SS/src/Mod/Mod.cpp index e76d972a0..65550fa71 100644 --- a/UE4SS/src/Mod/Mod.cpp +++ b/UE4SS/src/Mod/Mod.cpp @@ -48,7 +48,6 @@ #include #pragma warning(default : 4005) -#include namespace RC { diff --git a/UE4SS/src/UE4SSProgram.cpp b/UE4SS/src/UE4SSProgram.cpp index 12a9c5f7d..cfcc15e8b 100644 --- a/UE4SS/src/UE4SSProgram.cpp +++ b/UE4SS/src/UE4SSProgram.cpp @@ -34,7 +34,6 @@ #include #include #include -#include #include #include #include @@ -160,7 +159,6 @@ namespace RC UE4SSProgram::UE4SSProgram(const std::wstring& moduleFilePath, std::initializer_list options) : MProgram(options) { - TIME_FUNCTION() s_program = this; @@ -309,8 +307,6 @@ namespace RC auto UE4SSProgram::init() -> void { - TIME_FUNCTION(); - try { setup_unreal(); @@ -1666,8 +1662,6 @@ namespace RC // Do cleanup of static objects here // This function is called right before the DLL detaches from the game // Including when the player hits the 'X' button to exit the game -#if TIME_FUNCTION_MACRO_V2 == 0 - FunctionTimerCollection::dump(); -#endif + } } // namespace RC diff --git a/deps/first/CMakeLists.txt b/deps/first/CMakeLists.txt index ce0c26a37..ce7415f1d 100644 --- a/deps/first/CMakeLists.txt +++ b/deps/first/CMakeLists.txt @@ -5,7 +5,6 @@ add_subdirectory("Constructs") add_subdirectory("DynamicOutput") add_subdirectory("File") add_subdirectory("Function") -add_subdirectory("FunctionTimer") add_subdirectory("Helpers") add_subdirectory("IniParser") add_subdirectory("Input") diff --git a/deps/first/FunctionTimer/CMakeLists.txt b/deps/first/FunctionTimer/CMakeLists.txt deleted file mode 100644 index 15346909c..000000000 --- a/deps/first/FunctionTimer/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -cmake_minimum_required(VERSION 3.18) - -set(TARGET FunctionTimer) -project(${TARGET}) - -option(UE4SS_${TARGET}_BUILD_SHARED "Build as a shared lib" OFF) - -set(${TARGET}_Sources - "${CMAKE_CURRENT_SOURCE_DIR}/src/FunctionTimer.cpp" - ) - -string(REGEX REPLACE "(.)([A-Z])" "\\1_\\2" MODULE_NAME ${TARGET}) -string(TOUPPER ${MODULE_NAME} MODULE_NAME) - -if (UE4SS_${TARGET}_BUILD_SHARED) - message("Project: ${TARGET} (SHARED)") - add_library(${TARGET} SHARED ${${TARGET}_Sources}) -else () - message("Project: ${TARGET} (STATIC)") - add_library(${TARGET} ${${TARGET}_Sources}) -endif () - -# Enabling c++20 support -target_compile_features(${TARGET} PUBLIC cxx_std_20) - -target_compile_definitions(${TARGET} PRIVATE - RC_${MODULE_NAME}_EXPORTS - $<$>: - RC_${MODULE_NAME}_BUILD_STATIC>) - -target_include_directories(${TARGET} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) - -target_link_libraries(${TARGET} PUBLIC Helpers File DynamicOutput) diff --git a/deps/first/FunctionTimer/LICENSE b/deps/first/FunctionTimer/LICENSE deleted file mode 100644 index eee4c9316..000000000 --- a/deps/first/FunctionTimer/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2022 Narknon - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/deps/first/FunctionTimer/include/Timer/Common.hpp b/deps/first/FunctionTimer/include/Timer/Common.hpp deleted file mode 100644 index f9ca34665..000000000 --- a/deps/first/FunctionTimer/include/Timer/Common.hpp +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#ifndef RC_FUNCTION_TIMER_EXPORTS -#ifndef RC_FUNCTION_TIMER_BUILD_STATIC -#ifndef RC_FNCTMR_API -#define RC_FNCTMR_API __declspec(dllimport) -#endif -#else -#ifndef RC_FNCTMR_API -#define RC_FNCTMR_API -#endif -#endif -#else -#ifndef RC_FNCTMR_API -#define RC_FNCTMR_API __declspec(dllexport) -#endif -#endif diff --git a/deps/first/FunctionTimer/include/Timer/FunctionTimer.hpp b/deps/first/FunctionTimer/include/Timer/FunctionTimer.hpp deleted file mode 100644 index b02902091..000000000 --- a/deps/first/FunctionTimer/include/Timer/FunctionTimer.hpp +++ /dev/null @@ -1,273 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include - -#include -#include -#include - -#define TIME_FUNCTION_MACRO_V2 1 - -namespace RC -{ -#if TIME_FUNCTION_MACRO_V2 == 0 - class RC_FNCTMR_API FunctionTimer - { - private: - std::chrono::time_point m_start; - std::wstring m_function_name; - - public: - FunctionTimer(std::wstring_view function_name); - FunctionTimer(std::string_view function_name); - ~FunctionTimer(); - - public: - auto get_function_name() -> std::wstring; - }; - - struct SavedFunctionTimer - { - const std::wstring function_name; - const double duration{-1}; - }; - - class RC_FNCTMR_API FunctionTimerCollection - { - private: - static inline std::vector m_timers; - - public: - auto static add_timer(FunctionTimer* timer, double duration) -> void; - auto static dump() -> void; - }; - -#if defined(TIME_FUNCTION_MACRO_ENABLED) -#ifndef TIME_FUNCTION -#define TIME_FUNCTION() FunctionTimer scoped_function_timer{__FUNCSIG__}; -#endif -#else -#define TIME_FUNCTION() -#endif -#else - - using FunctionTimerIntervalUnderlyingType = double; - using FunctionTimerInterval = std::chrono::duration; - using FunctionTimerClockType = std::chrono::system_clock; - - struct RC_FNCTMR_API FunctionTimerInternalFrame - { - // std::chrono::time_point start{}; - // std::chrono::time_point end{}; - FunctionTimerInterval start{}; - FunctionTimerInterval end{}; - - auto calculate_duration() const -> FunctionTimerIntervalUnderlyingType - { - return FunctionTimerInterval{end - start}.count(); - } - }; - - class RC_FNCTMR_API FunctionTimerFrame - { - public: - std::string function_name{}; - size_t self_frame_index{}; - size_t end_frame_index{}; - size_t hits{1}; - std::vector hit_frames{}; - - public: - FunctionTimerFrame(std::string function_name) - : function_name(function_name), self_frame_index(s_frame_stack.size()), end_frame_index(s_frame_stack.size()) - { - hit_frames.reserve(100000); - } - - public: - static std::vector s_frame_stack; - static std::unordered_map s_functions_on_stack; - static bool s_timer_enabled; - - public: - static auto start_profiling() -> void - { - s_frame_stack.clear(); - s_frame_stack.reserve(100); - s_functions_on_stack.clear(); - s_timer_enabled = true; - } - - static auto stop_profiling() -> void - { - s_timer_enabled = false; - } - - static auto new_frame(const std::string& function_name) -> FunctionTimerFrame* - { - FunctionTimerFrame* frame{}; - - auto it = s_functions_on_stack.find(function_name); - if (it == s_functions_on_stack.end()) - { - frame = &FunctionTimerFrame::s_frame_stack.emplace_back(function_name); - s_functions_on_stack.emplace(function_name, frame->self_frame_index); - } - else - { - frame = &FunctionTimerFrame::s_frame_stack[it->second]; - } - - frame->hits++; - return frame; - } - - static auto dump_profile() -> void - { - Output::Targets scoped_out; - auto& file_device = scoped_out.get_device(); - file_device.set_file_name_and_path(STR("UE4SS_Internal_Profiler_Results.txt")); - - scoped_out.send(STR("Duration is in seconds\n")); - scoped_out.send(STR("Scientific notation is likely a tiny number\n\n\n")); - - // std::vector vec{10, 5, 8, 3, 2, 8}; - - for (const auto& frame : s_frame_stack) - { - auto inclusive_duration = frame.calculate_duration(); - auto exclusive_duration = inclusive_duration; - - std::vector average_exclusive_vec{}; - for (size_t i = frame.self_frame_index + 1; i < frame.end_frame_index; i++) - { - const auto& called_frame = s_frame_stack[i]; - // const auto dur = called_frame.calculate_duration(); - // exclusive_duration -= dur; - - for (const auto& hit_frame : called_frame.hit_frames) - { - const auto dur = hit_frame.calculate_duration(); - exclusive_duration -= dur; - average_exclusive_vec.emplace_back(dur); - } - } - - std::vector average_inclusive_vec{}; - for (const auto& hit_frame : frame.hit_frames) - { - average_inclusive_vec.emplace_back(hit_frame.calculate_duration()); - } - - // auto average_inclusive = std::accumulate(average_inclusive_vec.begin(), average_inclusive_vec.end(), 0ll, [n = 0](auto cma, auto i) mutable { - // return cma + (i - cma) / ++n; - // }); - // - // auto average_exclusive = std::accumulate(average_exclusive_vec.begin(), average_exclusive_vec.end(), 0ll, [n = 0](auto cma, auto i) mutable { - // return cma + (i - cma) / ++n; - // }); - - FunctionTimerIntervalUnderlyingType average_inclusive{}; - if (!frame.hit_frames.empty()) - { - average_inclusive = inclusive_duration / frame.hit_frames.size(); - } - else - { - Output::send(STR("No hit_frames\n")); - } - - FunctionTimerIntervalUnderlyingType average_exclusive{}; - if (!average_exclusive_vec.empty()) - { - average_exclusive = exclusive_duration / average_exclusive_vec.size(); - } - else - { - Output::send(STR("No frames captured between the start and end of this frame\n")); - } - - // if (average_exclusive == 0) { average_exclusive = average_exclusive_vec.empty() ? exclusive_duration : average_exclusive_vec.front(); - if (average_exclusive == 0) - { - average_exclusive = average_inclusive; - } - // if (average_inclusive == 0) { average_inclusive = average_inclusive_vec.empty() ? average_exclusive : average_inclusive_vec.front(); } - - scoped_out.send(STR("Frame: {}\n"), to_wstring(frame.function_name)); - scoped_out.send(STR("\tHits: {}\n"), frame.hits); - scoped_out.send(STR("\tDuration (ns) : {} (avg: {})\n"), exclusive_duration, average_exclusive); - scoped_out.send(STR("\tDuration (ns) : {} (avg: {})\n\n"), inclusive_duration, average_inclusive); - } - } - - public: - auto start_timer() -> void - { - hit_frames.emplace_back().start = std::chrono::duration_cast(FunctionTimerClockType::now().time_since_epoch()); - } - - auto stop_timer() -> void - { - auto& hit_frame = hit_frames.front(); - hit_frame.end = std::chrono::duration_cast(FunctionTimerClockType::now().time_since_epoch()); - end_frame_index = s_frame_stack.size() - 1; - - if (hit_frame.end.count() == 0) - { - abort(); - } - } - - auto calculate_duration() const -> FunctionTimerIntervalUnderlyingType - { - FunctionTimerIntervalUnderlyingType duration{}; - for (const auto& hit_frame : hit_frames) - { - if (hit_frame.end < hit_frame.start) - { - continue; - } - duration += hit_frame.calculate_duration(); - } - return duration; - } - }; - - class RC_FNCTMR_API FunctionTimerFrameGuard - { - public: - size_t self_frame_index{}; - - public: - ~FunctionTimerFrameGuard() - { - if (!FunctionTimerFrame::s_frame_stack.empty() && self_frame_index != std::numeric_limits::max()) - { - FunctionTimerFrame::s_frame_stack[self_frame_index].stop_timer(); - } - } - }; - -#if defined(TIME_FUNCTION_MACRO_ENABLED) -#ifndef TIME_FUNCTION -#define TIME_FUNCTION() \ - FunctionTimerFrame* function_timer_frame{}; \ - if (FunctionTimerFrame::s_timer_enabled) \ - { \ - function_timer_frame = FunctionTimerFrame::new_frame(__FUNCSIG__); \ - function_timer_frame->start_timer(); \ - } \ - FunctionTimerFrameGuard function_timer_frame_guard{function_timer_frame ? function_timer_frame->self_frame_index : std::numeric_limits::max()}; -#endif -#else -#define TIME_FUNCTION() -#endif - -#endif - -} // namespace RC diff --git a/deps/first/FunctionTimer/src/FunctionTimer.cpp b/deps/first/FunctionTimer/src/FunctionTimer.cpp deleted file mode 100644 index 20d36cf17..000000000 --- a/deps/first/FunctionTimer/src/FunctionTimer.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include -#include -#include - -namespace RC -{ -#if TIME_FUNCTION_MACRO_V2 == 0 - FunctionTimer::FunctionTimer(std::wstring_view function_name) : m_start(std::chrono::steady_clock::now()), m_function_name(function_name) - { - } - FunctionTimer::FunctionTimer(std::string_view function_name) : m_start(std::chrono::steady_clock::now()), m_function_name(to_wstring(function_name)) - { - } - - FunctionTimer::~FunctionTimer() - { - std::chrono::time_point end = std::chrono::steady_clock::now(); - std::chrono::duration duration = end - m_start; - FunctionTimerCollection::add_timer(this, duration.count()); - } - - auto FunctionTimer::get_function_name() -> std::wstring - { - return m_function_name; - } - - auto FunctionTimerCollection::add_timer(FunctionTimer* timer, double duration) -> void - { - // Copy the timer to permanent storage - // The original will get destroyed after its destructor finishes executing - m_timers.emplace_back(SavedFunctionTimer{.function_name = timer->get_function_name(), .duration = duration}); - } - - auto FunctionTimerCollection::dump() -> void - { -#ifdef TIME_FUNCTION_MACRO_ENABLED - Output::Targets scoped_out; - auto& file_device = scoped_out.get_device(); - file_device.set_file_name_and_path(STR("TimedFunctions.txt")); - - scoped_out.send(STR("Duration is in seconds\n")); - scoped_out.send(STR("Scientific notation is likely a tiny number\n\n")); - - for (const auto& timer : m_timers) - { - scoped_out.send(STR("{} took {}\n"), timer.function_name, timer.duration); - } -#endif - } -#else // TIME_FUNCTION_MACRO_V2 == 0 - std::vector FunctionTimerFrame::s_frame_stack{}; - std::unordered_map FunctionTimerFrame::s_functions_on_stack{}; - bool FunctionTimerFrame::s_timer_enabled{}; -#endif // TIME_FUNCTION_MACRO_V2 == 0 -} // namespace RC