Explorar o código

HPCC-23050 Write location and file name with analyzer issues

Signed-off-by: Shamser Ahmed <shamser.ahmed@lexisnexis.co.uk>
Shamser Ahmed %!s(int64=5) %!d(string=hai) anos
pai
achega
8bca5e7546

+ 40 - 2
common/wuanalysis/anacommon.cpp

@@ -14,6 +14,7 @@
     See the License for the specific language governing permissions and
     limitations under the License.
 ############################################################################## */
+#include <string.h>
 #include "anacommon.hpp"
 #include "workunit.hpp"
 
@@ -36,7 +37,12 @@ void PerformanceIssue::print() const
 {
     StringBuffer out;
     formatStatistic(out, cost, SMeasureTimeNs);
-    printf("[%s] E%d %s: %s\n", out.str(), errorCode, scope.str(), comment.str());
+    printf("[%s] E%d \"%s\" %s ", out.str(), errorCode,  comment.str(), scope.str());
+    if (filename.length()>0)
+        printf("%s", filename.str());
+    if (line>0 && column>0)
+        printf("(%u,%u)", line, column);
+    printf("\n");
 }
 
 void PerformanceIssue::createException(IWorkUnit * wu)
@@ -46,7 +52,16 @@ void PerformanceIssue::createException(IWorkUnit * wu)
     we->setSeverity(SeverityInformation);
     we->setScope(scope.str());
     we->setPriority((unsigned) statUnits2msecs(cost));
-    we->setExceptionMessage(comment.str());
+    if (line>0 && column>0)
+    {
+        we->setExceptionLineNo(line);
+        we->setExceptionColumn(column);
+    }
+    if (filename.length()>0)
+        we->setExceptionFileName(filename);
+    StringBuffer s(comment);        // Append scope to comment as scope column is not visible in ECLWatch
+    s.appendf(" (%s)", scope.str());
+    we->setExceptionMessage(s.str());
     we->setExceptionSource("Workunit Analyser");
 }
 
@@ -59,3 +74,26 @@ void PerformanceIssue::set(AnalyzerErrorCode _errorCode, stat_type _cost, const
     comment.valist_appendf(msg, args);
     va_end(args);
 }
+
+void PerformanceIssue::setLocation(const char * definition)
+{
+    const char *p1 = strchr(definition,'(');
+    if (!p1)
+        return;
+    const char *comma = strchr(p1+1,',');
+    if (!comma)
+        return;
+    const char *p2 = strchr(comma+1,')');
+    if (!p2)
+        return;
+    if (p1>definition) // have filename
+        filename.append(p1-definition, definition);
+    line = atoi(p1+1);
+    column = atoi(comma+1);
+    if (line < 0 || column < 0)
+    {
+        line=0;
+        column=0;
+        IERRLOG("Error parsing Definition for line and column: %s", definition);
+    }
+};

+ 5 - 1
common/wuanalysis/anacommon.hpp

@@ -68,11 +68,15 @@ public:
     void createException(IWorkUnit * we);
 
     void set(AnalyzerErrorCode _errorCode, stat_type _cost, 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; }
 
 private:
-    AnalyzerErrorCode errorCode;
+    AnalyzerErrorCode errorCode = ANA_GENERICERROR_ID;
+    StringBuffer filename;
+    unsigned line = 0;
+    unsigned column = 0;
     StringAttr scope;
     stat_type cost = 0;      // number of nanoseconds lost as a result.
     StringBuffer comment;

+ 7 - 6
common/wuanalysis/anarule.cpp

@@ -30,7 +30,6 @@ public:
     {
         return (activity.getAttr(WaKind) == kind);
     }
-
 protected:
     ThorActivityKind kind;
 };
@@ -63,9 +62,10 @@ public:
 
             IWuEdge * inputEdge = activity.queryInput(0);
             if (inputEdge && (inputEdge->getStatRaw(StNumRowsProcessed, StSkewMax) < rowsMaxSkew))
-                result.set(ANA_DISTRIB_SKEW_INPUT_ID, cost, "DISTRIBUTE output skew is worse than input skew (%s)", activity.queryName());
+                result.set(ANA_DISTRIB_SKEW_INPUT_ID, cost, "DISTRIBUTE output skew is worse than input skew");
             else
-                result.set(ANA_DISTRIB_SKEW_OUTPUT_ID, cost, "Significant skew in DISTRIBUTE output (%s)", activity.queryName());
+                result.set(ANA_DISTRIB_SKEW_OUTPUT_ID, cost, "Significant skew in DISTRIBUTE output");
+            updateInformation(result, activity);
             return true;
         }
         return false;
@@ -128,7 +128,7 @@ public:
         return false;
     }
 
-    virtual bool check(PerformanceIssue & results, IWuActivity & activity, const WuAnalyseOptions & options) override
+    virtual bool check(PerformanceIssue & result, IWuActivity & activity, const WuAnalyseOptions & options) override
     {
         stat_type ioAvg = activity.getStatRaw(stat, StAvgX);
         stat_type ioMaxSkew = activity.getStatRaw(stat, StSkewMax);
@@ -151,9 +151,10 @@ public:
             auto edgeMaxSkew = edge ? edge->getStatRaw(StNumRowsProcessed, StSkewMax) : 0;
             // If difference between ioSkew and edgeMaxSkew > 0.05%, then child record likely to have caused skew
             if (ioMaxSkew > edgeMaxSkew && (ioMaxSkew-edgeMaxSkew) > ioMaxSkew/200)
-                results.set(ANA_IOSKEW_RECORDS_ID, cost, "Significant skew in child records causes uneven %s time (%s)", category, activity.queryName());
+                result.set(ANA_IOSKEW_RECORDS_ID, cost, "Significant skew in child records causes uneven %s time", category);
             else
-                results.set(ANA_IOSKEW_CHILDRECORDS_ID, cost, "Significant skew in records causes uneven %s time (%s)", category, activity.queryName());
+                result.set(ANA_IOSKEW_CHILDRECORDS_ID, cost, "Significant skew in records causes uneven %s time", category);
+            updateInformation(result, activity);
             return true;
         }
         return false;

+ 6 - 0
common/wuanalysis/anarule.hpp

@@ -28,6 +28,12 @@ class AActivityRule : public CInterface
 public:
     virtual bool isCandidate(IWuActivity & activity) const = 0;
     virtual bool check(PerformanceIssue & results, IWuActivity & activity, const WuAnalyseOptions & options) = 0;
+    virtual void updateInformation(PerformanceIssue & result,  IWuActivity & activity)
+    {
+        StringBuffer def;
+        activity.getAttr(def,WaDefinition);
+        result.setLocation(def);
+    }
 };
 
 void gatherRules(CIArrayOf<AActivityRule> & rules);

+ 1 - 1
common/wuanalysis/anawu.cpp

@@ -247,7 +247,7 @@ void WuScope::getAttr(StringBuffer & result, WuAttr attr) const
 {
     StringBuffer name;
     name.append('@').append(queryWuAttributeName(attr));
-    attrs->getProp(result, name);
+    attrs->getProp(name, result);
 }
 
 void WuScope::trace(unsigned indent) const