Pārlūkot izejas kodu

Merge pull request #15831 from shamser/issue27203

HPCC-27203 WU Analysis Tool should report cost in money amounts

Reviewed-by: Gavin Halliday <ghalliday@hpccsystems.com>
Merged-by: Gavin Halliday <ghalliday@hpccsystems.com>
Gavin Halliday 3 gadi atpakaļ
vecāks
revīzija
cb000bb639

+ 12 - 7
common/wuanalysis/anacommon.cpp

@@ -27,16 +27,16 @@ int compareIssuesCostOrder(CInterface * const * _l, CInterface * const * _r)
 
 int PerformanceIssue::compareCost(const PerformanceIssue & other) const
 {
-    if (cost == other.cost)
+    if (timePenalty == other.timePenalty)
         return 0;
     else
-        return cost > other.cost ? -1 : +1;
+        return timePenalty > other.timePenalty ? -1 : +1;
 }
 
 void PerformanceIssue::print() const
 {
     StringBuffer out;
-    formatStatistic(out, cost, SMeasureTimeNs);
+    formatStatistic(out, timePenalty, SMeasureTimeNs);
     printf("[%s] E%d \"%s\" %s ", out.str(), errorCode,  comment.str(), scope.str());
     if (filename.length()>0)
         printf("%s", filename.str());
@@ -45,7 +45,7 @@ void PerformanceIssue::print() const
     printf("\n");
 }
 
-void PerformanceIssue::createException(IWorkUnit * wu)
+void PerformanceIssue::createException(IWorkUnit * wu, double costRate)
 {
     ErrorSeverity mappedSeverity = wu->getWarningSeverity(errorCode, (ErrorSeverity)SeverityWarning);
     if (mappedSeverity == SeverityIgnore)
@@ -55,7 +55,7 @@ void PerformanceIssue::createException(IWorkUnit * wu)
     we->setExceptionCode(errorCode);
     we->setSeverity(mappedSeverity);
     we->setScope(scope.str());
-    we->setPriority((unsigned) statUnits2msecs(cost));
+    we->setPriority((unsigned) statUnits2msecs(timePenalty));
     if (line>0 && column>0)
     {
         we->setExceptionLineNo(line);
@@ -65,13 +65,18 @@ void PerformanceIssue::createException(IWorkUnit * wu)
         we->setExceptionFileName(filename);
     StringBuffer s(comment);        // Append scope to comment as scope column is not visible in ECLWatch
     s.appendf(" (%s)", scope.str());
+    if (costRate!=0.0)
+    {
+        double timePenaltyPerHour = (double)statUnits2seconds(timePenalty) / 3600;
+        s.appendf(" cost %.2f", timePenaltyPerHour*costRate);
+    }
     we->setExceptionMessage(s.str());
     we->setExceptionSource("Workunit Analyzer");
 }
 
-void PerformanceIssue::set(AnalyzerErrorCode _errorCode, stat_type _cost, const char * msg, ...)
+void PerformanceIssue::set(AnalyzerErrorCode _errorCode, stat_type _timePenalty, const char * msg, ...)
 {
-    cost = _cost;
+    timePenalty = _timePenalty;
     errorCode = _errorCode;
     va_list args;
     va_start(args, msg);

+ 4 - 4
common/wuanalysis/anacommon.hpp

@@ -60,12 +60,12 @@ class PerformanceIssue : public CInterface
 public:
     int compareCost(const PerformanceIssue & other) const;
     void print() const;
-    void createException(IWorkUnit * we);
+    void createException(IWorkUnit * we, double costRate);
 
-    void set(AnalyzerErrorCode _errorCode, stat_type _cost, const char * msg, ...) __attribute__((format(printf, 4, 5)));
+    void set(AnalyzerErrorCode _errorCode, stat_type _timePenalty, const char * msg, ...) __attribute__((format(printf, 4, 5)));
     void setLocation(const char * definition);
     void setScope(const char *_scope) { scope.set(_scope); }
-    stat_type getCost() const         { return cost; }
+    stat_type getTimePenalityCost() const { return timePenalty; }
 
 private:
     AnalyzerErrorCode errorCode = ANA_GENERICERROR_ID;
@@ -73,7 +73,7 @@ private:
     unsigned line = 0;
     unsigned column = 0;
     StringAttr scope;
-    stat_type cost = 0;      // number of nanoseconds lost as a result.
+    stat_type timePenalty = 0; // number of nanoseconds lost as a result.
     StringBuffer comment;
 };
 

+ 9 - 9
common/wuanalysis/anawu.cpp

@@ -189,7 +189,7 @@ public:
     void check(const char * scope, IWuActivity & activity);
     void analyse(IConstWorkUnit * wu);
     void print();
-    void update(IWorkUnit *wu);
+    void update(IWorkUnit *wu, double costRate);
     void applyConfig(IPropertyTree *cfg);
 
 protected:
@@ -418,9 +418,9 @@ void WorkunitAnalyser::check(const char * scope, IWuActivity & activity)
             Owned<PerformanceIssue> issue (new PerformanceIssue);
             if (rules.item(i).check(*issue, activity, options))
             {
-                if (issue->getCost() >= options.queryOption(watOptMinInterestingCost))
+                if (issue->getTimePenalityCost() >= options.queryOption(watOptMinInterestingCost))
                 {
-                    if (!highestCostIssue || highestCostIssue->getCost() < issue->getCost())
+                    if (!highestCostIssue || highestCostIssue->getTimePenalityCost() < issue->getTimePenalityCost())
                         highestCostIssue.setown(issue.getClear());
                 }
             }
@@ -454,10 +454,10 @@ void WorkunitAnalyser::print()
         issues.item(i).print();
 }
 
