jstats.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 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 "jiface.hpp"
  14. #include "jstats.h"
  15. #include "jexcept.hpp"
  16. extern jlib_decl const char *getStatName(unsigned i)
  17. {
  18. switch (i)
  19. {
  20. case STATS_INDEX_SEEKS: return "Index seeks";
  21. case STATS_INDEX_SCANS: return "Index scans";
  22. case STATS_INDEX_WILDSEEKS: return "Index wildseeks";
  23. case STATS_INDEX_SKIPS: return "Index skips";
  24. case STATS_INDEX_NULLSKIPS: return "Index null skips";
  25. case STATS_INDEX_MERGES: return "Index merges";
  26. case STATS_BLOBCACHEHIT: return "Blob cache hit";
  27. case STATS_LEAFCACHEHIT: return "Leaf cache hit";
  28. case STATS_NODECACHEHIT: return "Node cache hit";
  29. case STATS_PRELOADCACHEHIT: return "Preload cache hit";
  30. case STATS_BLOBCACHEADD: return "Blob cache add";
  31. case STATS_LEAFCACHEADD: return "Leaf cache add";
  32. case STATS_NODECACHEADD: return "Node cache add";
  33. case STATS_PRELOADCACHEADD: return "Preload cache add";
  34. case STATS_INDEX_MERGECOMPARES: return "Index merge compares";
  35. case STATS_SERVERCACHEHIT: return "Server side cache potential hits";
  36. case STATS_ACCEPTED: return "Accepted index reads";
  37. case STATS_REJECTED: return "Rejected index reads";
  38. case STATS_ATMOST: return "ATMOST events triggered";
  39. case STATS_DISK_SEEKS: return "Disk seeks";
  40. default:
  41. return ("???");
  42. }
  43. }
  44. extern jlib_decl const char *getStatShortName(unsigned i)
  45. {
  46. switch (i)
  47. {
  48. case STATS_INDEX_SEEKS: return "seeks";
  49. case STATS_INDEX_SCANS: return "scans";
  50. case STATS_INDEX_WILDSEEKS: return "wildseeks";
  51. case STATS_INDEX_SKIPS: return "skips";
  52. case STATS_INDEX_NULLSKIPS: return "nullskips";
  53. case STATS_INDEX_MERGES: return "merges";
  54. case STATS_BLOBCACHEHIT: return "blobhit";
  55. case STATS_LEAFCACHEHIT: return "leafhit";
  56. case STATS_NODECACHEHIT: return "nodehit";
  57. case STATS_PRELOADCACHEHIT: return "preloadhit";
  58. case STATS_BLOBCACHEADD: return "blobadd";
  59. case STATS_LEAFCACHEADD: return "leafadd";
  60. case STATS_NODECACHEADD: return "nodeadd";
  61. case STATS_PRELOADCACHEADD: return "preloadadd";
  62. case STATS_INDEX_MERGECOMPARES: return "mergecompares";
  63. case STATS_SERVERCACHEHIT: return "sschits";
  64. case STATS_ACCEPTED: return "accepted";
  65. case STATS_REJECTED: return "rejected";
  66. case STATS_ATMOST: return "atmost";
  67. case STATS_DISK_SEEKS: return "fseeks";
  68. default:
  69. return ("???");
  70. }
  71. }
  72. extern jlib_decl StatisticCombineType getStatCombineMode(unsigned i)
  73. {
  74. switch (i)
  75. {
  76. case STATS_INDEX_SEEKS:
  77. case STATS_INDEX_SCANS:
  78. case STATS_INDEX_WILDSEEKS:
  79. case STATS_INDEX_SKIPS:
  80. case STATS_INDEX_NULLSKIPS:
  81. case STATS_INDEX_MERGES:
  82. case STATS_BLOBCACHEHIT:
  83. case STATS_LEAFCACHEHIT:
  84. case STATS_NODECACHEHIT:
  85. case STATS_PRELOADCACHEHIT:
  86. case STATS_BLOBCACHEADD:
  87. case STATS_LEAFCACHEADD:
  88. case STATS_NODECACHEADD:
  89. case STATS_INDEX_MERGECOMPARES:
  90. case STATS_SERVERCACHEHIT:
  91. case STATS_ACCEPTED:
  92. case STATS_REJECTED:
  93. case STATS_ATMOST:
  94. case STATS_DISK_SEEKS:
  95. default:
  96. return STATSMODE_COMBINE_SUM;
  97. }
  98. }
  99. class CStatsCategory : public CInterface
  100. {
  101. public:
  102. StringAttr longName;
  103. StringAttr shortName;
  104. StatisticCombineType mode;
  105. IMPLEMENT_IINTERFACE;
  106. CStatsCategory(const char *_longName, const char *_shortName, StatisticCombineType _mode)
  107. : longName(_longName), shortName(_shortName), mode(_mode)
  108. {
  109. }
  110. bool match(const char *_longName, const char *_shortName, StatisticCombineType _mode)
  111. {
  112. bool lm = stricmp(_longName, longName)==0;
  113. bool sm = stricmp(_shortName, shortName)==0;
  114. if (lm || sm)
  115. {
  116. if (lm && sm && mode==_mode)
  117. return true;
  118. throw MakeStringException(0, "A stats category %s (%s) is already registered", shortName.get(), longName.get());
  119. }
  120. return false;
  121. }
  122. };
  123. static CIArrayOf<CStatsCategory> statsCategories;
  124. static CriticalSection statsCategoriesCrit;
  125. extern int registerStatsCategory(const char *longName, const char *shortName, StatisticCombineType mode)
  126. {
  127. CriticalBlock b(statsCategoriesCrit);
  128. ForEachItemIn(idx, statsCategories)
  129. {
  130. if (statsCategories.item(idx).match(longName, shortName, mode))
  131. return idx;
  132. }
  133. statsCategories.append(*new CStatsCategory(longName, shortName, mode));
  134. return statsCategories.ordinality()-1;
  135. }