Skip to content

Commit

Permalink
Merge pull request #334 from altmp/feature/js-health
Browse files Browse the repository at this point in the history
Add js print health
  • Loading branch information
OlegTrofimov authored Dec 9, 2024
2 parents bac7246 + 5fd9c7a commit 5d9f68b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
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();
};

0 comments on commit 5d9f68b

Please sign in to comment.