Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ALTV-546 Add js print health #334

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion server/src/CNodeScriptRuntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class CNodeScriptRuntime : public alt::IScriptRuntime, public IRuntimeEventHandl
return platform.get();
}

std::unordered_set<CNodeResourceImpl*> GetResources()
std::unordered_set<CNodeResourceImpl*>& GetResources()
{
return resources;
}
Expand Down
10 changes: 9 additions & 1 deletion server/src/bindings/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,12 @@ static void HasBenefit(const v8::FunctionCallbackInfo<v8::Value>& info)
V8_ARG_TO_UINT(1, benefit);

V8_RETURN_BOOLEAN(alt::ICore::Instance().HasBenefit((alt::Benefit)benefit));
}

static void PrintHealth(const v8::FunctionCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT_RESOURCE();
resource->PrintHealth();
}

extern V8Class v8Player, v8Vehicle, v8Blip, v8AreaBlip, v8RadiusBlip, v8PointBlip, v8Checkpoint, v8VoiceChannel, v8Colshape, v8ColshapeCylinder, v8ColshapeSphere, v8ColshapeCircle,
Expand Down Expand Up @@ -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());
});
7 changes: 7 additions & 0 deletions server/src/node-module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ static void CommandHandler(const std::vector<std::string>& 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<std::string>&)
Expand Down
9 changes: 9 additions & 0 deletions shared/V8ResourceImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<v8::Value>& info)
{
Expand Down
4 changes: 3 additions & 1 deletion shared/V8ResourceImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
Loading