Jelajahi Sumber

HPCC-15123 Reimplement WorkunitServices.WorkunitTimeStamps

Signed-off-by: Gavin Halliday <gavin.halliday@lexisnexis.com>
Gavin Halliday 9 tahun lalu
induk
melakukan
ccfd02b567

+ 26 - 16
plugins/workunitservices/workunitservices.cpp

@@ -531,24 +531,34 @@ WORKUNITSERVICES_API void wsWorkunitTimeStamps(ICodeContext *ctx, size32_t & __l
     MemoryBuffer mb;
     if (wu)
     {
-/*
-        // Workunit timestamps have not been stored like this for a while - so this code has not been working
-        // Should look at fixing but perhaps as a separate Jira
-        Owned<IPropertyTreeIterator> iter = pt->getElements("TimeStamp");
-        ForEach(*iter)
+        Owned<StatisticsFilter> filter = new StatisticsFilter(SCTall, SSTall, SMeasureTimestampUs, StKindAll);
+        filter->setScopeDepth(1, 2);
+        Owned<IConstWUStatisticIterator> stats = &wu->getStatistics(filter);
+        ForEach(*stats)
         {
-            IPropertyTree &item = iter->query();
-            Owned<IPropertyTreeIterator> iter2 = item.getElements("*");
-            ForEach(*iter2)
-            {
-                IPropertyTree &item2 = iter2->query();
-                fixedAppend(mb, 32, item, "@application");              // item correct here
-                fixedAppend(mb, 16, item2.queryName());                 // id
-                fixedAppend(mb,  20, item2.queryProp(NULL));            // time
-                fixedAppend(mb,16, item, "@instance");                  // item correct here
-            }
+            IConstWUStatistic & cur = stats->query();
+
+            SCMStringBuffer scope;
+            cur.getScope(scope);
+
+            StatisticKind kind = cur.getKind();
+            const char * kindName = queryStatisticName(kind);
+            assertex(kindName && memicmp(kindName, "when", 4) == 0);
+            kindName += 4;
+
+            StringBuffer formattedTime;
+            convertTimestampToStr(cur.getValue(), formattedTime, true);
+
+            SCMStringBuffer creator;
+            cur.getCreator(creator);
+            const char * at = strchr(creator.str(), '@');
+            const char * instance = at ? at + 1 : creator.str();
+
+            fixedAppend(mb, 32, scope.str());
+            fixedAppend(mb, 16, kindName); // id
+            fixedAppend(mb, 20, formattedTime);            // time
+            fixedAppend(mb, 16, instance);                 // item correct here
         }
-  */
     }
     __lenResult = mb.length();
     __result = mb.detach();

+ 1 - 1
thorlcr/master/thmastermain.cpp

@@ -508,7 +508,7 @@ int main( int argc, char *argv[]  )
         Owned<IFile> iFile = createIFile("thor.xml");
         globals = iFile->exists() ? createPTree(*iFile, ipt_caseInsensitive) : createPTree("Thor", ipt_caseInsensitive);
     }
-    setStatisticsComponentName(SCTthor, globals->queryProp("@name"), false);
+    setStatisticsComponentName(SCTthor, globals->queryProp("@name"), true);
 
     globals->setProp("@masterBuildTag", BUILD_TAG);
     char **pp = argv+1;