From 607ea8925d4235ef9c72bd17b06eeef10e8b43db Mon Sep 17 00:00:00 2001
From: Gavin Halliday <gavin.halliday@lexisnexis.com>
Date: Wed, 30 Oct 2024 14:45:08 +0000
Subject: [PATCH] HPCC-32910 Add time waiting for git lock to the workunit
 stats

Signed-off-by: Gavin Halliday <gavin.halliday@lexisnexis.com>
---
 ecl/eclcc/eclcc.cpp       |  3 +++
 ecl/hql/hqlrepository.cpp | 11 +++++++++--
 ecl/hql/hqlrepository.hpp |  1 +
 3 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/ecl/eclcc/eclcc.cpp b/ecl/eclcc/eclcc.cpp
index 2aba8307f8c..9b1a959b28d 100644
--- a/ecl/eclcc/eclcc.cpp
+++ b/ecl/eclcc/eclcc.cpp
@@ -1535,8 +1535,11 @@ void EclCC::processSingleQuery(const EclRepositoryManager & localRepositoryManag
 
             updateWorkunitStat(instance.wu, SSToperation, ">compile:>parse", StTimeElapsed, NULL, parseTimeNs);
             stat_type sourceDownloadTime = localRepositoryManager.getStatistic(StTimeElapsed);
+            stat_type sourceDownloadBlockedTime = localRepositoryManager.getStatistic(StTimeBlocked);
             if (sourceDownloadTime)
                 updateWorkunitStat(instance.wu, SSToperation, ">compile:>parse:>download", StTimeElapsed, NULL, sourceDownloadTime);
+            if (sourceDownloadBlockedTime)
+                updateWorkunitStat(instance.wu, SSToperation, ">compile:>parse:>download", StTimeBlocked, NULL, sourceDownloadBlockedTime);
 
             if (optExtraStats)
             {
diff --git a/ecl/hql/hqlrepository.cpp b/ecl/hql/hqlrepository.cpp
index 06692728bb1..1c0d2507a21 100644
--- a/ecl/hql/hqlrepository.cpp
+++ b/ecl/hql/hqlrepository.cpp
@@ -676,6 +676,8 @@ unsigned __int64 EclRepositoryManager::getStatistic(StatisticKind kind) const
     {
     case StTimeElapsed:
         return cycle_to_nanosec(gitDownloadCycles);
+    case StTimeBlocked:
+        return cycle_to_nanosec(gitDownloadBlockedCycles);
     }
     return 0;
 }
@@ -823,7 +825,12 @@ IEclSourceCollection * EclRepositoryManager::resolveGitCollection(const char * r
         throw makeStringExceptionV(99, "Unsupported repository link format '%s'", defaultUrl);
 
     bool alreadyExists = false;
+
+    CCycleTimer gitDownloadTimer;
     Owned<IInterface> gitUpdateLock(getGitUpdateLock(repoPath));
+    cycle_t blockedCycles = gitDownloadTimer.elapsedCycles();
+    gitDownloadBlockedCycles += blockedCycles;
+
     if (checkDirExists(repoPath))
     {
         if (options.cleanRepos)
@@ -853,7 +860,6 @@ IEclSourceCollection * EclRepositoryManager::resolveGitCollection(const char * r
 
     bool ok = false;
     Owned<IError> error;
-    CCycleTimer gitDownloadTimer;
     if (alreadyExists)
     {
         if (options.updateRepos)
@@ -890,7 +896,8 @@ IEclSourceCollection * EclRepositoryManager::resolveGitCollection(const char * r
     //this could become a read/write lock if that proved to be an issue.
     gitUpdateLock.clear();
 
-    gitDownloadCycles += gitDownloadTimer.elapsedCycles();
+    gitDownloadCycles += (gitDownloadTimer.elapsedCycles() - blockedCycles);
+
     if (error)
     {
         if (errorReceiver)
diff --git a/ecl/hql/hqlrepository.hpp b/ecl/hql/hqlrepository.hpp
index 071139fe2da..3d4e5e1317d 100644
--- a/ecl/hql/hqlrepository.hpp
+++ b/ecl/hql/hqlrepository.hpp
@@ -105,6 +105,7 @@ class HQL_API EclRepositoryManager
     IArrayOf<IEclRepository> overrideSources;   // -D options
     IArrayOf<IEclRepository> allSources;        // also includes -D options
     cycle_t gitDownloadCycles = 0;
+    cycle_t gitDownloadBlockedCycles = 0;
 
     //Include all options in a nested struct to make it easy to ensure they are cloned
     struct {