-void WorkunitAnalyser::update(IWorkUnit *wu)
+void WorkunitAnalyser::update(IWorkUnit *wu, double costRate)
 {
     ForEachItemIn(i, issues)
-        issues.item(i).createException(wu);
+        issues.item(i).createException(wu, costRate);
 }
 
 
@@ -501,15 +501,15 @@ WuScope * WorkunitAnalyser::selectFullScope(const char * scope)
 
 //---------------------------------------------------------------------------------------------------------------------
 
-void WUANALYSIS_API analyseWorkunit(IWorkUnit * wu, IPropertyTree *options)
+void WUANALYSIS_API analyseWorkunit(IWorkUnit * wu, IPropertyTree *options, double costPerMs)
 {
     WorkunitAnalyser analyser;
     analyser.applyConfig(options);
     analyser.analyse(wu);
-    analyser.update(wu);
+    analyser.update(wu, costPerMs);
 }
 
-void WUANALYSIS_API analyseAndPrintIssues(IConstWorkUnit * wu, bool updatewu)
+void WUANALYSIS_API analyseAndPrintIssues(IConstWorkUnit * wu, double costRate, bool updatewu)
 {
     WorkunitAnalyser analyser;
     analyser.analyse(wu);
@@ -518,6 +518,6 @@ void WUANALYSIS_API analyseAndPrintIssues(IConstWorkUnit * wu, bool updatewu)
     {
         Owned<IWorkUnit> lockedwu = &(wu->lock());
         lockedwu->clearExceptions("Workunit Analyzer");
-        analyser.update(lockedwu);
+        analyser.update(lockedwu, costRate);
     }
 }

+ 2 - 2
common/wuanalysis/anawu.hpp

@@ -24,6 +24,6 @@
     #define WUANALYSIS_API DECL_IMPORT
 #endif
 
-void WUANALYSIS_API analyseWorkunit(IWorkUnit * wu, IPropertyTree *options);
-void WUANALYSIS_API analyseAndPrintIssues(IConstWorkUnit * wu, bool updatewu);
+void WUANALYSIS_API analyseWorkunit(IWorkUnit * wu, IPropertyTree *options, double costPerMs);
+void WUANALYSIS_API analyseAndPrintIssues(IConstWorkUnit * wu, double costPerMs, bool updatewu);
 #endif

+ 2 - 1
ecl/eclagent/eclagent.cpp

@@ -2016,8 +2016,9 @@ void EclAgent::doProcess()
         {
             if (w->getDebugValueBool("analyzeWorkunit", agentTopology->getPropBool("@analyzeWorkunit", true)))
             {
+                double costPerMs = calculateThorCost(1, getNodes());
                 IPropertyTree *analyzerOptions = agentTopology->queryPropTree("analyzerOptions");
-                analyseWorkunit(w.get(), analyzerOptions);
+                analyseWorkunit(w.get(), analyzerOptions, costPerMs);
             }
         }
         if(w->queryEventScheduledCount() > 0)

+ 2 - 1
tools/wutool/wutool.cpp

@@ -222,7 +222,8 @@ static void process(IConstWorkUnit &w, IProperties *globals, const StringArray &
     }
     else if (stricmp(action, "analyze")==0)
     {
-        analyseAndPrintIssues(&w, globals->getPropBool("UPDATEWU"));
+        // can't calculate cost in terms of money (pricing table not available and size of cluster not known here)
+        analyseAndPrintIssues(&w, 0, globals->getPropBool("UPDATEWU"));
     }
     else if (stricmp(action, "dump")==0)
     {