diff options
| author | Dan Engelbrecht <[email protected]> | 2023-10-30 18:29:09 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-10-30 18:29:09 +0100 |
| commit | cbdda104ada38108700f9da5b192867d83074119 (patch) | |
| tree | 98c04b344e041c156fdc1a5c393672bef743be34 /src/zenserver/admin/admin.cpp | |
| parent | fix changelog (diff) | |
| download | zen-cbdda104ada38108700f9da5b192867d83074119.tar.xz zen-cbdda104ada38108700f9da5b192867d83074119.zip | |
individual gc stats (#506)
- Feature: New parameter for endpoint `admin/gc` (GET) `details=true` which gives details stats on GC operation when using GC V2
- Feature: New options for zen command `gc-status`
- `--details` that enables the detailed output from the last GC operation when using GC V2
Diffstat (limited to 'src/zenserver/admin/admin.cpp')
| -rw-r--r-- | src/zenserver/admin/admin.cpp | 130 |
1 files changed, 124 insertions, 6 deletions
diff --git a/src/zenserver/admin/admin.cpp b/src/zenserver/admin/admin.cpp index fb376f238..83f33d4ea 100644 --- a/src/zenserver/admin/admin.cpp +++ b/src/zenserver/admin/admin.cpp @@ -199,6 +199,14 @@ HttpAdminService::HttpAdminService(GcScheduler& Scheduler, [this](HttpRouterRequest& Req) { const GcSchedulerState State = m_GcScheduler.GetState(); + const HttpServerRequest::QueryParams Params = Req.ServerRequest().GetQueryParams(); + + bool Details = false; + if (auto Param = Params.GetValue("details"); Param == "true") + { + Details = true; + } + auto SecondsToString = [](std::chrono::seconds Secs) { return NiceTimeSpanMs(uint64_t(std::chrono::milliseconds(Secs).count())); }; @@ -226,6 +234,101 @@ HttpAdminService::HttpAdminService(GcScheduler& Scheduler, Response << "DiskUsed" << NiceBytes(State.DiskUsed); Response << "DiskFree" << NiceBytes(State.DiskFree); + auto WriteReferencerStats = [&](CbObjectWriter& Response, const GcReferencerStats& Stats) { + if (Stats.Count == 0) + { + return; + } + Response << "Count" << Stats.Count; + Response << "Expired" << Stats.Expired; + Response << "Deleted" << Stats.Deleted; + + Response << "RemovedDisk" << NiceBytes(Stats.RemovedDisk); + Response << "RemovedMemory" << NiceBytes(Stats.RemovedMemory); + + Response << "RemoveExpiredData" << NiceTimeSpanMs(Stats.RemoveExpiredDataMS.count()); + Response << "CreateReferenceCheckers" << NiceTimeSpanMs(Stats.CreateReferenceCheckersMS.count()); + Response << "LockState" << NiceTimeSpanMs(Stats.LockStateMS.count()); + Response << "Elapsed" << NiceTimeSpanMs(Stats.ElapsedMS.count()); + }; + + auto WriteReferenceStoreStats = [&](CbObjectWriter& Response, const GcReferenceStoreStats& Stats) { + if (Stats.Count == 0) + { + return; + } + Response << "Count" << Stats.Count; + Response << "Pruned" << Stats.Pruned; + Response << "Compacted" << Stats.Compacted; + + Response << "RemovedDisk" << NiceBytes(Stats.RemovedDisk); + Response << "RemovedMemory" << NiceBytes(Stats.RemovedMemory); + + Response << "CreateReferencePruner" << NiceTimeSpanMs(Stats.CreateReferencePrunerMS.count()); + Response << "RemoveUnreferencedData" << NiceTimeSpanMs(Stats.RemoveUnreferencedDataMS.count()); + Response << "CompactReferenceStore" << NiceTimeSpanMs(Stats.CompactReferenceStoreMS.count()); + Response << "Elapsed" << NiceTimeSpanMs(Stats.ElapsedMS.count()); + }; + + auto WriteGCResult = [&](CbObjectWriter& Response, const GcResult& Result) { + Response << "RemovedDisk" << NiceBytes(Result.RemovedDisk); + Response << "RemovedMemory" << NiceBytes(Result.RemovedMemory); + Response << "WriteBlock" << NiceTimeSpanMs(Result.WriteBlockMS.count()); + Response << "Elapsed" << NiceTimeSpanMs(Result.ElapsedMS.count()); + + if (!Details) + { + return; + } + + Response << "RemoveExpiredData" << NiceTimeSpanMs(Result.RemoveExpiredDataMS.count()); + Response << "CreateReferenceCheckers" << NiceTimeSpanMs(Result.CreateReferenceCheckersMS.count()); + Response << "LockState" << NiceTimeSpanMs(Result.LockStateMS.count()); + + Response << "CreateReferencePruner" << NiceTimeSpanMs(Result.CreateReferencePrunerMS.count()); + Response << "RemoveUnreferencedData" << NiceTimeSpanMs(Result.RemoveUnreferencedDataMS.count()); + Response << "CompactReferenceStore" << NiceTimeSpanMs(Result.CompactReferenceStoreMS.count()); + + Response.BeginObject("ReferencerStats"); + { + WriteReferencerStats(Response, Result.ReferencerStat); + } + Response.EndObject(); + + Response.BeginObject("ReferenceStoreStats"); + { + WriteReferenceStoreStats(Response, Result.ReferenceStoreStat); + } + Response.EndObject(); + + if (!Result.ReferencerStats.empty()) + { + Response.BeginArray("Referencers"); + { + for (const std::pair<std::string, GcReferencerStats>& It : Result.ReferencerStats) + { + Response.BeginObject(); + Response << "Name" << It.first; + WriteReferencerStats(Response, It.second); + Response.EndObject(); + } + } + Response.EndArray(); + } + if (!Result.ReferenceStoreStats.empty()) + { + Response.BeginArray("ReferenceStores"); + for (const std::pair<std::string, GcReferenceStoreStats>& It : Result.ReferenceStoreStats) + { + Response.BeginObject(); + Response << "Name" << It.first; + WriteReferenceStoreStats(Response, It.second); + Response.EndObject(); + } + Response.EndArray(); + } + }; + Response.BeginObject("FullGC"); { Response << "LastTime" << fmt::format("{}", State.LastFullGcTime); @@ -234,18 +337,33 @@ HttpAdminService::HttpAdminService(GcScheduler& Scheduler, { Response << "SpaceToNext" << NiceBytes(State.RemainingSpaceUntilFullGC); } - Response << "LastDuration" << NiceTimeSpanMs(State.LastFullGcDuration.count()); - Response << "LastDiskFreed" << NiceBytes(State.LastFullGCDiff.DiskSize); - Response << "LastMemoryFreed" << NiceBytes(State.LastFullGCDiff.MemorySize); + if (State.LastFullGCV2Result) + { + WriteGCResult(Response, State.LastFullGCV2Result.value()); + } + else + { + Response << "LastDuration" << NiceTimeSpanMs(State.LastFullGcDuration.count()); + Response << "LastDiskFreed" << NiceBytes(State.LastFullGCDiff.DiskSize); + Response << "LastMemoryFreed" << NiceBytes(State.LastFullGCDiff.MemorySize); + } } Response.EndObject(); Response.BeginObject("LightweightGC"); { Response << "LastTime" << fmt::format("{}", State.LastLightweightGcTime); Response << "TimeToNext" << SecondsToString(State.RemainingTimeUntilLightweightGc); - Response << "LastDuration" << NiceTimeSpanMs(State.LastLightweightGcDuration.count()); - Response << "LastDiskFreed" << NiceBytes(State.LastLightweightGCDiff.DiskSize); - Response << "LastMemoryFreed" << NiceBytes(State.LastLightweightGCDiff.MemorySize); + + if (State.LastLightweightGCV2Result) + { + WriteGCResult(Response, State.LastLightweightGCV2Result.value()); + } + else + { + Response << "LastDuration" << NiceTimeSpanMs(State.LastLightweightGcDuration.count()); + Response << "LastDiskFreed" << NiceBytes(State.LastLightweightGCDiff.DiskSize); + Response << "LastMemoryFreed" << NiceBytes(State.LastLightweightGCDiff.MemorySize); + } } Response.EndObject(); Req.ServerRequest().WriteResponse(HttpResponseCode::OK, Response.Save()); |