anacommon.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2019 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #include <string.h>
  14. #include "anacommon.hpp"
  15. #include "workunit.hpp"
  16. int compareIssuesCostOrder(CInterface * const * _l, CInterface * const * _r)
  17. {
  18. const PerformanceIssue * l = static_cast<const PerformanceIssue *>(*_l);
  19. const PerformanceIssue * r = static_cast<const PerformanceIssue *>(*_r);
  20. return l->compareCost(*r);
  21. }
  22. int PerformanceIssue::compareCost(const PerformanceIssue & other) const
  23. {
  24. if (cost == other.cost)
  25. return 0;
  26. else
  27. return cost > other.cost ? -1 : +1;
  28. }
  29. void PerformanceIssue::print() const
  30. {
  31. StringBuffer out;
  32. formatStatistic(out, cost, SMeasureTimeNs);
  33. printf("[%s] E%d \"%s\" %s ", out.str(), errorCode, comment.str(), scope.str());
  34. if (filename.length()>0)
  35. printf("%s", filename.str());
  36. if (line>0 && column>0)
  37. printf("(%u,%u)", line, column);
  38. printf("\n");
  39. }
  40. void PerformanceIssue::createException(IWorkUnit * wu)
  41. {
  42. Owned<IWUException> we = wu->createException();
  43. we->setExceptionCode(errorCode);
  44. we->setSeverity(SeverityInformation);
  45. we->setScope(scope.str());
  46. we->setPriority((unsigned) statUnits2msecs(cost));
  47. if (line>0 && column>0)
  48. {
  49. we->setExceptionLineNo(line);
  50. we->setExceptionColumn(column);
  51. }
  52. if (filename.length()>0)
  53. we->setExceptionFileName(filename);
  54. StringBuffer s(comment); // Append scope to comment as scope column is not visible in ECLWatch
  55. s.appendf(" (%s)", scope.str());
  56. we->setExceptionMessage(s.str());
  57. we->setExceptionSource("Workunit Analyser");
  58. }
  59. void PerformanceIssue::set(AnalyzerErrorCode _errorCode, stat_type _cost, const char * msg, ...)
  60. {
  61. cost = _cost;
  62. errorCode = _errorCode;
  63. va_list args;
  64. va_start(args, msg);
  65. comment.valist_appendf(msg, args);
  66. va_end(args);
  67. }
  68. void PerformanceIssue::setLocation(const char * definition)
  69. {
  70. const char *p1 = strchr(definition,'(');
  71. if (!p1)
  72. return;
  73. const char *comma = strchr(p1+1,',');
  74. if (!comma)
  75. return;
  76. const char *p2 = strchr(comma+1,')');
  77. if (!p2)
  78. return;
  79. if (p1>definition) // have filename
  80. filename.append(p1-definition, definition);
  81. line = atoi(p1+1);
  82. column = atoi(comma+1);
  83. if (line==0 || column==0)
  84. {
  85. line=0;
  86. column=0;
  87. IERRLOG("Error parsing Definition for line and column: %s", definition);
  88. }
  89. };