Update ConfigMenu to have a "hidden" sub menu for toggling heap tracking, preserve heap tracking option on wiiloading

This commit is contained in:
Maschell
2026-02-18 15:39:14 +01:00
parent 1ec0215226
commit f1da0cfbcf
17 changed files with 520 additions and 188 deletions

View File

@@ -16,14 +16,19 @@
#include <optional>
PluginContainer::PluginContainer(PluginMetaInformation metaInformation, PluginLinkInformation pluginLinkInformation, std::shared_ptr<PluginData> pluginData)
PluginContainer::PluginContainer(PluginMetaInformation metaInformation, PluginLinkInformation pluginLinkInformation, std::shared_ptr<PluginData> pluginData, std::optional<PluginMetaInformation::HeapTrackingOptions> heapTrackingOptions)
: mMetaInformation(std::move(metaInformation)),
mPluginLinkInformation(std::move(pluginLinkInformation)),
mPluginData(std::move(pluginData)) {
// Abuse this as a stable handle that references itself and survives std::move
*mHandle = reinterpret_cast<uint32_t>(mHandle.get());
if (const bool res = useTrackingPluginHeapMemoryAllocator(mMetaInformation.getHeapTrackingOptions()); !res) {
auto trackingOptions = mMetaInformation.getHeapTrackingOptions();
if (heapTrackingOptions) {
trackingOptions = *heapTrackingOptions;
}
if (const bool res = useTrackingPluginHeapMemoryAllocator(trackingOptions); !res) {
DEBUG_FUNCTION_LINE_WARN("Failed to set heap tracking options for \"%s\"", mMetaInformation.getName().c_str());
}
}

View File

@@ -33,7 +33,7 @@ class PluginData;
class PluginContainer {
public:
PluginContainer(PluginMetaInformation metaInformation, PluginLinkInformation pluginLinkInformation, std::shared_ptr<PluginData> pluginData);
PluginContainer(PluginMetaInformation metaInformation, PluginLinkInformation pluginLinkInformation, std::shared_ptr<PluginData> pluginData, std::optional<PluginMetaInformation::HeapTrackingOptions> heapTrackingOptions);
PluginContainer(const PluginContainer &) = delete;
@@ -73,11 +73,6 @@ public:
[[nodiscard]] uint32_t getButtonComboManagerHandle() const;
/**
* @return Returns true if setting the value was successful
*/
bool useTrackingPluginHeapMemoryAllocator(PluginMetaInformation::HeapTrackingOptions options);
[[nodiscard]] bool isUsingTrackingPluginHeapMemoryAllocator() const;
[[nodiscard]] const IPluginHeapMemoryAllocator &getMemoryAllocator() const;
@@ -87,6 +82,11 @@ public:
[[nodiscard]] size_t getMemoryFootprint() const;
private:
/**
* @return Returns true if setting the value was successful
*/
bool useTrackingPluginHeapMemoryAllocator(PluginMetaInformation::HeapTrackingOptions options);
PluginMetaInformation mMetaInformation;
PluginLinkInformation mPluginLinkInformation;
std::optional<TrackingPluginHeapMemoryAllocator> mTrackingHeapAllocatorOpt;

View File

@@ -42,7 +42,11 @@ std::vector<PluginLoadWrapper> PluginDataFactory::loadDir(const std::string_view
if (inactivePluginsFilenames.contains(fileName)) {
shouldBeLoadedAndLinked = false;
}
result.emplace_back(std::move(pluginData), shouldBeLoadedAndLinked);
bool enableHeapTracking = false;
#ifdef DEBUG
enableHeapTracking = true;
#endif
result.emplace_back(std::move(pluginData), shouldBeLoadedAndLinked, enableHeapTracking);
} else {
auto errMsg = string_format("Failed to load plugin: %s", full_file_path.c_str());
DEBUG_FUNCTION_LINE_ERR("%s", errMsg.c_str());

View File

@@ -1,12 +1,16 @@
#pragma once
#include "PluginMetaInformation.h"
#include <memory>
class PluginData;
class PluginLoadWrapper {
public:
PluginLoadWrapper(std::shared_ptr<PluginData> pluginData, const bool linkAndLoad) : mPluginData(std::move(pluginData)), mIsLoadAndLink(linkAndLoad) {
PluginLoadWrapper(std::shared_ptr<PluginData> pluginData, const bool linkAndLoad, const bool heapTrackingEnabled = false)
: mPluginData(std::move(pluginData)), mIsLoadAndLink(linkAndLoad), mIsHeapTrackingEnabled(heapTrackingEnabled) {
}
[[nodiscard]] const std::shared_ptr<PluginData> &getPluginData() const {
@@ -17,7 +21,19 @@ public:
return mIsLoadAndLink;
}
[[nodiscard]] bool isHeapTrackingEnabled() const {
return mIsHeapTrackingEnabled;
}
[[nodiscard]] std::optional<PluginMetaInformation::HeapTrackingOptions> getHeapTrackingOptions() const {
if (mIsHeapTrackingEnabled) {
return PluginMetaInformation::HeapTrackingOptions::TRACK_HEAP_OPTIONS_TRACK_SIZE_AND_COLLECT_STACK_TRACES;
}
return std::nullopt;
}
private:
std::shared_ptr<PluginData> mPluginData;
bool mIsLoadAndLink = false;
bool mIsLoadAndLink = false;
bool mIsHeapTrackingEnabled = false;
};