diff --git a/server/src/CNodeScriptRuntime.h b/server/src/CNodeScriptRuntime.h index b81a37e4..121edff0 100644 --- a/server/src/CNodeScriptRuntime.h +++ b/server/src/CNodeScriptRuntime.h @@ -72,7 +72,7 @@ class CNodeScriptRuntime : public alt::IScriptRuntime, public IRuntimeEventHandl return platform.get(); } - std::unordered_set GetResources() + std::unordered_set& GetResources() { return resources; } diff --git a/server/src/bindings/Main.cpp b/server/src/bindings/Main.cpp index 5d66483d..b17295fb 100644 --- a/server/src/bindings/Main.cpp +++ b/server/src/bindings/Main.cpp @@ -841,6 +841,12 @@ static void HasBenefit(const v8::FunctionCallbackInfo& info) V8_ARG_TO_UINT(1, benefit); V8_RETURN_BOOLEAN(alt::ICore::Instance().HasBenefit((alt::Benefit)benefit)); +} + +static void PrintHealth(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + resource->PrintHealth(); } extern V8Class v8Player, v8Vehicle, v8Blip, v8AreaBlip, v8RadiusBlip, v8PointBlip, v8Checkpoint, v8VoiceChannel, v8Colshape, v8ColshapeCylinder, v8ColshapeSphere, v8ColshapeCircle, @@ -935,7 +941,9 @@ extern V8Module V8Helpers::RegisterFunc(exports, "getMigrationDistance", &GetMigrationDistance); V8Helpers::RegisterFunc(exports, "setMigrationDistance", &SetMigrationDistance); - V8Helpers::RegisterFunc(exports, "hasBenefit", &HasBenefit); + V8Helpers::RegisterFunc(exports, "hasBenefit", &HasBenefit); + + V8Helpers::RegisterFunc(exports, "printHealth", &PrintHealth); V8_OBJECT_SET_STRING(exports, "rootDir", alt::ICore::Instance().GetRootDirectory()); }); diff --git a/server/src/node-module.cpp b/server/src/node-module.cpp index 67569047..cb084254 100644 --- a/server/src/node-module.cpp +++ b/server/src/node-module.cpp @@ -76,6 +76,13 @@ static void CommandHandler(const std::vector& args) Log::Colored << " ~ly~--help ~w~- this message." << Log::Endl; Log::Colored << " ~ly~--version ~w~- version info." << Log::Endl; } + else if (args[0] == "--health") + { + auto& runtime = CNodeScriptRuntime::Instance(); + auto& resources = runtime.GetResources(); + + for(auto resource : resources) resource->PrintHealth(); + } } static void TimersCommand(const std::vector&) diff --git a/shared/V8ResourceImpl.cpp b/shared/V8ResourceImpl.cpp index 1181a8bf..e11af602 100644 --- a/shared/V8ResourceImpl.cpp +++ b/shared/V8ResourceImpl.cpp @@ -629,6 +629,15 @@ void V8ResourceImpl::InvokeEventHandlers(const alt::CEvent* ev, const std::vecto } } +void V8ResourceImpl::PrintHealth() +{ + Log::Info << "Resource health: " << resource->GetName() << Log::Endl; + Log::Info << " - Entities: " << entities.size() << Log::Endl; + Log::Info << " - Timers: " << timers.size() << Log::Endl; + Log::Info << " - Timer benchmarks: " << benchmarkTimers.size() << Log::Endl; + Log::Info << " - Vehicle passengers: " << vehiclePassengers.size() << Log::Endl; +} + // Internal script globals static void SetLogFunction(const v8::FunctionCallbackInfo& info) { diff --git a/shared/V8ResourceImpl.h b/shared/V8ResourceImpl.h index 8978fc23..7650db38 100644 --- a/shared/V8ResourceImpl.h +++ b/shared/V8ResourceImpl.h @@ -424,5 +424,7 @@ class V8ResourceImpl : public alt::IResource::Impl ObjectKey AKey{ this, "a" }; ObjectKey PosKey{ this, "pos" }; - ObjectKey WeaponKey{ this, "weapon" }; + ObjectKey WeaponKey{ this, "weapon" }; + + void PrintHealth(); };