From f69de3558b706c7ec2f6c4dd21ded981d9749029 Mon Sep 17 00:00:00 2001 From: Andreas Joachim Peters Date: Tue, 11 Jun 2024 12:19:41 +0200 Subject: [PATCH] XrdApps::JCache fix statistics in case of very short transfers and suppress output if nothing has been moved at all --- src/XrdApps/XrdClJCachePlugin/file/Art.hh | 9 +++++++++ .../XrdClJCachePlugin/file/CacheStats.hh | 9 ++++++--- src/XrdApps/XrdClJCachePlugin/file/TimeBench.hh | 17 +++++++++++------ .../XrdClJCachePlugin/file/XrdClJCacheFile.cc | 2 +- 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/XrdApps/XrdClJCachePlugin/file/Art.hh b/src/XrdApps/XrdClJCachePlugin/file/Art.hh index 783f848b494..fae1c3cf00e 100644 --- a/src/XrdApps/XrdClJCachePlugin/file/Art.hh +++ b/src/XrdApps/XrdClJCachePlugin/file/Art.hh @@ -56,6 +56,9 @@ namespace JCache { std::vector normalizedDataPoints; for (double point : dataPoints) { int normalizedValue = static_cast((point - minValue) / (maxValue - minValue) * (plotHeight - 1)); + if (normalizedValue<0){ + normalizedValue=0; + } normalizedDataPoints.push_back(normalizedValue); } @@ -87,6 +90,12 @@ namespace JCache { void drawCurve(const std::vector& data, double interval, double runtime) { std::vector newdata; + if (interval == 0) { + interval = 0.00001; + } + if (runtime == 0) { + runtime = 0.00001; + } for ( auto i:data ) { newdata.push_back(i/1000000.0 / interval); } diff --git a/src/XrdApps/XrdClJCachePlugin/file/CacheStats.hh b/src/XrdApps/XrdClJCachePlugin/file/CacheStats.hh index 7bccbeee8f3..d52bdede05a 100644 --- a/src/XrdApps/XrdClJCachePlugin/file/CacheStats.hh +++ b/src/XrdApps/XrdClJCachePlugin/file/CacheStats.hh @@ -66,7 +66,7 @@ namespace JCache } ~CacheStats() { - if (dumponexit.load()) { + if (dumponexit.load() && totaldatasize) { using namespace std::chrono; std::string jsonpath = XrdCl::JCacheFile::sJsonPath + "jcache."; std::string name = getenv("XRD_APPNAME")?getenv("XRD_APPNAME"):"none"+std::string(".")+std::to_string(getpid()); @@ -76,6 +76,9 @@ namespace JCache XrdCl::JCacheFile::sStats.bytes_per_second = XrdCl::JCacheFile::sStats.bench.GetBins((int)(realTime)); XrdCl::JCacheFile::sStats.peakrate = *(std::max_element(XrdCl::JCacheFile::sStats.bytes_per_second.begin(), XrdCl::JCacheFile::sStats.bytes_per_second.end())); + if (realTime <1) { + XrdCl::JCacheFile::sStats.peakrate = ReadBytes() / realTime; + } if (XrdCl::JCacheFile::sJsonPath.length()) { XrdCl::JCacheFile::sStats.persistToJson(jsonpath, name); } @@ -245,7 +248,7 @@ namespace JCache oss << "# JCache : app real time : " << std::fixed << std::setprecision(2) << sStats.realTime << " s" << std::endl; oss << "# JCache : app sys time : " << std::fixed << std::setprecision(2) << sStats.sysTime << " s" << std::endl; oss << "# JCache : app acceleration : " << std::fixed << std::setprecision(2) << sStats.userTime / sStats.realTime << "x" << std::endl; - oss << "# JCache : app readrate : " << std::fixed << std::setprecision(2) << sStats.bytesToHumanReadable((sStats.ReadBytes()/sStats.realTime)) << "/s" << " [ peak " << sStats.bytesToHumanReadable(sStats.peakrate) << "/s ]" << std::endl; + oss << "# JCache : app readrate : " << std::fixed << std::setprecision(2) << sStats.bytesToHumanReadable((sStats.ReadBytes()/sStats.realTime)) << "/s" << " [ peak (1s) " << sStats.bytesToHumanReadable(sStats.peakrate) << "/s ]" << std::endl; oss << "# ----------------------------------------------------------- #" << std::endl; return oss.str(); @@ -271,4 +274,4 @@ namespace JCache std::vector bytes_per_second; std::atomic peakrate; }; // class CacheStats -} // namespace JCache \ No newline at end of file +} // namespace JCache diff --git a/src/XrdApps/XrdClJCachePlugin/file/TimeBench.hh b/src/XrdApps/XrdClJCachePlugin/file/TimeBench.hh index b3fc236ebe8..09502a10699 100644 --- a/src/XrdApps/XrdClJCachePlugin/file/TimeBench.hh +++ b/src/XrdApps/XrdClJCachePlugin/file/TimeBench.hh @@ -27,6 +27,7 @@ #include #include #include +#include namespace JCache { @@ -60,20 +61,24 @@ namespace JCache std::vector GetBins(size_t bin = 10) { std::lock_guard guard(mtx); - nbins = bin?bin:1; + nbins = bin?bin:1; Duration totalTime = std::chrono::duration_cast(end - start); Duration binSize = totalTime / nbins; bins.clear(); bins.resize(nbins, 0); - + std::fill(bins.begin(), bins.end(), 0); size_t binIndex = 0; for (auto i : measurements) { - binIndex = (i.first - start)/ binSize; + if (binSize.count()) { + binIndex = (i.first - start)/ binSize; + } else { + binIndex = 0; + } if (binIndex < nbins) { - bins[binIndex] += i.second; + bins[binIndex] += i.second; } else { - break; // Don't process future measurements + break; // Don't process future measurements } } @@ -86,4 +91,4 @@ namespace JCache return binSize; } }; -} // namespace JCache \ No newline at end of file +} // namespace JCache diff --git a/src/XrdApps/XrdClJCachePlugin/file/XrdClJCacheFile.cc b/src/XrdApps/XrdClJCachePlugin/file/XrdClJCacheFile.cc index 9d95a9c6429..a1b90805c41 100644 --- a/src/XrdApps/XrdClJCachePlugin/file/XrdClJCacheFile.cc +++ b/src/XrdApps/XrdClJCachePlugin/file/XrdClJCacheFile.cc @@ -145,7 +145,7 @@ JCacheFile::Close(ResponseHandler* handler, } else { st = XRootDStatus(stOK, 0); } - if (sEnableJournalCache) { + if (sEnableJournalCache && pJournal) { pJournal->detach(); } } else {