From 8750ec743da8979aca9473bf5bed457867280b19 Mon Sep 17 00:00:00 2001 From: Dan Engelbrecht Date: Fri, 17 Apr 2026 10:16:22 +0200 Subject: operationlogoutput refactor (#967) - Improvement: Replaced `OperationLogOutput` with `ProgressBase` in `zenutil`; logging and progress reporting are now separate concerns. Operation classes receive a `LoggerRef` for logging and a `ProgressBase&` for progress bars --- src/zenutil/progress.cpp | 99 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 src/zenutil/progress.cpp (limited to 'src/zenutil/progress.cpp') diff --git a/src/zenutil/progress.cpp b/src/zenutil/progress.cpp new file mode 100644 index 000000000..a12076dcc --- /dev/null +++ b/src/zenutil/progress.cpp @@ -0,0 +1,99 @@ +// Copyright Epic Games, Inc. All Rights Reserved. + +#include + +#include + +namespace zen { + +class StandardProgressBase; + +class StandardProgressBar : public ProgressBase::ProgressBar +{ +public: + StandardProgressBar(StandardProgressBase& Owner, std::string_view InSubTask) : m_Owner(Owner), m_SubTask(InSubTask) {} + + virtual void UpdateState(const State& NewState, bool DoLinebreak) override; + virtual void Finish() override; + +private: + LoggerRef Log(); + StandardProgressBase& m_Owner; + std::string m_SubTask; + State m_State; +}; + +class StandardProgressBase : public ProgressBase +{ +public: + StandardProgressBase(LoggerRef Log) : m_Log(Log) {} + + virtual void SetLogOperationName(std::string_view Name) override + { + m_LogOperationName = Name; + ZEN_INFO("{}", m_LogOperationName); + } + virtual void SetLogOperationProgress(uint32_t StepIndex, uint32_t StepCount) override + { + const size_t PercentDone = StepCount > 0u ? (100u * StepIndex) / StepCount : 0u; + ZEN_INFO("{}: {}%", m_LogOperationName, PercentDone); + } + virtual uint32_t GetProgressUpdateDelayMS() const override { return 2000; } + virtual std::unique_ptr CreateProgressBar(std::string_view InSubTask) override + { + return std::make_unique(*this, InSubTask); + } + +private: + friend class StandardProgressBar; + LoggerRef m_Log; + std::string m_LogOperationName; + LoggerRef Log() { return m_Log; } +}; + +LoggerRef +StandardProgressBar::Log() +{ + return m_Owner.Log(); +} + +void +StandardProgressBar::UpdateState(const State& NewState, bool DoLinebreak) +{ + ZEN_UNUSED(DoLinebreak); + const size_t PercentDone = + NewState.TotalCount > 0u ? (100u * (NewState.TotalCount - NewState.RemainingCount)) / NewState.TotalCount : 0u; + std::string Task = NewState.Task; + switch (NewState.Status) + { + case State::EStatus::Aborted: + Task = "Aborting"; + break; + case State::EStatus::Paused: + Task = "Paused"; + break; + default: + break; + } + ZEN_INFO("{}: {}%{}", Task, PercentDone, NewState.Details.empty() ? "" : fmt::format(" {}", NewState.Details)); + m_State = NewState; +} +void +StandardProgressBar::Finish() +{ + if (m_State.RemainingCount > 0) + { + State NewState = m_State; + NewState.RemainingCount = 0; + NewState.Details = ""; + UpdateState(NewState, /*DoLinebreak*/ true); + } +} + +ProgressBase* +CreateStandardProgress(LoggerRef Log) +{ + return new StandardProgressBase(Log); +} + +} // namespace zen -- cgit v1.2.3 From c7c59cdc5a70bfd6e5f66f3b032ea3f8f6b4d12a Mon Sep 17 00:00:00 2001 From: Dan Engelbrecht Date: Mon, 20 Apr 2026 07:27:35 +0200 Subject: builds cmd refactor (#975) - Bugfix: `builds download` partial-block fetch decisions now account for build storage host latency - Bugfix: Transfer rate displays in `builds` commands now smooth correctly - Split `buildstorageoperations.cpp` (8.5k lines) into per-operation TUs: buildinspect, buildprimecache, buildstorageresolve, buildupdatefolder, builduploadfolder, buildvalidatebuildpart; stats moved to buildstoragestats.h. - FilteredRate extracted to zenutil. - BuildsCommand shared state consolidated into a BuildsConfiguration struct; subcommands inherit from BuildsSubCmdBase holding a `const BuildsConfiguration&` instead of a `BuildsCommand&`. - `ProgressBar` renamed to `ConsoleProgressBar`; mode enum (`ConsoleProgressMode`) lifted to namespace scope; `PushLogOperation`/`PopLogOperation`/`ForceLinebreak` promoted to virtuals on `ProgressBase`. - Free-function wrappers (`UploadFolder`, `DownloadFolder`, `ValidateBuildPart`) added around the existing operation classes so callers stop reimplementing setup + stats logging. --- src/zenutil/progress.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/zenutil/progress.cpp') diff --git a/src/zenutil/progress.cpp b/src/zenutil/progress.cpp index a12076dcc..01f6529f2 100644 --- a/src/zenutil/progress.cpp +++ b/src/zenutil/progress.cpp @@ -14,6 +14,7 @@ public: StandardProgressBar(StandardProgressBase& Owner, std::string_view InSubTask) : m_Owner(Owner), m_SubTask(InSubTask) {} virtual void UpdateState(const State& NewState, bool DoLinebreak) override; + virtual void ForceLinebreak() override {} virtual void Finish() override; private: @@ -38,6 +39,8 @@ public: const size_t PercentDone = StepCount > 0u ? (100u * StepIndex) / StepCount : 0u; ZEN_INFO("{}: {}%", m_LogOperationName, PercentDone); } + virtual void PushLogOperation(std::string_view Name) override { ZEN_UNUSED(Name); } + virtual void PopLogOperation() override {} virtual uint32_t GetProgressUpdateDelayMS() const override { return 2000; } virtual std::unique_ptr CreateProgressBar(std::string_view InSubTask) override { -- cgit v1.2.3