From 248c2f4d49653ac78726ca6831a811e3189baa70 Mon Sep 17 00:00:00 2001 From: Michael Davis <michael.davis@cern.ch> Date: Tue, 18 Jun 2019 16:09:31 +0200 Subject: [PATCH] [cta-admin] Calculates data sizes from smallest to largest --- cmdline/CtaAdminCmd.cpp | 4 ++-- cmdline/CtaAdminTextFormatter.cpp | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cmdline/CtaAdminCmd.cpp b/cmdline/CtaAdminCmd.cpp index 3ebb3b07b0..631ceaa758 100644 --- a/cmdline/CtaAdminCmd.cpp +++ b/cmdline/CtaAdminCmd.cpp @@ -32,8 +32,8 @@ // global synchronisation flag std::atomic<bool> isHeaderSent(false); -// initialise an output buffer of 5 lines -cta::admin::TextFormatter formattedText(5); +// initialise an output buffer of 1000 lines +cta::admin::TextFormatter formattedText(1000); namespace XrdSsiPb { diff --git a/cmdline/CtaAdminTextFormatter.cpp b/cmdline/CtaAdminTextFormatter.cpp index 9b2dc8dd7f..60107443c8 100644 --- a/cmdline/CtaAdminTextFormatter.cpp +++ b/cmdline/CtaAdminTextFormatter.cpp @@ -43,16 +43,16 @@ std::string TextFormatter::timeToStr(const time_t &unixtime) { std::string TextFormatter::dataSizeToStr(uint64_t value) { - const std::vector<char> suffix = { 'E', 'P', 'T', 'G', 'M', 'K' }; + const std::vector<char> suffix = { 'K', 'M', 'G', 'T', 'P', 'E' }; // Simple case, values less than 1000 bytes don't take a suffix if(value < 1000) return std::to_string(value); - // Find the correct scaling, starting at 1 EB and working down. I'm assuming we won't have - // zettabytes or yottabytes of data in a tapepool anytime soon. - uint64_t divisor; + // Find the correct scaling, starting at 1 KB and working up. I'm assuming we won't have zettabytes + // or yottabytes of data in a tapepool anytime soon. int unit; - for(unit = 0, divisor = 1'000'000'000'000'000'000; value < divisor; divisor /= 1000, ++unit) ; + uint64_t divisor; + for(unit = 0, divisor = 1000; unit < 6 && value >= divisor*1000; divisor *= 1000, ++unit) ; // Convert to format like "3.1G" double val_d = static_cast<double>(value) / static_cast<double>(divisor); -- GitLab