jstats.cpp 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836
  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. #include "jiter.ipp"
  17. #include "jlog.hpp"
  18. #include "jregexp.hpp"
  19. #ifdef _WIN32
  20. #include <sys/timeb.h>
  21. #endif
  22. static CriticalSection statsNameCs;
  23. static StringBuffer statisticsComponentName;
  24. static StatisticCreatorType statisticsComponentType = SCTunknown;
  25. StatisticCreatorType queryStatisticsComponentType()
  26. {
  27. return statisticsComponentType;
  28. }
  29. const char * queryStatisticsComponentName()
  30. {
  31. CriticalBlock c(statsNameCs);
  32. if (statisticsComponentName.length() == 0)
  33. {
  34. statisticsComponentName.append("unknown").append(GetCachedHostName());
  35. DBGLOG("getProcessUniqueName hasn't been configured correctly");
  36. }
  37. return statisticsComponentName.str();
  38. }
  39. void setStatisticsComponentName(StatisticCreatorType processType, const char * processName, bool appendIP)
  40. {
  41. if (!processName)
  42. return;
  43. CriticalBlock c(statsNameCs);
  44. statisticsComponentType = processType;
  45. statisticsComponentName.clear().append(processName);
  46. if (appendIP)
  47. statisticsComponentName.append("@").append(GetCachedHostName()); // should I use _ instead?
  48. }
  49. //--------------------------------------------------------------------------------------------------------------------
  50. // Textual forms of the different enumerations, first items are for none and all.
  51. static const char * const measureNames[] = { "", "all", "ns", "ts", "cnt", "sz", "cpu", "skw", "node", "ppm", "ip", NULL };
  52. static const char * const creatorTypeNames[]= { "", "all", "unknown", "hthor", "roxie", "roxie:s", "thor", "thor:m", "thor:s", "eclcc", "esp", "summary", NULL };
  53. static const char * const scopeTypeNames[] = { "", "all", "global", "graph", "subgraph", "activity", "allocator", "section", "compile", "dfu", "edge", NULL };
  54. static unsigned matchString(const char * const * names, const char * search)
  55. {
  56. if (!search)
  57. return 0;
  58. if (streq(search, "*"))
  59. search = "all";
  60. unsigned i=0;
  61. loop
  62. {
  63. const char * next = names[i];
  64. if (!next)
  65. return 0;
  66. if (streq(next, search))
  67. return i;
  68. i++;
  69. }
  70. }
  71. //--------------------------------------------------------------------------------------------------------------------
  72. extern jlib_decl unsigned __int64 getTimeStampNowValue()
  73. {
  74. #ifdef _WIN32
  75. struct _timeb now;
  76. _ftime(&now);
  77. return (unsigned __int64)now.time * I64C(1000000) + now.millitm * 1000;
  78. #else
  79. struct timeval tm;
  80. gettimeofday(&tm,NULL);
  81. return (unsigned __int64)tm.tv_sec * I64C(1000000) + tm.tv_usec;
  82. #endif
  83. }
  84. const static unsigned __int64 msUntilResync = 1000; // resync every second ~= 1ms accuracy
  85. static cycle_t cyclesUntilResync;
  86. MODULE_INIT(INIT_PRIORITY_STANDARD)
  87. {
  88. cyclesUntilResync = nanosec_to_cycle(msUntilResync * 1000000);
  89. return true;
  90. }
  91. OptimizedTimestamp::OptimizedTimestamp()
  92. {
  93. lastCycles = get_cycles_now();
  94. lastTimestamp = ::getTimeStampNowValue();
  95. }
  96. #if 0
  97. //This version almost certainly has problems if the computer is suspended and cycles->nanoseconds is only accurate to
  98. //about 0.1% - so should only be used for relatively short periods
  99. unsigned __int64 OptimizedTimestamp::getTimeStampNowValue()
  100. {
  101. cycle_t nowCycles = get_cycles_now();
  102. return lastTimestamp + cycle_to_microsec(nowCycles - lastCycles);
  103. }
  104. #else
  105. //This version will resync every minute, but is not thread safe. Adding a critical section makes it less efficient than recalculating
  106. unsigned __int64 OptimizedTimestamp::getTimeStampNowValue()
  107. {
  108. cycle_t nowCycles = get_cycles_now();
  109. if (nowCycles - lastCycles > cyclesUntilResync)
  110. {
  111. lastCycles = nowCycles;
  112. lastTimestamp = ::getTimeStampNowValue();
  113. }
  114. return lastTimestamp + cycle_to_microsec(nowCycles - lastCycles);
  115. }
  116. #endif
  117. unsigned __int64 getIPV4StatsValue(const IpAddress & ip)
  118. {
  119. unsigned ipValue;
  120. if (ip.getNetAddress(sizeof(ipValue),&ipValue))
  121. return ipValue;
  122. return 0;
  123. }
  124. //--------------------------------------------------------------------------------------------------------------------
  125. const static unsigned __int64 oneMilliSecond = I64C(1000000);
  126. const static unsigned __int64 oneSecond = I64C(1000000000);
  127. const static unsigned __int64 oneMinute = I64C(60000000000);
  128. const static unsigned __int64 oneHour = I64C(3600000000000);
  129. const static unsigned __int64 oneDay = 24 * I64C(3600000000000);
  130. static void formatTime(StringBuffer & out, unsigned __int64 value)
  131. {
  132. //Aim to display at least 3 significant digits in the result string
  133. if (value < oneMilliSecond)
  134. out.appendf("%uns", (unsigned)value);
  135. else if (value < oneSecond)
  136. {
  137. unsigned uvalue = (unsigned)value;
  138. out.appendf("%u.%03ums", uvalue / 1000000, (uvalue / 1000) % 1000);
  139. }
  140. else
  141. {
  142. unsigned days = (unsigned)(value / oneDay);
  143. value = value % oneDay;
  144. unsigned hours = (unsigned)(value / oneHour);
  145. value = value % oneHour;
  146. unsigned mins = (unsigned)(value / oneMinute);
  147. value = value % oneMinute;
  148. unsigned secs = (unsigned)(value / oneSecond);
  149. unsigned ns = (unsigned)(value % oneSecond);
  150. if (days > 0)
  151. out.appendf("%u days ", days);
  152. if (hours > 0 || days)
  153. out.appendf("%u:%02u:%02u", hours, mins, secs);
  154. else if (mins >= 10)
  155. out.appendf("%u:%02u", mins, secs);
  156. else if (mins >= 1)
  157. out.appendf("%u:%02u.%03u", mins, secs, ns / 1000000);
  158. else
  159. out.appendf("%u.%03us", secs, ns / 1000000);
  160. }
  161. }
  162. static void formatTimeStamp(StringBuffer & out, unsigned __int64 value)
  163. {
  164. time_t seconds = value / 1000000;
  165. unsigned us = value % 1000000;
  166. char timeStamp[64];
  167. time_t tNow = seconds;
  168. #ifdef _WIN32
  169. struct tm *gmtNow;
  170. gmtNow = gmtime(&tNow);
  171. strftime(timeStamp, 64, "%Y-%m-%d %H:%M:%S", gmtNow);
  172. #else
  173. struct tm gmtNow;
  174. gmtime_r(&tNow, &gmtNow);
  175. strftime(timeStamp, 64, "%Y-%m-%d %H:%M:%S", &gmtNow);
  176. #endif //_WIN32
  177. out.append(timeStamp).appendf(".%03u", us / 1000);
  178. }
  179. static const unsigned oneKb = 1024;
  180. static const unsigned oneMb = 1024 * 1024;
  181. static const unsigned oneGb = 1024 * 1024 * 1024;
  182. static unsigned toPermille(unsigned x) { return (x * 1000) / 1024; }
  183. static void formatSize(StringBuffer & out, unsigned __int64 value)
  184. {
  185. unsigned Gb = (unsigned)(value / oneGb);
  186. unsigned Mb = (unsigned)((value % oneGb) / oneMb);
  187. unsigned Kb = (unsigned)((value % oneMb) / oneKb);
  188. unsigned b = (unsigned)(value % oneKb);
  189. if (Gb)
  190. out.appendf("%u.%03uGb", Gb, toPermille(Mb));
  191. else if (Mb)
  192. out.appendf("%u.%03uMb", Mb, toPermille(Kb));
  193. else if (Kb)
  194. out.appendf("%u.%03uKb", Kb, toPermille(b));
  195. else
  196. out.appendf("%ub", b);
  197. }
  198. static void formatLoad(StringBuffer & out, unsigned __int64 value)
  199. {
  200. //Stored as millionth of a core. Display as a percentage => scale by 10,000
  201. out.appendf("%u.%03u%%", (unsigned)(value / 10000), (unsigned)(value % 10000) / 10);
  202. }
  203. static void formatSkew(StringBuffer & out, unsigned __int64 value)
  204. {
  205. //Skew stored as 10000 = perfect, display as percentage
  206. out.appendf("%.2f%%", ((double)(__int64)value) / 100.0);
  207. }
  208. static void formatIPV4(StringBuffer & out, unsigned __int64 value)
  209. {
  210. byte ip1 = (value & 255);
  211. byte ip2 = ((value >> 8) & 255);
  212. byte ip3 = ((value >> 16) & 255);
  213. byte ip4 = ((value >> 24) & 255);
  214. out.appendf("%d.%d.%d.%d", ip1, ip2, ip3, ip4);
  215. }
  216. void formatStatistic(StringBuffer & out, unsigned __int64 value, StatisticMeasure measure)
  217. {
  218. switch (measure)
  219. {
  220. case SMeasureTimeNs:
  221. formatTime(out, value);
  222. break;
  223. case SMeasureTimestampUs:
  224. formatTimeStamp(out, value);
  225. break;
  226. case SMeasureCount:
  227. out.append(value);
  228. break;
  229. case SMeasureSize:
  230. formatSize(out, value);
  231. break;
  232. case SMeasureLoad:
  233. formatLoad(out, value);
  234. break;
  235. case SMeasureSkew:
  236. formatSkew(out, value);
  237. break;
  238. case SMeasureNode:
  239. out.append(value);
  240. break;
  241. case SMeasurePercent:
  242. out.appendf("%.2f%%", (double)value / 10000.0); // stored as ppm
  243. break;
  244. case SMeasureIPV4:
  245. formatIPV4(out, value);
  246. break;
  247. default:
  248. throwUnexpected();
  249. }
  250. }
  251. void formatStatistic(StringBuffer & out, unsigned __int64 value, StatisticKind kind)
  252. {
  253. formatStatistic(out, value, queryMeasure(kind));
  254. }
  255. //--------------------------------------------------------------------------------------------------------------------
  256. unsigned queryStatisticsDepth(const char * text)
  257. {
  258. unsigned depth = 1;
  259. loop
  260. {
  261. switch (*text)
  262. {
  263. case 0:
  264. return depth;
  265. case ':':
  266. depth++;
  267. break;
  268. }
  269. text++;
  270. }
  271. }
  272. const char * queryMeasurePrefix(StatisticMeasure measure)
  273. {
  274. switch (measure)
  275. {
  276. case SMeasureAll: return NULL;
  277. case SMeasureTimeNs: return "Time";
  278. case SMeasureTimestampUs: return "When";
  279. case SMeasureCount: return "Num";
  280. case SMeasureSize: return "Size";
  281. case SMeasureLoad: return "Load";
  282. case SMeasureSkew: return "Skew";
  283. case SMeasureNode: return "Node";
  284. case SMeasurePercent: return "Per";
  285. case SMeasureIPV4: return "Ip";
  286. default:
  287. throwUnexpected();
  288. }
  289. }
  290. const char * queryMeasureName(StatisticMeasure measure)
  291. {
  292. return measureNames[measure];
  293. }
  294. StatisticMeasure queryMeasure(const char * measure)
  295. {
  296. //MORE: Use a hash table??
  297. return (StatisticMeasure)matchString(measureNames, measure);
  298. }
  299. StatsMergeAction queryMergeMode(StatisticMeasure measure)
  300. {
  301. switch (measure)
  302. {
  303. case SMeasureTimeNs: return StatsMergeSum;
  304. case SMeasureTimestampUs: return StatsMergeKeep;
  305. case SMeasureCount: return StatsMergeSum;
  306. case SMeasureSize: return StatsMergeSum;
  307. case SMeasureLoad: return StatsMergeMax;
  308. case SMeasureSkew: return StatsMergeMax;
  309. case SMeasureNode: return StatsMergeKeep;
  310. case SMeasurePercent: return StatsMergeReplace;
  311. case SMeasureIPV4: return StatsMergeKeep;
  312. default:
  313. throwUnexpected();
  314. }
  315. }
  316. //--------------------------------------------------------------------------------------------------------------------
  317. StatisticMeasure queryMeasure(StatisticKind kind)
  318. {
  319. unsigned varient = (kind & ~StKindMask);
  320. switch (varient)
  321. {
  322. case StSkew:
  323. case StSkewMin:
  324. case StSkewMax:
  325. return SMeasureSkew;
  326. case StNodeMin:
  327. case StNodeMax:
  328. return SMeasureNode;
  329. case StDeltaX:
  330. {
  331. StatisticMeasure measure = queryMeasure((StatisticKind)(kind & StKindMask));
  332. switch (measure)
  333. {
  334. case SMeasureTimestampUs:
  335. return SMeasureTimeNs;
  336. default:
  337. return measure;
  338. }
  339. break;
  340. }
  341. }
  342. switch (kind & StKindMask)
  343. {
  344. case StKindNone:
  345. return SMeasureNone;
  346. case StKindAll:
  347. return SMeasureAll;
  348. case StWhenGraphStarted:
  349. case StWhenGraphFinished:
  350. case StWhenFirstRow:
  351. case StWhenQueryStarted:
  352. case StWhenQueryFinished:
  353. case StWhenCreated:
  354. case StWhenCompiled:
  355. case StWhenWorkunitModified:
  356. return SMeasureTimestampUs;
  357. case StTimeElapsed:
  358. case StTimeLocalExecute:
  359. case StTimeTotalExecute:
  360. case StTimeRemaining:
  361. return SMeasureTimeNs;
  362. case StSizeGeneratedCpp:
  363. case StSizePeakMemory:
  364. case StSizeMaxRowSize:
  365. return SMeasureSize;
  366. case StNumRowsProcessed:
  367. case StNumSlaves:
  368. case StNumStarted:
  369. case StNumStopped:
  370. case StNumIndexSeeks:
  371. case StNumIndexScans:
  372. case StNumIndexWildSeeks:
  373. case StNumIndexSkips:
  374. case StNumIndexNullSkips:
  375. case StNumIndexMerges:
  376. case StNumIndexMergeCompares:
  377. case StNumPreFiltered:
  378. case StNumPostFiltered:
  379. case StNumBlobCacheHits:
  380. case StNumLeafCacheHits:
  381. case StNumNodeCacheHits:
  382. case StNumBlobCacheAdds:
  383. case StNumLeafCacheAdds:
  384. case StNumNodeCacheAdds:
  385. case StNumPreloadCacheHits:
  386. case StNumPreloadCacheAdds:
  387. case StNumServerCacheHits:
  388. case StNumIndexAccepted:
  389. case StNumIndexRejected:
  390. case StNumAtmostTriggered:
  391. case StNumDiskSeeks:
  392. case StNumIterations:
  393. case StNumLeftRows:
  394. case StNumRightRows:
  395. case StNumDiskRowsRead:
  396. case StNumIndexRowsRead:
  397. case StNumDiskAccepted:
  398. case StNumDiskRejected:
  399. return SMeasureCount;
  400. case StLoadWhileSorting: // Average load while processing a sort?
  401. return SMeasureLoad;
  402. case StPerReplicated:
  403. return SMeasurePercent;
  404. default:
  405. throwUnexpected();
  406. }
  407. }
  408. //NOTE: Min/Max/Avg still contain the type prefix, otherwise you cannot deduce the measure from the name
  409. #define DEFINE_DEFAULTSHORTNAME_BASE(x, y) \
  410. case St##x##y: return #x #y; \
  411. case (St ## x ## y | StMinX): return #x "Min" # y; \
  412. case (St ## x ## y | StMaxX): return #x "Max" # y; \
  413. case (St ## x ## y | StAvgX): return #x "Avg" # y; \
  414. case (St ## x ## y | StSkew): return "Skew" # y; \
  415. case (St ## x ## y | StSkewMin): return "SkewMin" # y; \
  416. case (St ## x ## y | StSkewMax): return "SkewMax" # y; \
  417. case (St ## x ## y | StNodeMin): return "NodeMin" # y; \
  418. case (St ## x ## y | StNodeMax): return "NodeMax" # y;
  419. #define DEFINE_DEFAULTSHORTNAME(x, y) \
  420. DEFINE_DEFAULTSHORTNAME_BASE(x, y) \
  421. case (St ## x ## y | StDeltaX): return #x "Delta" # y;
  422. #define DEFINE_TIMESTAMPSHORTNAME(x, y) \
  423. DEFINE_DEFAULTSHORTNAME_BASE(x, y) \
  424. case (St ## x ## y | StDeltaX): return "TimeDelta" # y;
  425. const char * queryStatisticName(StatisticKind kind)
  426. {
  427. switch (kind)
  428. {
  429. case StKindNone: return "";
  430. case StKindAll: return "all";
  431. DEFINE_DEFAULTSHORTNAME(When, GraphStarted);
  432. DEFINE_DEFAULTSHORTNAME(When, GraphFinished);
  433. DEFINE_DEFAULTSHORTNAME(When, FirstRow);
  434. DEFINE_DEFAULTSHORTNAME(When, QueryStarted);
  435. DEFINE_DEFAULTSHORTNAME(When, QueryFinished);
  436. DEFINE_DEFAULTSHORTNAME(When, Created);
  437. DEFINE_DEFAULTSHORTNAME(When, Compiled);
  438. DEFINE_DEFAULTSHORTNAME(When, WorkunitModified);
  439. DEFINE_TIMESTAMPSHORTNAME(Time, Elapsed);
  440. DEFINE_TIMESTAMPSHORTNAME(Time, LocalExecute);
  441. DEFINE_TIMESTAMPSHORTNAME(Time, TotalExecute);
  442. DEFINE_TIMESTAMPSHORTNAME(Time, Remaining);
  443. DEFINE_DEFAULTSHORTNAME(Size, GeneratedCpp);
  444. DEFINE_DEFAULTSHORTNAME(Size, PeakMemory);
  445. DEFINE_DEFAULTSHORTNAME(Size, MaxRowSize);
  446. DEFINE_DEFAULTSHORTNAME(Num, RowsProcessed);
  447. DEFINE_DEFAULTSHORTNAME(Num, Slaves);
  448. DEFINE_DEFAULTSHORTNAME(Num, Started);
  449. DEFINE_DEFAULTSHORTNAME(Num, Stopped);
  450. DEFINE_DEFAULTSHORTNAME(Num, IndexSeeks);
  451. DEFINE_DEFAULTSHORTNAME(Num, IndexScans);
  452. DEFINE_DEFAULTSHORTNAME(Num, IndexWildSeeks);
  453. DEFINE_DEFAULTSHORTNAME(Num, IndexSkips);
  454. DEFINE_DEFAULTSHORTNAME(Num, IndexNullSkips);
  455. DEFINE_DEFAULTSHORTNAME(Num, IndexMerges);
  456. DEFINE_DEFAULTSHORTNAME(Num, IndexMergeCompares);
  457. DEFINE_DEFAULTSHORTNAME(Num, PreFiltered);
  458. DEFINE_DEFAULTSHORTNAME(Num, PostFiltered);
  459. DEFINE_DEFAULTSHORTNAME(Num, BlobCacheHits);
  460. DEFINE_DEFAULTSHORTNAME(Num, LeafCacheHits);
  461. DEFINE_DEFAULTSHORTNAME(Num, NodeCacheHits);
  462. DEFINE_DEFAULTSHORTNAME(Num, BlobCacheAdds);
  463. DEFINE_DEFAULTSHORTNAME(Num, LeafCacheAdds);
  464. DEFINE_DEFAULTSHORTNAME(Num, NodeCacheAdds);
  465. DEFINE_DEFAULTSHORTNAME(Num, PreloadCacheHits);
  466. DEFINE_DEFAULTSHORTNAME(Num, PreloadCacheAdds);
  467. DEFINE_DEFAULTSHORTNAME(Num, ServerCacheHits);
  468. DEFINE_DEFAULTSHORTNAME(Num, IndexAccepted);
  469. DEFINE_DEFAULTSHORTNAME(Num, IndexRejected);
  470. DEFINE_DEFAULTSHORTNAME(Num, AtmostTriggered);
  471. DEFINE_DEFAULTSHORTNAME(Num, DiskSeeks);
  472. DEFINE_DEFAULTSHORTNAME(Num, Iterations);
  473. DEFINE_DEFAULTSHORTNAME(Load, WhileSorting);
  474. DEFINE_DEFAULTSHORTNAME(Num, LeftRows);
  475. DEFINE_DEFAULTSHORTNAME(Num, RightRows);
  476. DEFINE_DEFAULTSHORTNAME(Per, Replicated);
  477. DEFINE_DEFAULTSHORTNAME(Num, DiskRowsRead);
  478. DEFINE_DEFAULTSHORTNAME(Num, IndexRowsRead);
  479. DEFINE_DEFAULTSHORTNAME(Num, DiskAccepted);
  480. DEFINE_DEFAULTSHORTNAME(Num, DiskRejected);
  481. default:
  482. throwUnexpected();
  483. }
  484. }
  485. #undef DEFINE_DEFAULTSHORTNAME_BASE // prevent it being used accidentally
  486. #undef DEFINE_DEFAULTSHORTNAME // prevent it being used accidentally
  487. #undef DEFINE_TIMESTAMPSHORTNAME
  488. //--------------------------------------------------------------------------------------------------------------------
  489. void queryLongStatisticName(StringBuffer & out, StatisticKind kind)
  490. {
  491. out.append(queryStatisticName(kind));
  492. }
  493. //--------------------------------------------------------------------------------------------------------------------
  494. //Keep prefixes on min/max/avg so they are consistent with short names (tags will eventually go...)
  495. #define DEFINE_TAGNAME(x, y, dft) \
  496. case St##x##y: return dft; \
  497. case (St ## x ## y | StMinX): return "@" #x "Min" # y; \
  498. case (St ## x ## y | StMaxX): return "@" #x "Max" # y; \
  499. case (St ## x ## y | StAvgX): return "@" #x "Avg" # y; \
  500. case (St ## x ## y | StSkew): return "@Skew" # y; \
  501. case (St ## x ## y | StSkewMin): return "@SkewMin" # y; \
  502. case (St ## x ## y | StSkewMax): return "@SkewMax" # y; \
  503. case (St ## x ## y | StNodeMin): return "@NodeMin" # y; \
  504. case (St ## x ## y | StNodeMax): return "@NodeMax" # y; \
  505. case (St ## x ## y | StDeltaX): return "@" #x "Delta" # y;
  506. #define DEFINE_DEFAULTTAGNAME(x, y) DEFINE_TAGNAME(x, y, "@" #x #y)
  507. const char * queryTreeTag(StatisticKind kind)
  508. {
  509. //For backward compatibility - where it matters. Will eventually be deleted.
  510. switch (kind)
  511. {
  512. DEFINE_DEFAULTTAGNAME(When, GraphStarted);
  513. DEFINE_DEFAULTTAGNAME(When, GraphFinished);
  514. DEFINE_DEFAULTTAGNAME(When, FirstRow);
  515. DEFINE_DEFAULTTAGNAME(When, QueryStarted);
  516. DEFINE_DEFAULTTAGNAME(When, QueryFinished);
  517. DEFINE_DEFAULTTAGNAME(When, Created);
  518. DEFINE_DEFAULTTAGNAME(When, Compiled);
  519. DEFINE_DEFAULTTAGNAME(When, WorkunitModified);
  520. DEFINE_DEFAULTTAGNAME(Time, Elapsed);
  521. DEFINE_TAGNAME(Time, LocalExecute, "@localTime");
  522. DEFINE_TAGNAME(Time, TotalExecute, "@totalTime");
  523. DEFINE_DEFAULTTAGNAME(Time, Remaining);
  524. DEFINE_DEFAULTTAGNAME(Size, GeneratedCpp);
  525. DEFINE_DEFAULTTAGNAME(Size, PeakMemory);
  526. DEFINE_DEFAULTTAGNAME(Size, MaxRowSize);
  527. //Primarily used for graph progress - backward compatible to simplify migration.
  528. DEFINE_TAGNAME(Num, RowsProcessed, "@count");
  529. DEFINE_TAGNAME(Num, Slaves, "@slaves");
  530. DEFINE_TAGNAME(Num, Started, "@started");
  531. DEFINE_TAGNAME(Num, Stopped, "@stopped");
  532. DEFINE_TAGNAME(Num, IndexSeeks, "@seeks");
  533. DEFINE_TAGNAME(Num, IndexScans, "@scans");
  534. DEFINE_TAGNAME(Num, IndexWildSeeks, "@wildscans");
  535. DEFINE_TAGNAME(Num, IndexSkips, "@skips");
  536. DEFINE_TAGNAME(Num, IndexNullSkips, "@nullskips");
  537. DEFINE_TAGNAME(Num, IndexMerges, "@merges");
  538. DEFINE_TAGNAME(Num, IndexMergeCompares, "@mergecompares");
  539. DEFINE_TAGNAME(Num, PreFiltered, "@prefiltered");
  540. DEFINE_TAGNAME(Num, PostFiltered, "@postfiltered");
  541. DEFINE_TAGNAME(Num, BlobCacheHits, "@blobhit");
  542. DEFINE_TAGNAME(Num, LeafCacheHits, "@leafhit");
  543. DEFINE_TAGNAME(Num, NodeCacheHits, "@nodehit");
  544. DEFINE_TAGNAME(Num, BlobCacheAdds, "@blobadd");
  545. DEFINE_TAGNAME(Num, LeafCacheAdds, "@leadadd");
  546. DEFINE_TAGNAME(Num, NodeCacheAdds, "@nodeadd");
  547. DEFINE_TAGNAME(Num, PreloadCacheHits, "@preloadhits");
  548. DEFINE_TAGNAME(Num, PreloadCacheAdds, "@preloadadds");
  549. DEFINE_TAGNAME(Num, ServerCacheHits, "@sschits");
  550. DEFINE_TAGNAME(Num, IndexAccepted, "@accepted");
  551. DEFINE_TAGNAME(Num, IndexRejected, "@rejected");
  552. DEFINE_TAGNAME(Num, AtmostTriggered, "@atmost");
  553. DEFINE_TAGNAME(Num, DiskSeeks, "@fseeks");
  554. DEFINE_DEFAULTTAGNAME(Num, Iterations);
  555. DEFINE_DEFAULTTAGNAME(Load, WhileSorting);
  556. DEFINE_DEFAULTTAGNAME(Num, LeftRows);
  557. DEFINE_DEFAULTTAGNAME(Num, RightRows);
  558. DEFINE_DEFAULTTAGNAME(Per, Replicated);
  559. DEFINE_DEFAULTTAGNAME(Num, DiskRowsRead);
  560. DEFINE_DEFAULTTAGNAME(Num, IndexRowsRead);
  561. DEFINE_DEFAULTTAGNAME(Num, DiskAccepted);
  562. DEFINE_DEFAULTTAGNAME(Num, DiskRejected);
  563. default:
  564. throwUnexpected();
  565. }
  566. }
  567. #undef DEFINE_DEFAULTTAGNAME
  568. //--------------------------------------------------------------------------------------------------------------------
  569. StatisticKind queryStatisticKind(const char * search)
  570. {
  571. if (!search)
  572. return StKindNone;
  573. if (streq(search, "*"))
  574. return StKindAll;
  575. //Slow - should use a hash table....
  576. for (unsigned i=0; i < StMax; i++)
  577. {
  578. StatisticKind kind = (StatisticKind)i;
  579. const char * shortName = queryStatisticName(kind);
  580. if (strieq(shortName, search))
  581. return kind;
  582. }
  583. return StKindNone;
  584. }
  585. //--------------------------------------------------------------------------------------------------------------------
  586. const char * queryCreatorTypeName(StatisticCreatorType sct)
  587. {
  588. return creatorTypeNames[sct];
  589. }
  590. StatisticCreatorType queryCreatorType(const char * sct)
  591. {
  592. //MORE: Use a hash table??
  593. return (StatisticCreatorType)matchString(creatorTypeNames, sct);
  594. }
  595. //--------------------------------------------------------------------------------------------------------------------
  596. const char * queryScopeTypeName(StatisticScopeType sst)
  597. {
  598. return scopeTypeNames[sst];
  599. }
  600. extern jlib_decl StatisticScopeType queryScopeType(const char * sst)
  601. {
  602. //MORE: Use a hash table??
  603. return (StatisticScopeType)matchString(scopeTypeNames, sst);
  604. }
  605. //--------------------------------------------------------------------------------------------------------------------
  606. inline void mergeUpdate(StatisticMeasure measure, unsigned __int64 & value, const unsigned __int64 otherValue)
  607. {
  608. switch (measure)
  609. {
  610. case SMeasureTimeNs:
  611. case SMeasureCount:
  612. case SMeasureSize:
  613. case SMeasureLoad:
  614. case SMeasureSkew:
  615. value += otherValue;
  616. break;
  617. case SMeasureTimestampUs:
  618. if (otherValue && otherValue < value)
  619. value = otherValue;
  620. break;
  621. }
  622. }
  623. unsigned __int64 mergeStatistic(StatisticMeasure measure, unsigned __int64 value, unsigned __int64 otherValue)
  624. {
  625. mergeUpdate(measure, value, otherValue);
  626. return value;
  627. }
  628. unsigned __int64 mergeStatisticValue(unsigned __int64 prevValue, unsigned __int64 newValue, StatsMergeAction mergeAction)
  629. {
  630. switch (mergeAction)
  631. {
  632. case StatsMergeKeep:
  633. return prevValue;
  634. case StatsMergeAppend:
  635. case StatsMergeReplace:
  636. return newValue;
  637. case StatsMergeSum:
  638. return prevValue + newValue;
  639. case StatsMergeMin:
  640. if (prevValue > newValue)
  641. return newValue;
  642. else
  643. return prevValue;
  644. case StatsMergeMax:
  645. if (prevValue < newValue)
  646. return newValue;
  647. else
  648. return prevValue;
  649. default:
  650. throwUnexpected();
  651. }
  652. }
  653. //--------------------------------------------------------------------------------------------------------------------
  654. class CComponentStatistics
  655. {
  656. protected:
  657. StringAttr creator;
  658. byte creatorDepth;
  659. byte scopeDepth;
  660. // StatisticArray stats;
  661. };
  662. //--------------------------------------------------------------------------------------------------------------------
  663. static int compareUnsigned(unsigned const * left, unsigned const * right)
  664. {
  665. return (*left < *right) ? -1 : (*left > *right) ? +1 : 0;
  666. }
  667. class StatisticsMapping
  668. {
  669. public:
  670. StatisticsMapping(StatisticKind kind, ...)
  671. {
  672. indexToKind.append(kind);
  673. va_list args;
  674. va_start(args, kind);
  675. for (;;)
  676. {
  677. unsigned next = va_arg(args, unsigned);
  678. if (!next)
  679. break;
  680. indexToKind.append(next);
  681. }
  682. va_end(args);
  683. process();
  684. }
  685. unsigned getIndex(StatisticKind kind) const { return kindToIndex.item(kind); }
  686. StatisticKind getKind(unsigned index) const { return (StatisticKind)indexToKind.item(index); }
  687. unsigned numStatistics() const { return indexToKind.ordinality(); }
  688. protected:
  689. void process()
  690. {
  691. //Possibly not needed, but sort the kinds, so that it is easy to merge/stream the results out in the correct order.
  692. indexToKind.sort(compareUnsigned);
  693. ForEachItemIn(i, indexToKind)
  694. {
  695. unsigned kind = indexToKind.item(i);
  696. while (kindToIndex.ordinality() < kind)
  697. kindToIndex.append(0);
  698. kindToIndex.replace(i, kind);
  699. }
  700. }
  701. protected:
  702. UnsignedArray kindToIndex;
  703. UnsignedArray indexToKind;
  704. };
  705. //--------------------------------------------------------------------------------------------------------------------
  706. class Statistic : public CInterfaceOf<IStatistic>
  707. {
  708. public:
  709. Statistic(StatisticKind _kind, unsigned __int64 _value) : kind(_kind), value(_value)
  710. {
  711. }
  712. static Statistic * deserialize(MemoryBuffer & in, unsigned version)
  713. {
  714. return new Statistic(in, version);
  715. }
  716. virtual StatisticKind queryKind() const
  717. {
  718. return kind;
  719. }
  720. virtual unsigned __int64 queryValue() const
  721. {
  722. return value;
  723. }
  724. void merge(unsigned __int64 otherValue)
  725. {
  726. mergeUpdate(queryMeasure(kind), value, otherValue);
  727. }
  728. void serialize(MemoryBuffer & out) const
  729. {
  730. //MORE: Could compress - e.g., store as a packed integers
  731. out.append((unsigned)kind);
  732. out.append(value);
  733. }
  734. protected:
  735. Statistic(MemoryBuffer & in, unsigned version)
  736. {
  737. unsigned _kind;
  738. in.read(_kind);
  739. kind = (StatisticKind)_kind;
  740. in.read(value);
  741. }
  742. public:
  743. StatisticKind kind;
  744. unsigned __int64 value;
  745. };
  746. //--------------------------------------------------------------------------------------------------------------------
  747. StringBuffer & StatsScopeId::getScopeText(StringBuffer & out) const
  748. {
  749. switch (scopeType)
  750. {
  751. case SSTgraph:
  752. return out.append(GraphScopePrefix).append(id);
  753. case SSTsubgraph:
  754. return out.append(SubGraphScopePrefix).append(id);
  755. case SSTactivity:
  756. return out.append(ActivityScopePrefix).append(id);
  757. case SSTedge:
  758. return out.append(EdgeScopePrefix).append(id).append("_").append(extra);
  759. default:
  760. throwUnexpected();
  761. }
  762. }
  763. unsigned StatsScopeId::getHash() const
  764. {
  765. return hashc((const byte *)&id, sizeof(id), (unsigned)scopeType);
  766. }
  767. bool StatsScopeId::matches(const StatsScopeId & other) const
  768. {
  769. return (scopeType == other.scopeType) && (id == other.id) && (extra == other.extra);
  770. }
  771. unsigned StatsScopeId::queryActivity() const
  772. {
  773. switch (scopeType)
  774. {
  775. case SSTactivity:
  776. case SSTedge:
  777. return id;
  778. default:
  779. return 0;
  780. }
  781. }
  782. void StatsScopeId::deserialize(MemoryBuffer & in, unsigned version)
  783. {
  784. byte scopeTypeByte;
  785. in.read(scopeTypeByte);
  786. scopeType = (StatisticScopeType)scopeTypeByte;
  787. switch (scopeType)
  788. {
  789. case SSTgraph:
  790. case SSTsubgraph:
  791. case SSTactivity:
  792. in.read(id);
  793. break;
  794. case SSTedge:
  795. in.read(id);
  796. in.read(extra);
  797. break;
  798. default:
  799. throwUnexpected();
  800. }
  801. }
  802. void StatsScopeId::serialize(MemoryBuffer & out) const
  803. {
  804. out.append((byte)scopeType);
  805. switch (scopeType)
  806. {
  807. case SSTgraph:
  808. case SSTsubgraph:
  809. case SSTactivity:
  810. out.append(id);
  811. break;
  812. case SSTedge:
  813. out.append(id);
  814. out.append(extra);
  815. break;
  816. default:
  817. throwUnexpected();
  818. }
  819. }
  820. void StatsScopeId::setId(StatisticScopeType _scopeType, unsigned _id, unsigned _extra)
  821. {
  822. scopeType = _scopeType;
  823. id = _id;
  824. extra = _extra;
  825. }
  826. bool StatsScopeId::setScopeText(const char * text)
  827. {
  828. if (MATCHES_CONST_PREFIX(text, ActivityScopePrefix))
  829. setActivityId(atoi(text + CONST_STRLEN(ActivityScopePrefix)));
  830. else if (MATCHES_CONST_PREFIX(text, GraphScopePrefix))
  831. setId(SSTgraph, atoi(text + CONST_STRLEN(GraphScopePrefix)));
  832. else if (MATCHES_CONST_PREFIX(text, SubGraphScopePrefix))
  833. setSubgraphId(atoi(text + CONST_STRLEN(SubGraphScopePrefix)));
  834. else if (MATCHES_CONST_PREFIX(text, EdgeScopePrefix))
  835. {
  836. const char * underscore = strchr(text, '_');
  837. if (!underscore)
  838. return false;
  839. setEdgeId(atoi(text + CONST_STRLEN(EdgeScopePrefix)), atoi(underscore+1));
  840. }
  841. else
  842. return false;
  843. return true;
  844. }
  845. void StatsScopeId::setActivityId(unsigned _id)
  846. {
  847. setId(SSTactivity, _id);
  848. }
  849. void StatsScopeId::setEdgeId(unsigned _id, unsigned _output)
  850. {
  851. setId(SSTedge, _id, _output);
  852. }
  853. void StatsScopeId::setSubgraphId(unsigned _id)
  854. {
  855. setId(SSTsubgraph, _id);
  856. }
  857. //Use an atom table to minimimize memory usage in esp.
  858. //The class could try and use a combination of the scope type and an unsigned, but I suspect not worth it.
  859. IAtom * createStatsScope(const char * name)
  860. {
  861. //MORE: Should this use a separate atom table?
  862. return createAtom(name);
  863. }
  864. IAtom * createActivityScope(unsigned value)
  865. {
  866. char temp[12];
  867. sprintf(temp, ActivityScopePrefix "%u", value);
  868. return createStatsScope(temp);
  869. }
  870. static IAtom * createSubGraphScope(unsigned value)
  871. {
  872. char temp[13];
  873. sprintf(temp, SubGraphScopePrefix "%u", value);
  874. return createStatsScope(temp);
  875. }
  876. IAtom * createEdgeScope(unsigned value1, unsigned value2)
  877. {
  878. StringBuffer temp;
  879. temp.append(EdgeScopePrefix).append(value1).append("_").append(value2);
  880. return createStatsScope(temp);
  881. }
  882. //--------------------------------------------------------------------------------------------------------------------
  883. enum
  884. {
  885. SCroot,
  886. SCintermediate,
  887. SCleaf,
  888. };
  889. class CStatisticCollection;
  890. static CStatisticCollection * deserializeCollection(CStatisticCollection * parent, MemoryBuffer & in, unsigned version);
  891. //MORE: Create an implementation with no children
  892. typedef StructArrayOf<Statistic> StatsArray;
  893. class CollectionHashTable : public SuperHashTableOf<CStatisticCollection, StatsScopeId>
  894. {
  895. public:
  896. ~CollectionHashTable() { releaseAll(); }
  897. virtual void onAdd(void *et);
  898. virtual void onRemove(void *et);
  899. virtual unsigned getHashFromElement(const void *et) const;
  900. virtual unsigned getHashFromFindParam(const void *fp) const;
  901. virtual const void * getFindParam(const void *et) const;
  902. virtual bool matchesFindParam(const void *et, const void *key, unsigned fphash) const;
  903. virtual bool matchesElement(const void *et, const void *searchET) const;
  904. };
  905. typedef IArrayOf<CStatisticCollection> CollectionArray;
  906. class CStatisticCollection : public CInterfaceOf<IStatisticCollection>
  907. {
  908. friend class CollectionHashTable;
  909. public:
  910. CStatisticCollection(CStatisticCollection * _parent, const StatsScopeId & _id) : parent(_parent), id(_id)
  911. {
  912. }
  913. CStatisticCollection(CStatisticCollection * _parent, MemoryBuffer & in, unsigned version) : parent(_parent)
  914. {
  915. id.deserialize(in, version);
  916. unsigned numStats;
  917. in.read(numStats);
  918. stats.ensure(numStats);
  919. while (numStats-- > 0)
  920. {
  921. Statistic * next = Statistic::deserialize(in, version);
  922. stats.append(*next);
  923. }
  924. unsigned numChildren;
  925. in.read(numChildren);
  926. children.ensure(numChildren);
  927. while (numChildren-- > 0)
  928. {
  929. CStatisticCollection * next = deserializeCollection(this, in, version);
  930. children.add(*next);
  931. }
  932. }
  933. virtual byte getCollectionType() const { return SCintermediate; }
  934. //interface IStatisticCollection:
  935. virtual StatisticScopeType queryScopeType() const
  936. {
  937. return id.queryScopeType();
  938. }
  939. virtual unsigned __int64 queryWhenCreated() const
  940. {
  941. if (parent)
  942. return parent->queryWhenCreated();
  943. return 0;
  944. }
  945. virtual StringBuffer & getScope(StringBuffer & str) const
  946. {
  947. return id.getScopeText(str);
  948. }
  949. virtual StringBuffer & getFullScope(StringBuffer & str) const
  950. {
  951. if (parent)
  952. {
  953. parent->getFullScope(str);
  954. str.append(':');
  955. }
  956. id.getScopeText(str);
  957. return str;
  958. }
  959. virtual unsigned __int64 queryStatistic(StatisticKind kind) const
  960. {
  961. ForEachItemIn(i, stats)
  962. {
  963. const Statistic & cur = stats.item(i);
  964. if (cur.kind == kind)
  965. return cur.value;
  966. }
  967. return 0;
  968. }
  969. virtual unsigned getNumStatistics() const
  970. {
  971. return stats.ordinality();
  972. }
  973. virtual void getStatistic(StatisticKind & kind, unsigned __int64 & value, unsigned idx) const
  974. {
  975. const Statistic & cur = stats.item(idx);
  976. kind = cur.kind;
  977. value = cur.value;
  978. }
  979. virtual IStatisticCollectionIterator & getScopes(const char * filter)
  980. {
  981. assertex(!filter);
  982. return * new SuperHashIIteratorOf<IStatisticCollection, IStatisticCollectionIterator, false>(children);
  983. }
  984. virtual void getMinMaxScope(IStringVal & minValue, IStringVal & maxValue, StatisticScopeType searchScopeType) const
  985. {
  986. if (id.queryScopeType() == searchScopeType)
  987. {
  988. const char * curMin = minValue.str();
  989. const char * curMax = maxValue.str();
  990. StringBuffer name;
  991. id.getScopeText(name);
  992. if (!curMin || !*curMin || strcmp(name.str(), curMin) < 0)
  993. minValue.set(name.str());
  994. if (!curMax || strcmp(name.str(), curMax) > 0)
  995. maxValue.set(name.str());
  996. }
  997. SuperHashIteratorOf<CStatisticCollection> iter(children, false);
  998. for (iter.first(); iter.isValid(); iter.next())
  999. iter.query().getMinMaxScope(minValue, maxValue, searchScopeType);
  1000. }
  1001. virtual void getMinMaxActivity(unsigned & minValue, unsigned & maxValue) const
  1002. {
  1003. unsigned activityId = id.queryActivity();
  1004. if (activityId)
  1005. {
  1006. if ((minValue == 0) || (activityId < minValue))
  1007. minValue = activityId;
  1008. if (activityId > maxValue)
  1009. maxValue = activityId;
  1010. }
  1011. SuperHashIteratorOf<CStatisticCollection> iter(children, false);
  1012. for (iter.first(); iter.isValid(); iter.next())
  1013. iter.query().getMinMaxActivity(minValue, maxValue);
  1014. }
  1015. //other public interface functions
  1016. void addStatistic(StatisticKind kind, unsigned __int64 value)
  1017. {
  1018. stats.append(*new Statistic(kind, value));
  1019. }
  1020. void updateStatistic(StatisticKind kind, unsigned __int64 value, StatsMergeAction mergeAction)
  1021. {
  1022. if (mergeAction != StatsMergeAppend)
  1023. {
  1024. ForEachItemIn(i, stats)
  1025. {
  1026. Statistic & cur = stats.element(i);
  1027. if (cur.kind == kind)
  1028. {
  1029. cur.value = mergeStatisticValue(cur.value, value, mergeAction);
  1030. return;
  1031. }
  1032. }
  1033. }
  1034. stats.append(*new Statistic(kind, value));
  1035. }
  1036. CStatisticCollection * ensureSubScope(const StatsScopeId & search, bool hasChildren)
  1037. {
  1038. //MORE: Implement hasChildren
  1039. return resolveSubScope(search, true, false);
  1040. }
  1041. CStatisticCollection * resolveSubScope(const StatsScopeId & search, bool create, bool replace)
  1042. {
  1043. if (!replace)
  1044. {
  1045. CStatisticCollection * match = children.find(&search);
  1046. if (match)
  1047. return LINK(match);
  1048. }
  1049. if (create)
  1050. {
  1051. CStatisticCollection * ret = new CStatisticCollection(this, search);
  1052. children.add(*ret);
  1053. return LINK(ret);
  1054. }
  1055. return NULL;
  1056. }
  1057. virtual void serialize(MemoryBuffer & out) const
  1058. {
  1059. out.append(getCollectionType());
  1060. id.serialize(out);
  1061. out.append(stats.ordinality());
  1062. ForEachItemIn(iStat, stats)
  1063. stats.item(iStat).serialize(out);
  1064. out.append(children.ordinality());
  1065. SuperHashIteratorOf<CStatisticCollection> iter(children, false);
  1066. for (iter.first(); iter.isValid(); iter.next())
  1067. iter.query().serialize(out);
  1068. }
  1069. private:
  1070. StatsScopeId id;
  1071. CStatisticCollection * parent;
  1072. CollectionHashTable children;
  1073. StatsArray stats;
  1074. };
  1075. //---------------------------------------------------------------------------------------------------------------------
  1076. void CollectionHashTable::onAdd(void *et)
  1077. {
  1078. }
  1079. void CollectionHashTable::onRemove(void *et)
  1080. {
  1081. CStatisticCollection * elem = reinterpret_cast<CStatisticCollection *>(et);
  1082. elem->Release();
  1083. }
  1084. unsigned CollectionHashTable::getHashFromElement(const void *et) const
  1085. {
  1086. const CStatisticCollection * elem = reinterpret_cast<const CStatisticCollection *>(et);
  1087. return elem->id.getHash();
  1088. }
  1089. unsigned CollectionHashTable::getHashFromFindParam(const void *fp) const
  1090. {
  1091. const StatsScopeId * search = reinterpret_cast<const StatsScopeId *>(fp);
  1092. return search->getHash();
  1093. }
  1094. const void * CollectionHashTable::getFindParam(const void *et) const
  1095. {
  1096. const CStatisticCollection * elem = reinterpret_cast<const CStatisticCollection *>(et);
  1097. return &elem->id;
  1098. }
  1099. bool CollectionHashTable::matchesFindParam(const void *et, const void *key, unsigned fphash) const
  1100. {
  1101. const CStatisticCollection * elem = reinterpret_cast<const CStatisticCollection *>(et);
  1102. const StatsScopeId * search = reinterpret_cast<const StatsScopeId *>(key);
  1103. return elem->id.matches(*search);
  1104. }
  1105. bool CollectionHashTable::matchesElement(const void *et, const void *searchET) const
  1106. {
  1107. const CStatisticCollection * elem = reinterpret_cast<const CStatisticCollection *>(et);
  1108. const CStatisticCollection * searchElem = reinterpret_cast<const CStatisticCollection *>(searchET);
  1109. return elem->id.matches(searchElem->id);
  1110. }
  1111. //---------------------------------------------------------------------------------------------------------------------
  1112. class CRootStatisticCollection : public CStatisticCollection
  1113. {
  1114. public:
  1115. CRootStatisticCollection(StatisticCreatorType _creatorType, const char * _creator, const StatsScopeId & _id)
  1116. : CStatisticCollection(NULL, _id), creatorType(_creatorType), creator(_creator)
  1117. {
  1118. whenCreated = getTimeStampNowValue();
  1119. }
  1120. CRootStatisticCollection(MemoryBuffer & in, unsigned version) : CStatisticCollection(NULL, in, version)
  1121. {
  1122. byte creatorTypeByte;
  1123. in.read(creatorTypeByte);
  1124. creatorType = (StatisticCreatorType)creatorTypeByte;
  1125. in.read(creator);
  1126. in.read(whenCreated);
  1127. }
  1128. virtual byte getCollectionType() const { return SCroot; }
  1129. virtual unsigned __int64 queryWhenCreated() const
  1130. {
  1131. return whenCreated;
  1132. }
  1133. virtual void serialize(MemoryBuffer & out) const
  1134. {
  1135. CStatisticCollection::serialize(out);
  1136. out.append((byte)creatorType);
  1137. out.append(creator);
  1138. out.append(whenCreated);
  1139. }
  1140. public:
  1141. StatisticCreatorType creatorType;
  1142. StringAttr creator;
  1143. unsigned __int64 whenCreated;
  1144. };
  1145. //---------------------------------------------------------------------------------------------------------------------
  1146. void serializeStatisticCollection(MemoryBuffer & out, IStatisticCollection * collection)
  1147. {
  1148. unsigned currentStatisticsVersion = 1;
  1149. out.append(currentStatisticsVersion);
  1150. collection->serialize(out);
  1151. }
  1152. static CStatisticCollection * deserializeCollection(CStatisticCollection * parent, MemoryBuffer & in, unsigned version)
  1153. {
  1154. byte kind;
  1155. in.read(kind);
  1156. switch (kind)
  1157. {
  1158. case SCroot:
  1159. assertex(!parent);
  1160. return new CRootStatisticCollection(in, version);
  1161. case SCintermediate:
  1162. return new CStatisticCollection(parent, in, version);
  1163. default:
  1164. UNIMPLEMENTED;
  1165. }
  1166. }
  1167. IStatisticCollection * createStatisticCollection(MemoryBuffer & in)
  1168. {
  1169. unsigned version;
  1170. in.read(version);
  1171. return deserializeCollection(NULL, in, version);
  1172. }
  1173. //--------------------------------------------------------------------------------------------------------------------
  1174. class StatisticGatherer : implements CInterfaceOf<IStatisticGatherer>
  1175. {
  1176. public:
  1177. StatisticGatherer(CStatisticCollection * scope) : rootScope(scope)
  1178. {
  1179. scopes.append(*scope);
  1180. }
  1181. virtual void beginScope(const StatsScopeId & id)
  1182. {
  1183. CStatisticCollection & tos = scopes.tos();
  1184. scopes.append(*tos.ensureSubScope(id, true));
  1185. }
  1186. virtual void beginActivityScope(unsigned id)
  1187. {
  1188. StatsScopeId scopeId(SSTactivity, id);
  1189. CStatisticCollection & tos = scopes.tos();
  1190. scopes.append(*tos.ensureSubScope(scopeId, false));
  1191. }
  1192. virtual void beginSubGraphScope(unsigned id)
  1193. {
  1194. StatsScopeId scopeId(SSTsubgraph, id);
  1195. CStatisticCollection & tos = scopes.tos();
  1196. scopes.append(*tos.ensureSubScope(scopeId, true));
  1197. }
  1198. virtual void beginEdgeScope(unsigned id, unsigned oid)
  1199. {
  1200. StatsScopeId scopeId(SSTedge, id, oid);
  1201. CStatisticCollection & tos = scopes.tos();
  1202. scopes.append(*tos.ensureSubScope(scopeId, false));
  1203. }
  1204. virtual void endScope()
  1205. {
  1206. scopes.pop();
  1207. }
  1208. virtual void addStatistic(StatisticKind kind, unsigned __int64 value)
  1209. {
  1210. CStatisticCollection & tos = scopes.tos();
  1211. tos.addStatistic(kind, value);
  1212. }
  1213. virtual void updateStatistic(StatisticKind kind, unsigned __int64 value, StatsMergeAction mergeAction)
  1214. {
  1215. CStatisticCollection & tos = scopes.tos();
  1216. tos.updateStatistic(kind, value, mergeAction);
  1217. }
  1218. virtual IStatisticCollection * getResult()
  1219. {
  1220. return LINK(rootScope);
  1221. }
  1222. protected:
  1223. ICopyArrayOf<CStatisticCollection> scopes;
  1224. Linked<CStatisticCollection> rootScope;
  1225. };
  1226. extern IStatisticGatherer * createStatisticsGatherer(StatisticCreatorType creatorType, const char * creator, const StatsScopeId & rootScope)
  1227. {
  1228. //creator unused at the moment.
  1229. Owned<CStatisticCollection> rootCollection = new CRootStatisticCollection(creatorType, creator, rootScope);
  1230. return new StatisticGatherer(rootCollection);
  1231. }
  1232. //--------------------------------------------------------------------------------------------------------------------
  1233. //This class is used to gather statistics for an activity.
  1234. class CRuntimeStatisticCollection : public IStatisticCollection
  1235. {
  1236. public:
  1237. CRuntimeStatisticCollection(const StatisticsMapping & _mapping) : mapping(_mapping)
  1238. {
  1239. unsigned num = mapping.numStatistics();
  1240. values = new unsigned __int64[num];
  1241. reset();
  1242. }
  1243. ~CRuntimeStatisticCollection()
  1244. {
  1245. delete [] values;
  1246. }
  1247. virtual void addStatistic(StatisticKind kind, unsigned __int64 value)
  1248. {
  1249. unsigned index = queryMapping().getIndex(kind);
  1250. values[index] += value;
  1251. }
  1252. virtual void setStatistic(StatisticKind kind, unsigned __int64 value)
  1253. {
  1254. unsigned index = queryMapping().getIndex(kind);
  1255. values[index] = value;
  1256. }
  1257. virtual unsigned __int64 getStatisticValue(StatisticKind kind) const
  1258. {
  1259. unsigned index = queryMapping().getIndex(kind);
  1260. return values[index];
  1261. }
  1262. void reset()
  1263. {
  1264. unsigned num = mapping.numStatistics();
  1265. memset(values, 0, sizeof(unsigned __int64) * num);
  1266. }
  1267. inline const StatisticsMapping & queryMapping() const { return mapping; };
  1268. inline unsigned ordinality() const { return mapping.numStatistics(); }
  1269. inline StatisticKind getKind(unsigned i) const { return mapping.getKind(i); }
  1270. private:
  1271. const StatisticsMapping & mapping;
  1272. unsigned __int64 * values;
  1273. };
  1274. void processStatistics(IStatisticGatherer & target, const CRuntimeStatisticCollection & stats)
  1275. {
  1276. ForEachItemIn(i, stats)
  1277. {
  1278. StatisticKind kind = stats.getKind(i);
  1279. target.addStatistic(kind, stats.getStatisticValue(kind));
  1280. }
  1281. }
  1282. // ------------------------- old code -------------------------
  1283. extern jlib_decl StatisticKind mapRoxieStatKind(unsigned i)
  1284. {
  1285. switch (i)
  1286. {
  1287. case STATS_INDEX_SEEKS: return StNumIndexSeeks;
  1288. case STATS_INDEX_SCANS: return StNumIndexScans;
  1289. case STATS_INDEX_WILDSEEKS: return StNumIndexWildSeeks;
  1290. case STATS_INDEX_SKIPS: return StNumIndexSkips;
  1291. case STATS_INDEX_NULLSKIPS: return StNumIndexNullSkips;
  1292. case STATS_INDEX_MERGES: return StNumIndexMerges;
  1293. case STATS_BLOBCACHEHIT: return StNumBlobCacheHits;
  1294. case STATS_LEAFCACHEHIT: return StNumLeafCacheHits;
  1295. case STATS_NODECACHEHIT: return StNumNodeCacheHits;
  1296. case STATS_PRELOADCACHEHIT: return StNumPreloadCacheHits;
  1297. case STATS_BLOBCACHEADD: return StNumBlobCacheAdds;
  1298. case STATS_LEAFCACHEADD: return StNumLeafCacheAdds;
  1299. case STATS_NODECACHEADD: return StNumNodeCacheAdds;
  1300. case STATS_PRELOADCACHEADD: return StNumPreloadCacheAdds;
  1301. case STATS_INDEX_MERGECOMPARES: return StNumIndexMergeCompares;
  1302. case STATS_SERVERCACHEHIT: return StNumServerCacheHits;
  1303. case STATS_ACCEPTED: return StNumIndexAccepted;
  1304. case STATS_REJECTED: return StNumIndexRejected;
  1305. case STATS_ATMOST: return StNumAtmostTriggered;
  1306. case STATS_DISK_SEEKS: return StNumDiskSeeks;
  1307. default:
  1308. throwUnexpected();
  1309. }
  1310. }
  1311. extern jlib_decl StatisticMeasure getStatMeasure(unsigned i)
  1312. {
  1313. return SMeasureCount;
  1314. }
  1315. //---------------------------------------------------
  1316. bool ScopedItemFilter::matchDepth(unsigned low, unsigned high) const
  1317. {
  1318. if (maxDepth && low && maxDepth < low)
  1319. return false;
  1320. if (minDepth && high && minDepth > high)
  1321. return false;
  1322. return true;
  1323. }
  1324. bool ScopedItemFilter::match(const char * search) const
  1325. {
  1326. if (search)
  1327. {
  1328. if (value)
  1329. {
  1330. if (hasWildcard)
  1331. {
  1332. //MORE: If wildcarding ends up being used a lot then this should be replaced with something that creates a DFA
  1333. if (!WildMatch(search, value, false))
  1334. return false;
  1335. }
  1336. else
  1337. {
  1338. return streq(search, value);
  1339. }
  1340. }
  1341. if (minDepth || maxDepth)
  1342. {
  1343. unsigned searchDepth = queryStatisticsDepth(search);
  1344. if (searchDepth < minDepth)
  1345. return false;
  1346. if (maxDepth && searchDepth > maxDepth)
  1347. return false;
  1348. }
  1349. }
  1350. return true;
  1351. }
  1352. void ScopedItemFilter::set(const char * _value)
  1353. {
  1354. if (_value && *_value && !streq(_value, "*") )
  1355. {
  1356. value.set(_value);
  1357. minDepth = queryStatisticsDepth(_value);
  1358. if (!strchr(_value, '*'))
  1359. {
  1360. maxDepth = minDepth;
  1361. hasWildcard = strchr(_value, '?') != NULL;
  1362. }
  1363. else
  1364. hasWildcard = true;
  1365. }
  1366. else
  1367. value.clear();
  1368. }
  1369. void ScopedItemFilter::setDepth(unsigned _depth)
  1370. {
  1371. minDepth = _depth;
  1372. maxDepth = _depth;
  1373. }
  1374. void ScopedItemFilter::setDepth(unsigned _minDepth, unsigned _maxDepth)
  1375. {
  1376. minDepth = _minDepth;
  1377. maxDepth = _maxDepth;
  1378. }
  1379. StatisticsFilter::StatisticsFilter()
  1380. {
  1381. init();
  1382. }
  1383. StatisticsFilter::StatisticsFilter(const char * filter)
  1384. {
  1385. init();
  1386. setFilter(filter);
  1387. }
  1388. StatisticsFilter::StatisticsFilter(StatisticCreatorType _creatorType, StatisticScopeType _scopeType, StatisticMeasure _measure, StatisticKind _kind)
  1389. {
  1390. init();
  1391. creatorType = _creatorType;
  1392. scopeType = _scopeType;
  1393. measure = _measure;
  1394. kind = _kind;
  1395. }
  1396. StatisticsFilter::StatisticsFilter(const char * _creatorType, const char * _scopeType, const char * _kind)
  1397. {
  1398. init();
  1399. set(_creatorType, _scopeType, _kind);
  1400. }
  1401. StatisticsFilter::StatisticsFilter(const char * _creatorTypeText, const char * _creator, const char * _scopeTypeText, const char * _scope, const char * _measureText, const char * _kindText)
  1402. {
  1403. init();
  1404. set(_creatorTypeText, _creator, _scopeTypeText, _scope, _measureText, _kindText);
  1405. }
  1406. StatisticsFilter::StatisticsFilter(StatisticCreatorType _creatorType, const char * _creator, StatisticScopeType _scopeType, const char * _scope, StatisticMeasure _measure, StatisticKind _kind)
  1407. {
  1408. init();
  1409. creatorType = _creatorType;
  1410. setCreator(_creator);
  1411. scopeType = _scopeType;
  1412. setScope(_scope);
  1413. measure = _measure;
  1414. kind = _kind;
  1415. }
  1416. void StatisticsFilter::init()
  1417. {
  1418. mergeSources = true;
  1419. creatorType = SCTall;
  1420. scopeType = SSTall;
  1421. measure = SMeasureAll;
  1422. kind = StKindAll;
  1423. }
  1424. bool StatisticsFilter::matches(StatisticCreatorType curCreatorType, const char * curCreator, StatisticScopeType curScopeType, const char * curScope, StatisticMeasure curMeasure, StatisticKind curKind) const
  1425. {
  1426. if ((curCreatorType != SCTall) && (creatorType != SCTall) && (creatorType != curCreatorType))
  1427. return false;
  1428. if ((curScopeType != SSTall) && (scopeType != SSTall) && (scopeType != curScopeType))
  1429. return false;
  1430. if ((curMeasure != SMeasureAll) && (measure != SMeasureAll) && (measure != curMeasure))
  1431. return false;
  1432. if ((curKind!= StKindAll) && (kind != StKindAll) && (kind != curKind))
  1433. return false;
  1434. if (!creatorFilter.match(curCreator))
  1435. return false;
  1436. if (!scopeFilter.match(curScope))
  1437. return false;
  1438. return true;
  1439. }
  1440. void StatisticsFilter::set(const char * creatorTypeText, const char * scopeTypeText, const char * kindText)
  1441. {
  1442. StatisticCreatorType creatorType = queryCreatorType(creatorTypeText);
  1443. StatisticScopeType scopeType = queryScopeType(scopeTypeText);
  1444. if (creatorType != SCTnone)
  1445. setCreatorType(creatorType);
  1446. if (scopeType != SSTnone)
  1447. setScopeType(scopeType);
  1448. setKind(kindText);
  1449. }
  1450. void StatisticsFilter::set(const char * _creatorTypeText, const char * _creator, const char * _scopeTypeText, const char * _scope, const char * _measureText, const char * _kindText)
  1451. {
  1452. StatisticMeasure newMeasure = queryMeasure(_measureText);
  1453. if (measure != SMeasureNone)
  1454. setMeasure(measure);
  1455. set(_creatorTypeText, _scopeTypeText, _kindText);
  1456. setCreator(_creator);
  1457. setScope(_scope);
  1458. }
  1459. void StatisticsFilter::setCreatorDepth(unsigned _minCreatorDepth, unsigned _maxCreatorDepth)
  1460. {
  1461. creatorFilter.setDepth(_minCreatorDepth, _maxCreatorDepth);
  1462. }
  1463. void StatisticsFilter::setCreator(const char * _creator)
  1464. {
  1465. creatorFilter.set(_creator);
  1466. }
  1467. void StatisticsFilter::setCreatorType(StatisticCreatorType _creatorType)
  1468. {
  1469. creatorType = _creatorType;
  1470. }
  1471. void StatisticsFilter::setFilter(const char * filter)
  1472. {
  1473. //MORE: Process the filter from a text representation
  1474. }
  1475. void StatisticsFilter::setScopeDepth(unsigned _scopeDepth)
  1476. {
  1477. scopeFilter.setDepth(_scopeDepth);
  1478. }
  1479. void StatisticsFilter::setScopeDepth(unsigned _minScopeDepth, unsigned _maxScopeDepth)
  1480. {
  1481. scopeFilter.setDepth(_minScopeDepth, _maxScopeDepth);
  1482. }
  1483. void StatisticsFilter::setScope(const char * _scope)
  1484. {
  1485. scopeFilter.set(_scope);
  1486. }
  1487. void StatisticsFilter::setScopeType(StatisticScopeType _scopeType)
  1488. {
  1489. scopeType = _scopeType;
  1490. }
  1491. void StatisticsFilter::setMeasure(StatisticMeasure _measure)
  1492. {
  1493. measure = _measure;
  1494. }
  1495. void StatisticsFilter::setMergeSources(bool _value)
  1496. {
  1497. mergeSources = _value;
  1498. }
  1499. void StatisticsFilter::setKind(StatisticKind _kind)
  1500. {
  1501. kind = _kind;
  1502. if (measure == SMeasureAll)
  1503. measure = queryMeasure(kind);
  1504. }
  1505. void StatisticsFilter::setKind(const char * _kind)
  1506. {
  1507. if (!_kind || !*_kind || streq(_kind, "*"))
  1508. {
  1509. measure = SMeasureAll;
  1510. kind = StKindAll;
  1511. return;
  1512. }
  1513. //Convert a kind wildcard to a measure
  1514. for (unsigned i1=SMeasureAll+1; i1 < SMeasureMax; i1++)
  1515. {
  1516. const char * prefix = queryMeasurePrefix((StatisticMeasure)i1);
  1517. size_t len = strlen(prefix);
  1518. if (strnicmp(_kind, prefix, len) == 0)
  1519. {
  1520. setMeasure((StatisticMeasure)i1);
  1521. //Treat When* and When as filters on times.
  1522. if (streq(_kind + len, "*") || !_kind[len])
  1523. return;
  1524. }
  1525. }
  1526. //Other wildcards not currently supported
  1527. kind = queryStatisticKind(_kind);
  1528. }
  1529. //---------------------------------------------------
  1530. class CStatsCategory : public CInterface
  1531. {
  1532. public:
  1533. StringAttr longName;
  1534. StringAttr shortName;
  1535. CStatsCategory(const char *_longName, const char *_shortName)
  1536. : longName(_longName), shortName(_shortName)
  1537. {
  1538. }
  1539. bool match(const char *_longName, const char *_shortName)
  1540. {
  1541. bool lm = stricmp(_longName, longName)==0;
  1542. bool sm = stricmp(_shortName, shortName)==0;
  1543. if (lm || sm)
  1544. {
  1545. if (lm && sm)
  1546. return true;
  1547. throw MakeStringException(0, "A stats category %s (%s) is already registered", shortName.get(), longName.get());
  1548. }
  1549. return false;
  1550. }
  1551. };
  1552. static CIArrayOf<CStatsCategory> statsCategories;
  1553. static CriticalSection statsCategoriesCrit;
  1554. extern int registerStatsCategory(const char *longName, const char *shortName)
  1555. {
  1556. CriticalBlock b(statsCategoriesCrit);
  1557. ForEachItemIn(idx, statsCategories)
  1558. {
  1559. if (statsCategories.item(idx).match(longName, shortName))
  1560. return idx;
  1561. }
  1562. statsCategories.append(*new CStatsCategory(longName, shortName));
  1563. return statsCategories.ordinality()-1;
  1564. }
  1565. static void checkKind(StatisticKind kind)
  1566. {
  1567. StatisticMeasure measure = queryMeasure(kind);
  1568. const char * shortName = queryStatisticName(kind);
  1569. StringBuffer longName;
  1570. queryLongStatisticName(longName, kind);
  1571. const char * tagName = queryTreeTag(kind);
  1572. const char * prefix = queryMeasurePrefix(measure);
  1573. //Check short names are all correctly prefixed.
  1574. assertex(strncmp(shortName, prefix, strlen(prefix)) == 0);
  1575. }
  1576. static void checkDistributedKind(StatisticKind kind)
  1577. {
  1578. checkKind(kind);
  1579. checkKind((StatisticKind)(kind|StMinX));
  1580. checkKind((StatisticKind)(kind|StMaxX));
  1581. checkKind((StatisticKind)(kind|StAvgX));
  1582. checkKind((StatisticKind)(kind|StSkew));
  1583. checkKind((StatisticKind)(kind|StSkewMin));
  1584. checkKind((StatisticKind)(kind|StSkewMax));
  1585. checkKind((StatisticKind)(kind|StNodeMin));
  1586. checkKind((StatisticKind)(kind|StNodeMax));
  1587. checkKind((StatisticKind)(kind|StDeltaX));
  1588. }
  1589. void verifyStatisticFunctions()
  1590. {
  1591. assertex(_elements_in(measureNames) == SMeasureMax+1 && !measureNames[SMeasureMax]);
  1592. assertex(_elements_in(creatorTypeNames) == SCTmax+1 && !creatorTypeNames[SCTmax]);
  1593. assertex(_elements_in(scopeTypeNames) == SSTmax+1 && !scopeTypeNames[SSTmax]);
  1594. //Check the various functions return values for all possible values.
  1595. for (unsigned i1=SMeasureAll; i1 < SMeasureMax; i1++)
  1596. {
  1597. const char * prefix = queryMeasurePrefix((StatisticMeasure)i1);
  1598. const char * name = queryMeasureName((StatisticMeasure)i1);
  1599. assertex(queryMeasure(name) == i1);
  1600. }
  1601. for (StatisticScopeType sst = SSTnone; sst < SSTmax; sst = (StatisticScopeType)(sst+1))
  1602. {
  1603. const char * name = queryScopeTypeName(sst);
  1604. assertex(queryScopeType(name) == sst);
  1605. }
  1606. for (StatisticCreatorType sct = SCTnone; sct < SCTmax; sct = (StatisticCreatorType)(sct+1))
  1607. {
  1608. const char * name = queryCreatorTypeName(sct);
  1609. assertex(queryCreatorType(name) == sct);
  1610. }
  1611. for (unsigned i2=StKindAll+1; i2 < StMax; i2++)
  1612. {
  1613. checkDistributedKind((StatisticKind)i2);
  1614. }
  1615. }
  1616. #if 0
  1617. MODULE_INIT(INIT_PRIORITY_STANDARD)
  1618. {
  1619. verifyStatisticFunctions();
  1620. return true;
  1621. }
  1622. #endif