Skip to content

Commit f7dfa22

Browse files
committed
Plugin: Track number of reloads and last load time for all plugins
1 parent 96e6df4 commit f7dfa22

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

Libraries/Plugin/Plugin.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,8 @@ SC::Result SC::PluginDynamicLibrary::load(const PluginCompiler& compiler, const
618618
SC_TRY_MSG(dynamicLibrary.getSymbol(buffer.view(), pluginClose), "Missing #PluginName#Close");
619619
SC_TRY(StringBuilder(buffer).format("{}QueryInterface", definition.identity.identifier.view()));
620620
SC_COMPILER_UNUSED(dynamicLibrary.getSymbol(buffer.view(), pluginQueryInterface)); // QueryInterface is optional
621+
numReloads += 1;
622+
lastLoadTime = Time::Absolute::now();
621623
return Result(true);
622624
}
623625

Libraries/Plugin/Plugin.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "../Containers/SmallVector.h"
55
#include "../Containers/VectorMap.h"
66
#include "../Strings/SmallString.h"
7+
#include "../Time/Time.h"
78
#include "Internal/DynamicLibrary.h"
89

910
namespace SC
@@ -172,7 +173,8 @@ struct SC::PluginDynamicLibrary
172173
{
173174
PluginDefinition definition; ///< Definition of the loaded plugin
174175
SystemDynamicLibrary dynamicLibrary; ///< System handle of plugin's dynamic library
175-
176+
Time::Absolute lastLoadTime; ///< time when this plugin was last loaded
177+
uint32_t numReloads; ///< Number of times that the plugin has been hot-reloaded
176178
/// @brief Try to obtain a given interface as exported by a plugin through SC_PLUGIN_EXPORT_INTERFACES macro
177179
/// @param[out] outInterface Pointer to the interface that will be returned by the plugin, if it exists
178180
/// @return true if the plugin is loaded and the requested interface is implemented by the plugin itself
@@ -186,6 +188,8 @@ struct SC::PluginDynamicLibrary
186188
return false;
187189
}
188190

191+
PluginDynamicLibrary() : lastLoadTime(Time::Absolute::now()) { numReloads = 0; }
192+
189193
private:
190194
void* instance = nullptr;
191195
bool (*pluginInit)(void*& instance) = nullptr;

0 commit comments

Comments
 (0)