jstats.cpp 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499
  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. #include "jfile.hpp"
  20. #include <math.h>
  21. #ifdef _WIN32
  22. #include <sys/timeb.h>
  23. #endif
  24. static CriticalSection statsNameCs;
  25. static StringBuffer statisticsComponentName;
  26. static StatisticCreatorType statisticsComponentType = SCTunknown;
  27. const static unsigned currentStatisticsVersion = 1;
  28. StatisticCreatorType queryStatisticsComponentType()
  29. {
  30. return statisticsComponentType;
  31. }
  32. const char * queryStatisticsComponentName()
  33. {
  34. CriticalBlock c(statsNameCs);
  35. if (statisticsComponentName.length() == 0)
  36. {
  37. statisticsComponentName.append("unknown").append(GetCachedHostName());
  38. DBGLOG("getProcessUniqueName hasn't been configured correctly");
  39. }
  40. return statisticsComponentName.str();
  41. }
  42. void setStatisticsComponentName(StatisticCreatorType processType, const char * processName, bool appendIP)
  43. {
  44. if (!processName)
  45. return;
  46. CriticalBlock c(statsNameCs);
  47. statisticsComponentType = processType;
  48. statisticsComponentName.clear().append(processName);
  49. if (appendIP)
  50. statisticsComponentName.append("@").append(GetCachedHostName()); // should I use _ instead?
  51. }
  52. //--------------------------------------------------------------------------------------------------------------------
  53. // Textual forms of the different enumerations, first items are for none and all.
  54. static const char * const measureNames[] = { "", "all", "ns", "ts", "cnt", "sz", "cpu", "skw", "node", "ppm", "ip", "cy", NULL };
  55. static const char * const creatorTypeNames[]= { "", "all", "unknown", "hthor", "roxie", "roxie:s", "thor", "thor:m", "thor:s", "eclcc", "esp", "summary", NULL };
  56. static const char * const scopeTypeNames[] = { "", "all", "global", "graph", "subgraph", "activity", "allocator", "section", "compile", "dfu", "edge", "function", NULL };
  57. static unsigned matchString(const char * const * names, const char * search)
  58. {
  59. if (!search)
  60. return 0;
  61. if (streq(search, "*"))
  62. search = "all";
  63. unsigned i=0;
  64. loop
  65. {
  66. const char * next = names[i];
  67. if (!next)
  68. return 0;
  69. if (strieq(next, search))
  70. return i;
  71. i++;
  72. }
  73. }
  74. //--------------------------------------------------------------------------------------------------------------------
  75. extern jlib_decl unsigned __int64 getTimeStampNowValue()
  76. {
  77. #ifdef _WIN32
  78. struct _timeb now;
  79. _ftime(&now);
  80. return (unsigned __int64)now.time * I64C(1000000) + now.millitm * 1000;
  81. #else
  82. struct timeval tm;
  83. gettimeofday(&tm,NULL);
  84. return (unsigned __int64)tm.tv_sec * I64C(1000000) + tm.tv_usec;
  85. #endif
  86. }
  87. const static unsigned __int64 msUntilResync = 1000; // resync every second ~= 1ms accuracy
  88. static cycle_t cyclesUntilResync;
  89. MODULE_INIT(INIT_PRIORITY_STANDARD)
  90. {
  91. cyclesUntilResync = nanosec_to_cycle(msUntilResync * 1000000);
  92. return true;
  93. }
  94. OptimizedTimestamp::OptimizedTimestamp()
  95. {
  96. lastCycles = get_cycles_now();
  97. lastTimestamp = ::getTimeStampNowValue();
  98. }
  99. #if 0
  100. //This version almost certainly has problems if the computer is suspended and cycles->nanoseconds is only accurate to
  101. //about 0.1% - so should only be used for relatively short periods
  102. unsigned __int64 OptimizedTimestamp::getTimeStampNowValue()
  103. {
  104. cycle_t nowCycles = get_cycles_now();
  105. return lastTimestamp + cycle_to_microsec(nowCycles - lastCycles);
  106. }
  107. #else
  108. //This version will resync every minute, but is not thread safe. Adding a critical section makes it less efficient than recalculating
  109. unsigned __int64 OptimizedTimestamp::getTimeStampNowValue()
  110. {
  111. cycle_t nowCycles = get_cycles_now();
  112. if (nowCycles - lastCycles > cyclesUntilResync)
  113. {
  114. lastCycles = nowCycles;
  115. lastTimestamp = ::getTimeStampNowValue();
  116. }
  117. return lastTimestamp + cycle_to_microsec(nowCycles - lastCycles);
  118. }
  119. #endif
  120. unsigned __int64 getIPV4StatsValue(const IpAddress & ip)
  121. {
  122. unsigned ipValue;
  123. if (ip.getNetAddress(sizeof(ipValue),&ipValue))
  124. return ipValue;
  125. return 0;
  126. }
  127. //--------------------------------------------------------------------------------------------------------------------
  128. const static unsigned __int64 oneMilliSecond = I64C(1000000);
  129. const static unsigned __int64 oneSecond = I64C(1000000000);
  130. const static unsigned __int64 oneMinute = I64C(60000000000);
  131. const static unsigned __int64 oneHour = I64C(3600000000000);
  132. const static unsigned __int64 oneDay = 24 * I64C(3600000000000);
  133. static void formatTime(StringBuffer & out, unsigned __int64 value)
  134. {
  135. //Aim to display at least 3 significant digits in the result string
  136. if (value < oneMilliSecond)
  137. out.appendf("%uns", (unsigned)value);
  138. else if (value < oneSecond)
  139. {
  140. unsigned uvalue = (unsigned)value;
  141. out.appendf("%u.%03ums", uvalue / 1000000, (uvalue / 1000) % 1000);
  142. }
  143. else
  144. {
  145. unsigned days = (unsigned)(value / oneDay);
  146. value = value % oneDay;
  147. unsigned hours = (unsigned)(value / oneHour);
  148. value = value % oneHour;
  149. unsigned mins = (unsigned)(value / oneMinute);
  150. value = value % oneMinute;
  151. unsigned secs = (unsigned)(value / oneSecond);
  152. unsigned ns = (unsigned)(value % oneSecond);
  153. if (days > 0)
  154. out.appendf("%u days ", days);
  155. if (hours > 0 || days)
  156. out.appendf("%u:%02u:%02u", hours, mins, secs);
  157. else if (mins >= 10)
  158. out.appendf("%u:%02u", mins, secs);
  159. else if (mins >= 1)
  160. out.appendf("%u:%02u.%03u", mins, secs, ns / 1000000);
  161. else
  162. out.appendf("%u.%03us", secs, ns / 1000000);
  163. }
  164. }
  165. extern void formatTimeCollatable(StringBuffer & out, unsigned __int64 value, bool nano)
  166. {
  167. unsigned days = (unsigned)(value / oneDay);
  168. value = value % oneDay;
  169. unsigned hours = (unsigned)(value / oneHour);
  170. value = value % oneHour;
  171. unsigned mins = (unsigned)(value / oneMinute);
  172. value = value % oneMinute;
  173. unsigned secs = (unsigned)(value / oneSecond);
  174. unsigned ns = (unsigned)(value % oneSecond);
  175. if (days)
  176. out.appendf(" %3ud ", days); // Two leading spaces helps the cassandra driver force to a single partition
  177. else
  178. out.appendf(" ");
  179. if (nano)
  180. out.appendf("%2u:%02u:%02u.%09u", hours, mins, secs, ns);
  181. else
  182. out.appendf("%2u:%02u:%02u.%03u", hours, mins, secs, ns/1000000);
  183. // More than 999 days, I don't care that it goes wrong.
  184. }
  185. extern unsigned __int64 extractTimeCollatable(const char *s, bool nano)
  186. {
  187. if (!s)
  188. return 0;
  189. unsigned days,hours,mins,secs,fracs;
  190. if (sscanf(s, " %ud %u:%u:%u.%u", &days, &hours, &mins, &secs, &fracs)!=5)
  191. {
  192. days = 0;
  193. if (sscanf(s, " %u:%u:%u.%u", &hours, &mins, &secs, &fracs) != 4)
  194. return 0;
  195. }
  196. unsigned __int64 ret = days*oneDay + hours*oneHour + mins*oneMinute + secs*oneSecond;
  197. if (nano)
  198. ret += fracs;
  199. else
  200. ret += milliToNano(fracs);
  201. return ret;
  202. }
  203. static void formatTimeStamp(StringBuffer & out, unsigned __int64 value)
  204. {
  205. time_t seconds = value / 1000000;
  206. unsigned us = value % 1000000;
  207. char timeStamp[64];
  208. time_t tNow = seconds;
  209. #ifdef _WIN32
  210. struct tm *gmtNow;
  211. gmtNow = gmtime(&tNow);
  212. strftime(timeStamp, 64, "%Y-%m-%dT%H:%M:%S", gmtNow);
  213. #else
  214. struct tm gmtNow;
  215. gmtime_r(&tNow, &gmtNow);
  216. strftime(timeStamp, 64, "%Y-%m-%dT%H:%M:%S", &gmtNow);
  217. #endif //_WIN32
  218. out.append(timeStamp).appendf(".%03uZ", us / 1000);
  219. }
  220. void formatTimeStampAsLocalTime(StringBuffer & out, unsigned __int64 value)
  221. {
  222. time_t seconds = value / 1000000;
  223. unsigned us = value % 1000000;
  224. char timeStamp[64];
  225. time_t tNow = seconds;
  226. #ifdef _WIN32
  227. struct tm *gmtNow;
  228. gmtNow = localtime(&tNow);
  229. strftime(timeStamp, 64, "%H:%M:%S", gmtNow);
  230. #else
  231. struct tm gmtNow;
  232. localtime_r(&tNow, &gmtNow);
  233. strftime(timeStamp, 64, "%H:%M:%S", &gmtNow);
  234. #endif //_WIN32
  235. out.append(timeStamp).appendf(".%03u", us / 1000);
  236. }
  237. static const unsigned oneKb = 1024;
  238. static const unsigned oneMb = 1024 * 1024;
  239. static const unsigned oneGb = 1024 * 1024 * 1024;
  240. static unsigned toPermille(unsigned x) { return (x * 1000) / 1024; }
  241. static void formatSize(StringBuffer & out, unsigned __int64 value)
  242. {
  243. unsigned Gb = (unsigned)(value / oneGb);
  244. unsigned Mb = (unsigned)((value % oneGb) / oneMb);
  245. unsigned Kb = (unsigned)((value % oneMb) / oneKb);
  246. unsigned b = (unsigned)(value % oneKb);
  247. if (Gb)
  248. out.appendf("%u.%03uGb", Gb, toPermille(Mb));
  249. else if (Mb)
  250. out.appendf("%u.%03uMb", Mb, toPermille(Kb));
  251. else if (Kb)
  252. out.appendf("%u.%03uKb", Kb, toPermille(b));
  253. else
  254. out.appendf("%ub", b);
  255. }
  256. static void formatLoad(StringBuffer & out, unsigned __int64 value)
  257. {
  258. //Stored as millionth of a core. Display as a percentage => scale by 10,000
  259. out.appendf("%u.%03u%%", (unsigned)(value / 10000), (unsigned)(value % 10000) / 10);
  260. }
  261. static void formatSkew(StringBuffer & out, unsigned __int64 value)
  262. {
  263. //Skew stored as 10000 = perfect, display as percentage
  264. out.appendf("%.2f%%", ((double)(__int64)value) / 100.0);
  265. }
  266. static void formatIPV4(StringBuffer & out, unsigned __int64 value)
  267. {
  268. byte ip1 = (value & 255);
  269. byte ip2 = ((value >> 8) & 255);
  270. byte ip3 = ((value >> 16) & 255);
  271. byte ip4 = ((value >> 24) & 255);
  272. out.appendf("%d.%d.%d.%d", ip1, ip2, ip3, ip4);
  273. }
  274. void formatStatistic(StringBuffer & out, unsigned __int64 value, StatisticMeasure measure)
  275. {
  276. switch (measure)
  277. {
  278. case SMeasureNone: // Unknown stat - e.g, on old esp accessing a new workunit
  279. out.append(value);
  280. break;
  281. case SMeasureTimeNs:
  282. formatTime(out, value);
  283. break;
  284. case SMeasureTimestampUs:
  285. formatTimeStamp(out, value);
  286. break;
  287. case SMeasureCount:
  288. out.append(value);
  289. break;
  290. case SMeasureSize:
  291. formatSize(out, value);
  292. break;
  293. case SMeasureLoad:
  294. formatLoad(out, value);
  295. break;
  296. case SMeasureSkew:
  297. formatSkew(out, value);
  298. break;
  299. case SMeasureNode:
  300. out.append(value);
  301. break;
  302. case SMeasurePercent:
  303. out.appendf("%.2f%%", (double)value / 10000.0); // stored as ppm
  304. break;
  305. case SMeasureIPV4:
  306. formatIPV4(out, value);
  307. break;
  308. case SMeasureCycle:
  309. out.append(value);
  310. break;
  311. default:
  312. throwUnexpected();
  313. }
  314. }
  315. void formatStatistic(StringBuffer & out, unsigned __int64 value, StatisticKind kind)
  316. {
  317. formatStatistic(out, value, queryMeasure(kind));
  318. }
  319. //--------------------------------------------------------------------------------------------------------------------
  320. unsigned queryStatisticsDepth(const char * text)
  321. {
  322. unsigned depth = 1;
  323. loop
  324. {
  325. switch (*text)
  326. {
  327. case 0:
  328. return depth;
  329. case ':':
  330. depth++;
  331. break;
  332. }
  333. text++;
  334. }
  335. }
  336. const char * queryMeasurePrefix(StatisticMeasure measure)
  337. {
  338. switch (measure)
  339. {
  340. case SMeasureAll: return NULL;
  341. case SMeasureTimeNs: return "Time";
  342. case SMeasureTimestampUs: return "When";
  343. case SMeasureCount: return "Num";
  344. case SMeasureSize: return "Size";
  345. case SMeasureLoad: return "Load";
  346. case SMeasureSkew: return "Skew";
  347. case SMeasureNode: return "Node";
  348. case SMeasurePercent: return "Per";
  349. case SMeasureIPV4: return "Ip";
  350. case SMeasureCycle: return "Cycle";
  351. default:
  352. throwUnexpected();
  353. }
  354. }
  355. const char * queryMeasureName(StatisticMeasure measure)
  356. {
  357. return measureNames[measure];
  358. }
  359. StatisticMeasure queryMeasure(const char * measure)
  360. {
  361. //MORE: Use a hash table??
  362. StatisticMeasure ret = (StatisticMeasure)matchString(measureNames, measure);
  363. //Legacy support for an unusual statistic - pretend the sizes are in bytes instead of kb.
  364. if ((ret == SMeasureNone) && measure)
  365. {
  366. if (streq(measure, "kb"))
  367. {
  368. ret = SMeasureSize;
  369. }
  370. else
  371. {
  372. for (unsigned i1=SMeasureAll+1; i1 < SMeasureMax; i1++)
  373. {
  374. const char * prefix = queryMeasurePrefix((StatisticMeasure)i1);
  375. if (strieq(measure, prefix))
  376. return (StatisticMeasure)i1;
  377. }
  378. }
  379. }
  380. return ret;
  381. }
  382. StatsMergeAction queryMergeMode(StatisticMeasure measure)
  383. {
  384. switch (measure)
  385. {
  386. case SMeasureTimeNs: return StatsMergeSum;
  387. case SMeasureTimestampUs: return StatsMergeKeepNonZero;
  388. case SMeasureCount: return StatsMergeSum;
  389. case SMeasureSize: return StatsMergeSum;
  390. case SMeasureLoad: return StatsMergeMax;
  391. case SMeasureSkew: return StatsMergeMax;
  392. case SMeasureNode: return StatsMergeKeepNonZero;
  393. case SMeasurePercent: return StatsMergeReplace;
  394. case SMeasureIPV4: return StatsMergeKeepNonZero;
  395. case SMeasureCycle: return StatsMergeSum;
  396. default:
  397. throwUnexpected();
  398. }
  399. }
  400. extern jlib_decl StatsMergeAction queryMergeMode(StatisticKind kind)
  401. {
  402. //MORE: Optimize by looking up in the meta
  403. return queryMergeMode(queryMeasure(kind));
  404. }
  405. //--------------------------------------------------------------------------------------------------------------------
  406. #define BASE_NAMES(x, y) \
  407. #x #y, \
  408. #x "Min" # y, \
  409. #x "Max" # y, \
  410. #x "Avg" # y, \
  411. "Skew" # y, \
  412. "SkewMin" # y, \
  413. "SkewMax" # y, \
  414. "NodeMin" # y, \
  415. "NodeMax" # y,
  416. #define NAMES(x, y) \
  417. BASE_NAMES(x, y) \
  418. #x "Delta" # y, \
  419. #x "StdDev" #y,
  420. #define WHENNAMES(x, y) \
  421. BASE_NAMES(x, y) \
  422. "TimeDelta" # y, \
  423. "TimeStdDev" # y,
  424. #define BASE_TAGS(x, y) \
  425. "@" #x "Min" # y, \
  426. "@" #x "Max" # y, \
  427. "@" #x "Avg" # y, \
  428. "@Skew" # y, \
  429. "@SkewMin" # y, \
  430. "@SkewMax" # y, \
  431. "@NodeMin" # y, \
  432. "@NodeMax" # y,
  433. //Default tags nothing special overriden
  434. #define TAGS(x, y) \
  435. "@" #x #y, \
  436. BASE_TAGS(x, y) \
  437. "@" #x "Delta" # y, \
  438. "@" #x "StdDev" # y,
  439. //Define the tags for time items.
  440. #define WHENTAGS(x, y) \
  441. "@" #x #y, \
  442. BASE_TAGS(x, y) \
  443. "@TimeDelta" # y, \
  444. "@TimeStdDev" # y,
  445. #define CORESTAT(x, y, m) St##x##y, m, St##x##y, { NAMES(x, y) }, { TAGS(x, y) }
  446. #define STAT(x, y, m) CORESTAT(x, y, m)
  447. //--------------------------------------------------------------------------------------------------------------------
  448. //These are the macros to use to define the different entries in the stats meta table
  449. #define TIMESTAT(y) STAT(Time, y, SMeasureTimeNs)
  450. #define WHENSTAT(y) St##When##y, SMeasureTimestampUs, St##When##y, { WHENNAMES(When, y) }, { WHENTAGS(When, y) }
  451. #define NUMSTAT(y) STAT(Num, y, SMeasureCount)
  452. #define SIZESTAT(y) STAT(Size, y, SMeasureSize)
  453. #define LOADSTAT(y) STAT(Load, y, SMeasureLoad)
  454. #define SKEWSTAT(y) STAT(Skew, y, SMeasureSkew)
  455. #define NODESTAT(y) STAT(Node, y, SMeasureNode)
  456. #define PERSTAT(y) STAT(Per, y, SMeasurePercent)
  457. #define IPV4STAT(y) STAT(IPV4, y, SMeasureIPV4)
  458. #define CYCLESTAT(y) St##Cycle##y##Cycles, SMeasureCycle, St##Time##y, { NAMES(Cycle, y##Cycles) }, { TAGS(Cycle, y##Cycles) }
  459. //--------------------------------------------------------------------------------------------------------------------
  460. class StatisticMeta
  461. {
  462. public:
  463. StatisticKind kind;
  464. StatisticMeasure measure;
  465. StatisticKind serializeKind;
  466. const char * names[StNextModifier/StVariantScale];
  467. const char * tags[StNextModifier/StVariantScale];
  468. };
  469. //The order of entries in this table must match the order in the enumeration
  470. static const StatisticMeta statsMetaData[StMax] = {
  471. { StKindNone, SMeasureNone, StKindNone, { "none" }, { "@none" } },
  472. { StKindAll, SMeasureAll, StKindAll, { "all" }, { "@all" } },
  473. { WHENSTAT(GraphStarted) },
  474. { WHENSTAT(GraphFinished) },
  475. { WHENSTAT(FirstRow) },
  476. { WHENSTAT(QueryStarted) },
  477. { WHENSTAT(QueryFinished) },
  478. { WHENSTAT(Created) },
  479. { WHENSTAT(Compiled) },
  480. { WHENSTAT(WorkunitModified) },
  481. { TIMESTAT(Elapsed) },
  482. { TIMESTAT(LocalExecute) },
  483. { TIMESTAT(TotalExecute) },
  484. { TIMESTAT(Remaining) },
  485. { SIZESTAT(GeneratedCpp) },
  486. { SIZESTAT(PeakMemory) },
  487. { SIZESTAT(MaxRowSize) },
  488. { NUMSTAT(RowsProcessed) },
  489. { NUMSTAT(Slaves) },
  490. { NUMSTAT(Started) },
  491. { NUMSTAT(Stopped) },
  492. { NUMSTAT(IndexSeeks) },
  493. { NUMSTAT(IndexScans) },
  494. { NUMSTAT(IndexWildSeeks) },
  495. { NUMSTAT(IndexSkips) },
  496. { NUMSTAT(IndexNullSkips) },
  497. { NUMSTAT(IndexMerges) },
  498. { NUMSTAT(IndexMergeCompares) },
  499. { NUMSTAT(PreFiltered) },
  500. { NUMSTAT(PostFiltered) },
  501. { NUMSTAT(BlobCacheHits) },
  502. { NUMSTAT(LeafCacheHits) },
  503. { NUMSTAT(NodeCacheHits) },
  504. { NUMSTAT(BlobCacheAdds) },
  505. { NUMSTAT(LeafCacheAdds) },
  506. { NUMSTAT(NodeCacheAdds) },
  507. { NUMSTAT(PreloadCacheHits) },
  508. { NUMSTAT(PreloadCacheAdds) },
  509. { NUMSTAT(ServerCacheHits) },
  510. { NUMSTAT(IndexAccepted) },
  511. { NUMSTAT(IndexRejected) },
  512. { NUMSTAT(AtmostTriggered) },
  513. { NUMSTAT(DiskSeeks) },
  514. { NUMSTAT(Iterations) },
  515. { LOADSTAT(WhileSorting) },
  516. { NUMSTAT(LeftRows) },
  517. { NUMSTAT(RightRows) },
  518. { PERSTAT(Replicated) },
  519. { NUMSTAT(DiskRowsRead) },
  520. { NUMSTAT(IndexRowsRead) },
  521. { NUMSTAT(DiskAccepted) },
  522. { NUMSTAT(DiskRejected) },
  523. { TIMESTAT(Soapcall) },
  524. { TIMESTAT(FirstExecute) },
  525. { TIMESTAT(DiskReadIO) },
  526. { TIMESTAT(DiskWriteIO) },
  527. { SIZESTAT(DiskRead) },
  528. { SIZESTAT(DiskWrite) },
  529. { CYCLESTAT(DiskReadIO) },
  530. { CYCLESTAT(DiskWriteIO) },
  531. { NUMSTAT(DiskReads) },
  532. { NUMSTAT(DiskWrites) },
  533. { NUMSTAT(Spills) },
  534. { TIMESTAT(SpillElapsed) },
  535. { TIMESTAT(SortElapsed) },
  536. { NUMSTAT(Groups) },
  537. { NUMSTAT(GroupMax) },
  538. { SIZESTAT(SpillFile) },
  539. { CYCLESTAT(SpillElapsed) },
  540. { CYCLESTAT(SortElapsed) },
  541. { NUMSTAT(Strands) },
  542. { CYCLESTAT(TotalExecute) },
  543. { NUMSTAT(Executions) },
  544. { TIMESTAT(TotalNested) },
  545. { CYCLESTAT(LocalExecute) },
  546. { NUMSTAT(Compares) },
  547. };
  548. //--------------------------------------------------------------------------------------------------------------------
  549. StatisticMeasure queryMeasure(StatisticKind kind)
  550. {
  551. unsigned variant = queryStatsVariant(kind);
  552. switch (variant)
  553. {
  554. case StSkew:
  555. case StSkewMin:
  556. case StSkewMax:
  557. return SMeasureSkew;
  558. case StNodeMin:
  559. case StNodeMax:
  560. return SMeasureNode;
  561. case StDeltaX:
  562. case StStdDevX:
  563. {
  564. StatisticMeasure measure = queryMeasure((StatisticKind)(kind & StKindMask));
  565. switch (measure)
  566. {
  567. case SMeasureTimestampUs:
  568. return SMeasureTimeNs;
  569. default:
  570. return measure;
  571. }
  572. break;
  573. }
  574. }
  575. StatisticKind rawkind = (StatisticKind)(kind & StKindMask);
  576. if (rawkind >= StKindNone && rawkind < StMax)
  577. return statsMetaData[rawkind].measure;
  578. return SMeasureNone;
  579. }
  580. const char * queryStatisticName(StatisticKind kind)
  581. {
  582. StatisticKind rawkind = (StatisticKind)(kind & StKindMask);
  583. unsigned variant = (kind / StVariantScale);
  584. dbgassertex(variant < (StNextModifier/StVariantScale));
  585. if (rawkind >= StKindNone && rawkind < StMax)
  586. return statsMetaData[rawkind].names[variant];
  587. return "Unknown";
  588. }
  589. unsigned __int64 convertMeasure(StatisticMeasure from, StatisticMeasure to, unsigned __int64 value)
  590. {
  591. if (from == to)
  592. return value;
  593. if ((from == SMeasureCycle) && (to == SMeasureTimeNs))
  594. return cycle_to_nanosec(value);
  595. if ((from == SMeasureTimeNs) && (to == SMeasureCycle))
  596. return nanosec_to_cycle(value);
  597. throwUnexpected();
  598. }
  599. unsigned __int64 convertMeasure(StatisticKind from, StatisticKind to, unsigned __int64 value)
  600. {
  601. return convertMeasure(queryMeasure(from), queryMeasure(to), value);
  602. }
  603. static double convertSquareMeasure(StatisticMeasure from, StatisticMeasure to, double value)
  604. {
  605. if (from == to)
  606. return value;
  607. const unsigned __int64 largeValue = 1000000000;
  608. double scale;
  609. if ((from == SMeasureCycle) && (to == SMeasureTimeNs))
  610. scale = (double)cycle_to_nanosec(largeValue) / (double)largeValue;
  611. else if ((from == SMeasureTimeNs) && (to == SMeasureCycle))
  612. scale = (double)nanosec_to_cycle(largeValue) / (double)largeValue;
  613. else
  614. throwUnexpected();
  615. return value * scale * scale;
  616. }
  617. static double convertSquareMeasure(StatisticKind from, StatisticKind to, double value)
  618. {
  619. return convertSquareMeasure(queryMeasure(from), queryMeasure(to), value);
  620. }
  621. StatisticKind querySerializedKind(StatisticKind kind)
  622. {
  623. StatisticKind rawkind = (StatisticKind)(kind & StKindMask);
  624. if (rawkind >= StMax)
  625. return kind;
  626. StatisticKind serialKind = statsMetaData[rawkind].serializeKind;
  627. return (StatisticKind)(serialKind | (kind & ~StKindMask));
  628. }
  629. //--------------------------------------------------------------------------------------------------------------------
  630. void queryLongStatisticName(StringBuffer & out, StatisticKind kind)
  631. {
  632. out.append(queryStatisticName(kind));
  633. }
  634. //--------------------------------------------------------------------------------------------------------------------
  635. const char * queryTreeTag(StatisticKind kind)
  636. {
  637. StatisticKind rawkind = (StatisticKind)(kind & StKindMask);
  638. unsigned variant = (kind / StVariantScale);
  639. dbgassertex(variant < (StNextModifier/StVariantScale));
  640. if (rawkind >= StKindNone && rawkind < StMax)
  641. return statsMetaData[rawkind].tags[variant];
  642. return "@Unknown";
  643. }
  644. //--------------------------------------------------------------------------------------------------------------------
  645. StatisticKind queryStatisticKind(const char * search)
  646. {
  647. if (!search)
  648. return StKindNone;
  649. if (streq(search, "*"))
  650. return StKindAll;
  651. //Slow - should use a hash table....
  652. for (unsigned variant=0; variant < StNextModifier; variant += StVariantScale)
  653. {
  654. for (unsigned i=0; i < StMax; i++)
  655. {
  656. StatisticKind kind = (StatisticKind)(i+variant);
  657. const char * shortName = queryStatisticName(kind);
  658. if (shortName && strieq(shortName, search))
  659. return kind;
  660. }
  661. }
  662. return StKindNone;
  663. }
  664. //--------------------------------------------------------------------------------------------------------------------
  665. const char * queryCreatorTypeName(StatisticCreatorType sct)
  666. {
  667. return creatorTypeNames[sct];
  668. }
  669. StatisticCreatorType queryCreatorType(const char * sct)
  670. {
  671. //MORE: Use a hash table??
  672. return (StatisticCreatorType)matchString(creatorTypeNames, sct);
  673. }
  674. //--------------------------------------------------------------------------------------------------------------------
  675. const char * queryScopeTypeName(StatisticScopeType sst)
  676. {
  677. return scopeTypeNames[sst];
  678. }
  679. extern jlib_decl StatisticScopeType queryScopeType(const char * sst)
  680. {
  681. //MORE: Use a hash table??
  682. return (StatisticScopeType)matchString(scopeTypeNames, sst);
  683. }
  684. //--------------------------------------------------------------------------------------------------------------------
  685. inline void mergeUpdate(StatisticMeasure measure, unsigned __int64 & value, const unsigned __int64 otherValue)
  686. {
  687. switch (measure)
  688. {
  689. case SMeasureTimeNs:
  690. case SMeasureCount:
  691. case SMeasureSize:
  692. case SMeasureLoad:
  693. case SMeasureSkew:
  694. case SMeasureCycle:
  695. value += otherValue;
  696. break;
  697. case SMeasureTimestampUs:
  698. if (otherValue && otherValue < value)
  699. value = otherValue;
  700. break;
  701. }
  702. }
  703. unsigned __int64 mergeStatistic(StatisticMeasure measure, unsigned __int64 value, unsigned __int64 otherValue)
  704. {
  705. mergeUpdate(measure, value, otherValue);
  706. return value;
  707. }
  708. unsigned __int64 mergeStatisticValue(unsigned __int64 prevValue, unsigned __int64 newValue, StatsMergeAction mergeAction)
  709. {
  710. switch (mergeAction)
  711. {
  712. case StatsMergeKeepNonZero:
  713. if (prevValue)
  714. return prevValue;
  715. return newValue;
  716. case StatsMergeAppend:
  717. case StatsMergeReplace:
  718. return newValue;
  719. case StatsMergeSum:
  720. return prevValue + newValue;
  721. case StatsMergeMin:
  722. if (prevValue > newValue)
  723. return newValue;
  724. else
  725. return prevValue;
  726. case StatsMergeMax:
  727. if (prevValue < newValue)
  728. return newValue;
  729. else
  730. return prevValue;
  731. default:
  732. throwUnexpected();
  733. }
  734. }
  735. //--------------------------------------------------------------------------------------------------------------------
  736. class CComponentStatistics
  737. {
  738. protected:
  739. StringAttr creator;
  740. byte creatorDepth;
  741. byte scopeDepth;
  742. // StatisticArray stats;
  743. };
  744. //--------------------------------------------------------------------------------------------------------------------
  745. static int compareUnsigned(unsigned const * left, unsigned const * right)
  746. {
  747. return (*left < *right) ? -1 : (*left > *right) ? +1 : 0;
  748. }
  749. StatisticsMapping::StatisticsMapping(StatisticKind kind, ...)
  750. {
  751. if (kind != StKindNone)
  752. {
  753. indexToKind.append(kind);
  754. va_list args;
  755. va_start(args, kind);
  756. for (;;)
  757. {
  758. unsigned next = va_arg(args, unsigned);
  759. if (!next)
  760. break;
  761. indexToKind.appendUniq(next);
  762. }
  763. va_end(args);
  764. }
  765. createMappings();
  766. }
  767. StatisticsMapping::StatisticsMapping(const StatisticsMapping * from, ...)
  768. {
  769. ForEachItemIn(idx, from->indexToKind)
  770. indexToKind.append(from->indexToKind.item(idx));
  771. va_list args;
  772. va_start(args, from);
  773. for (;;)
  774. {
  775. unsigned next = va_arg(args, unsigned);
  776. if (!next)
  777. break;
  778. indexToKind.appendUniq(next);
  779. }
  780. va_end(args);
  781. createMappings();
  782. }
  783. StatisticsMapping::StatisticsMapping()
  784. {
  785. for (int i = StKindAll+1; i < StMax; i++)
  786. indexToKind.append(i);
  787. createMappings();
  788. }
  789. void StatisticsMapping::createMappings()
  790. {
  791. //Possibly not needed, but sort the kinds, so that it is easy to merge/stream the results out in the correct order.
  792. indexToKind.sort(compareUnsigned);
  793. //Provide mappings to all statistics to map them to the "unknown" bin by default
  794. for (unsigned i=0; i < StMax; i++)
  795. kindToIndex.append(numStatistics());
  796. ForEachItemIn(i2, indexToKind)
  797. {
  798. unsigned kind = indexToKind.item(i2);
  799. kindToIndex.replace(i2, kind);
  800. }
  801. }
  802. const StatisticsMapping allStatistics;
  803. const StatisticsMapping diskLocalStatistics(StCycleDiskReadIOCycles, StSizeDiskRead, StNumDiskReads, StCycleDiskWriteIOCycles, StSizeDiskWrite, StNumDiskWrites, StKindNone);
  804. const StatisticsMapping diskRemoteStatistics(StTimeDiskReadIO, StSizeDiskRead, StNumDiskReads, StTimeDiskWriteIO, StSizeDiskWrite, StNumDiskWrites, StKindNone);
  805. const StatisticsMapping diskReadRemoteStatistics(StTimeDiskReadIO, StSizeDiskRead, StNumDiskReads, StKindNone);
  806. const StatisticsMapping diskWriteRemoteStatistics(StTimeDiskWriteIO, StSizeDiskWrite, StNumDiskWrites, StKindNone);
  807. //--------------------------------------------------------------------------------------------------------------------
  808. class Statistic
  809. {
  810. public:
  811. Statistic(StatisticKind _kind, unsigned __int64 _value) : kind(_kind), value(_value)
  812. {
  813. }
  814. Statistic(MemoryBuffer & in, unsigned version)
  815. {
  816. unsigned _kind;
  817. in.read(_kind);
  818. kind = (StatisticKind)_kind;
  819. in.read(value);
  820. }
  821. virtual StatisticKind queryKind() const
  822. {
  823. return kind;
  824. }
  825. virtual unsigned __int64 queryValue() const
  826. {
  827. return value;
  828. }
  829. void merge(unsigned __int64 otherValue)
  830. {
  831. mergeUpdate(queryMeasure(kind), value, otherValue);
  832. }
  833. void serialize(MemoryBuffer & out) const
  834. {
  835. //MORE: Could compress - e.g., store as a packed integers
  836. out.append((unsigned)kind);
  837. out.append(value);
  838. }
  839. StringBuffer & toXML(StringBuffer &out) const
  840. {
  841. return out.append(" <Stat name=\"").append(queryStatisticName(kind)).append("\" value=\"").append(value).append("\"/>\n");
  842. }
  843. public:
  844. StatisticKind kind;
  845. unsigned __int64 value;
  846. };
  847. //--------------------------------------------------------------------------------------------------------------------
  848. StringBuffer & StatsScopeId::getScopeText(StringBuffer & out) const
  849. {
  850. switch (scopeType)
  851. {
  852. case SSTgraph:
  853. return out.append(GraphScopePrefix).append(id);
  854. case SSTsubgraph:
  855. return out.append(SubGraphScopePrefix).append(id);
  856. case SSTactivity:
  857. return out.append(ActivityScopePrefix).append(id);
  858. case SSTedge:
  859. return out.append(EdgeScopePrefix).append(id).append("_").append(extra);
  860. case SSTfunction:
  861. return out.append(FunctionScopePrefix).append(name);
  862. default:
  863. throwUnexpected();
  864. break;
  865. }
  866. }
  867. unsigned StatsScopeId::getHash() const
  868. {
  869. switch (scopeType)
  870. {
  871. case SSTfunction:
  872. return hashc((const byte *)name.get(), strlen(name), (unsigned)scopeType);
  873. default:
  874. return hashc((const byte *)&id, sizeof(id), (unsigned)scopeType);
  875. }
  876. }
  877. bool StatsScopeId::matches(const StatsScopeId & other) const
  878. {
  879. return (scopeType == other.scopeType) && (id == other.id) && (extra == other.extra) && strsame(name, other.name);
  880. }
  881. unsigned StatsScopeId::queryActivity() const
  882. {
  883. switch (scopeType)
  884. {
  885. case SSTactivity:
  886. case SSTedge:
  887. return id;
  888. default:
  889. return 0;
  890. }
  891. }
  892. void StatsScopeId::deserialize(MemoryBuffer & in, unsigned version)
  893. {
  894. byte scopeTypeByte;
  895. in.read(scopeTypeByte);
  896. scopeType = (StatisticScopeType)scopeTypeByte;
  897. switch (scopeType)
  898. {
  899. case SSTgraph:
  900. case SSTsubgraph:
  901. case SSTactivity:
  902. in.read(id);
  903. break;
  904. case SSTedge:
  905. in.read(id);
  906. in.read(extra);
  907. break;
  908. case SSTfunction:
  909. in.read(name);
  910. break;
  911. default:
  912. throwUnexpected();
  913. break;
  914. }
  915. }
  916. void StatsScopeId::serialize(MemoryBuffer & out) const
  917. {
  918. out.append((byte)scopeType);
  919. switch (scopeType)
  920. {
  921. case SSTgraph:
  922. case SSTsubgraph:
  923. case SSTactivity:
  924. out.append(id);
  925. break;
  926. case SSTedge:
  927. out.append(id);
  928. out.append(extra);
  929. break;
  930. case SSTfunction:
  931. out.append(name);
  932. break;
  933. default:
  934. throwUnexpected();
  935. break;
  936. }
  937. }
  938. void StatsScopeId::setId(StatisticScopeType _scopeType, unsigned _id, unsigned _extra)
  939. {
  940. scopeType = _scopeType;
  941. id = _id;
  942. extra = _extra;
  943. }
  944. bool StatsScopeId::setScopeText(const char * text)
  945. {
  946. if (MATCHES_CONST_PREFIX(text, ActivityScopePrefix))
  947. setActivityId(atoi(text + CONST_STRLEN(ActivityScopePrefix)));
  948. else if (MATCHES_CONST_PREFIX(text, GraphScopePrefix))
  949. setId(SSTgraph, atoi(text + CONST_STRLEN(GraphScopePrefix)));
  950. else if (MATCHES_CONST_PREFIX(text, SubGraphScopePrefix))
  951. setSubgraphId(atoi(text + CONST_STRLEN(SubGraphScopePrefix)));
  952. else if (MATCHES_CONST_PREFIX(text, EdgeScopePrefix))
  953. {
  954. const char * underscore = strchr(text, '_');
  955. if (!underscore)
  956. return false;
  957. setEdgeId(atoi(text + CONST_STRLEN(EdgeScopePrefix)), atoi(underscore+1));
  958. }
  959. else if (MATCHES_CONST_PREFIX(text, FunctionScopePrefix))
  960. setFunctionId(text+CONST_STRLEN(FunctionScopePrefix));
  961. else
  962. return false;
  963. return true;
  964. }
  965. void StatsScopeId::setActivityId(unsigned _id)
  966. {
  967. setId(SSTactivity, _id);
  968. }
  969. void StatsScopeId::setEdgeId(unsigned _id, unsigned _output)
  970. {
  971. setId(SSTedge, _id, _output);
  972. }
  973. void StatsScopeId::setSubgraphId(unsigned _id)
  974. {
  975. setId(SSTsubgraph, _id);
  976. }
  977. void StatsScopeId::setFunctionId(const char * _name)
  978. {
  979. scopeType = SSTfunction;
  980. name.set(_name);
  981. }
  982. //--------------------------------------------------------------------------------------------------------------------
  983. enum
  984. {
  985. SCroot,
  986. SCintermediate,
  987. SCleaf,
  988. };
  989. class CStatisticCollection;
  990. static CStatisticCollection * deserializeCollection(CStatisticCollection * parent, MemoryBuffer & in, unsigned version);
  991. //MORE: Create an implementation with no children
  992. typedef StructArrayOf<Statistic> StatsArray;
  993. class CollectionHashTable : public SuperHashTableOf<CStatisticCollection, StatsScopeId>
  994. {
  995. public:
  996. ~CollectionHashTable() { _releaseAll(); }
  997. virtual void onAdd(void *et);
  998. virtual void onRemove(void *et);
  999. virtual unsigned getHashFromElement(const void *et) const;
  1000. virtual unsigned getHashFromFindParam(const void *fp) const;
  1001. virtual const void * getFindParam(const void *et) const;
  1002. virtual bool matchesFindParam(const void *et, const void *key, unsigned fphash) const;
  1003. virtual bool matchesElement(const void *et, const void *searchET) const;
  1004. };
  1005. typedef IArrayOf<CStatisticCollection> CollectionArray;
  1006. class CStatisticCollection : public CInterfaceOf<IStatisticCollection>
  1007. {
  1008. friend class CollectionHashTable;
  1009. public:
  1010. CStatisticCollection(CStatisticCollection * _parent, const StatsScopeId & _id) : id(_id), parent(_parent)
  1011. {
  1012. }
  1013. CStatisticCollection(CStatisticCollection * _parent, MemoryBuffer & in, unsigned version) : parent(_parent)
  1014. {
  1015. id.deserialize(in, version);
  1016. unsigned numStats;
  1017. in.read(numStats);
  1018. stats.ensure(numStats);
  1019. while (numStats-- > 0)
  1020. {
  1021. Statistic next (in, version);
  1022. stats.append(next);
  1023. }
  1024. unsigned numChildren;
  1025. in.read(numChildren);
  1026. children.ensure(numChildren);
  1027. while (numChildren-- > 0)
  1028. {
  1029. CStatisticCollection * next = deserializeCollection(this, in, version);
  1030. children.add(*next);
  1031. }
  1032. }
  1033. virtual byte getCollectionType() const { return SCintermediate; }
  1034. StringBuffer &toXML(StringBuffer &out) const;
  1035. //interface IStatisticCollection:
  1036. virtual StatisticScopeType queryScopeType() const
  1037. {
  1038. return id.queryScopeType();
  1039. }
  1040. virtual unsigned __int64 queryWhenCreated() const
  1041. {
  1042. if (parent)
  1043. return parent->queryWhenCreated();
  1044. return 0;
  1045. }
  1046. virtual StringBuffer & getScope(StringBuffer & str) const
  1047. {
  1048. return id.getScopeText(str);
  1049. }
  1050. virtual StringBuffer & getFullScope(StringBuffer & str) const
  1051. {
  1052. if (parent)
  1053. {
  1054. parent->getFullScope(str);
  1055. str.append(':');
  1056. }
  1057. id.getScopeText(str);
  1058. return str;
  1059. }
  1060. virtual unsigned __int64 queryStatistic(StatisticKind kind) const
  1061. {
  1062. ForEachItemIn(i, stats)
  1063. {
  1064. const Statistic & cur = stats.item(i);
  1065. if (cur.kind == kind)
  1066. return cur.value;
  1067. }
  1068. return 0;
  1069. }
  1070. virtual unsigned getNumStatistics() const
  1071. {
  1072. return stats.ordinality();
  1073. }
  1074. virtual void getStatistic(StatisticKind & kind, unsigned __int64 & value, unsigned idx) const
  1075. {
  1076. const Statistic & cur = stats.item(idx);
  1077. kind = cur.kind;
  1078. value = cur.value;
  1079. }
  1080. virtual IStatisticCollectionIterator & getScopes(const char * filter)
  1081. {
  1082. assertex(!filter);
  1083. return * new SuperHashIIteratorOf<IStatisticCollection, IStatisticCollectionIterator, false>(children);
  1084. }
  1085. virtual void getMinMaxScope(IStringVal & minValue, IStringVal & maxValue, StatisticScopeType searchScopeType) const
  1086. {
  1087. if (id.queryScopeType() == searchScopeType)
  1088. {
  1089. const char * curMin = minValue.str();
  1090. const char * curMax = maxValue.str();
  1091. StringBuffer name;
  1092. id.getScopeText(name);
  1093. if (!curMin || !*curMin || strcmp(name.str(), curMin) < 0)
  1094. minValue.set(name.str());
  1095. if (!curMax || strcmp(name.str(), curMax) > 0)
  1096. maxValue.set(name.str());
  1097. }
  1098. SuperHashIteratorOf<CStatisticCollection> iter(children, false);
  1099. for (iter.first(); iter.isValid(); iter.next())
  1100. iter.query().getMinMaxScope(minValue, maxValue, searchScopeType);
  1101. }
  1102. virtual void getMinMaxActivity(unsigned & minValue, unsigned & maxValue) const
  1103. {
  1104. unsigned activityId = id.queryActivity();
  1105. if (activityId)
  1106. {
  1107. if ((minValue == 0) || (activityId < minValue))
  1108. minValue = activityId;
  1109. if (activityId > maxValue)
  1110. maxValue = activityId;
  1111. }
  1112. SuperHashIteratorOf<CStatisticCollection> iter(children, false);
  1113. for (iter.first(); iter.isValid(); iter.next())
  1114. iter.query().getMinMaxActivity(minValue, maxValue);
  1115. }
  1116. //other public interface functions
  1117. void addStatistic(StatisticKind kind, unsigned __int64 value)
  1118. {
  1119. Statistic s(kind, value);
  1120. stats.append(s);
  1121. }
  1122. void updateStatistic(StatisticKind kind, unsigned __int64 value, StatsMergeAction mergeAction)
  1123. {
  1124. if (mergeAction != StatsMergeAppend)
  1125. {
  1126. ForEachItemIn(i, stats)
  1127. {
  1128. Statistic & cur = stats.element(i);
  1129. if (cur.kind == kind)
  1130. {
  1131. cur.value = mergeStatisticValue(cur.value, value, mergeAction);
  1132. return;
  1133. }
  1134. }
  1135. }
  1136. Statistic s(kind, value);
  1137. stats.append(s);
  1138. }
  1139. CStatisticCollection * ensureSubScope(const StatsScopeId & search, bool hasChildren)
  1140. {
  1141. //MORE: Implement hasChildren
  1142. return resolveSubScope(search, true, false);
  1143. }
  1144. CStatisticCollection * resolveSubScope(const StatsScopeId & search, bool create, bool replace)
  1145. {
  1146. if (!replace)
  1147. {
  1148. CStatisticCollection * match = children.find(&search);
  1149. if (match)
  1150. return LINK(match);
  1151. }
  1152. if (create)
  1153. {
  1154. CStatisticCollection * ret = new CStatisticCollection(this, search);
  1155. children.add(*ret);
  1156. return LINK(ret);
  1157. }
  1158. return NULL;
  1159. }
  1160. virtual void serialize(MemoryBuffer & out) const
  1161. {
  1162. out.append(getCollectionType());
  1163. id.serialize(out);
  1164. out.append(stats.ordinality());
  1165. ForEachItemIn(iStat, stats)
  1166. stats.item(iStat).serialize(out);
  1167. out.append(children.ordinality());
  1168. SuperHashIteratorOf<CStatisticCollection> iter(children, false);
  1169. for (iter.first(); iter.isValid(); iter.next())
  1170. iter.query().serialize(out);
  1171. }
  1172. private:
  1173. StatsScopeId id;
  1174. CStatisticCollection * parent;
  1175. CollectionHashTable children;
  1176. StatsArray stats;
  1177. };
  1178. StringBuffer &CStatisticCollection::toXML(StringBuffer &out) const
  1179. {
  1180. out.append("<Scope id=\"");
  1181. id.getScopeText(out).append("\">\n");
  1182. if (stats.ordinality())
  1183. {
  1184. out.append(" <Stats>");
  1185. ForEachItemIn(i, stats)
  1186. stats.item(i).toXML(out);
  1187. out.append(" </Stats>\n");
  1188. }
  1189. SuperHashIteratorOf<CStatisticCollection> iter(children, false);
  1190. for (iter.first(); iter.isValid(); iter.next())
  1191. iter.query().toXML(out);
  1192. out.append("</Scope>\n");
  1193. return out;
  1194. }
  1195. //---------------------------------------------------------------------------------------------------------------------
  1196. void CollectionHashTable::onAdd(void *et)
  1197. {
  1198. }
  1199. void CollectionHashTable::onRemove(void *et)
  1200. {
  1201. CStatisticCollection * elem = reinterpret_cast<CStatisticCollection *>(et);
  1202. elem->Release();
  1203. }
  1204. unsigned CollectionHashTable::getHashFromElement(const void *et) const
  1205. {
  1206. const CStatisticCollection * elem = reinterpret_cast<const CStatisticCollection *>(et);
  1207. return elem->id.getHash();
  1208. }
  1209. unsigned CollectionHashTable::getHashFromFindParam(const void *fp) const
  1210. {
  1211. const StatsScopeId * search = reinterpret_cast<const StatsScopeId *>(fp);
  1212. return search->getHash();
  1213. }
  1214. const void * CollectionHashTable::getFindParam(const void *et) const
  1215. {
  1216. const CStatisticCollection * elem = reinterpret_cast<const CStatisticCollection *>(et);
  1217. return &elem->id;
  1218. }
  1219. bool CollectionHashTable::matchesFindParam(const void *et, const void *key, unsigned fphash) const
  1220. {
  1221. const CStatisticCollection * elem = reinterpret_cast<const CStatisticCollection *>(et);
  1222. const StatsScopeId * search = reinterpret_cast<const StatsScopeId *>(key);
  1223. return elem->id.matches(*search);
  1224. }
  1225. bool CollectionHashTable::matchesElement(const void *et, const void *searchET) const
  1226. {
  1227. const CStatisticCollection * elem = reinterpret_cast<const CStatisticCollection *>(et);
  1228. const CStatisticCollection * searchElem = reinterpret_cast<const CStatisticCollection *>(searchET);
  1229. return elem->id.matches(searchElem->id);
  1230. }
  1231. //---------------------------------------------------------------------------------------------------------------------
  1232. class CRootStatisticCollection : public CStatisticCollection
  1233. {
  1234. public:
  1235. CRootStatisticCollection(StatisticCreatorType _creatorType, const char * _creator, const StatsScopeId & _id)
  1236. : CStatisticCollection(NULL, _id), creatorType(_creatorType), creator(_creator)
  1237. {
  1238. whenCreated = getTimeStampNowValue();
  1239. }
  1240. CRootStatisticCollection(MemoryBuffer & in, unsigned version) : CStatisticCollection(NULL, in, version)
  1241. {
  1242. byte creatorTypeByte;
  1243. in.read(creatorTypeByte);
  1244. creatorType = (StatisticCreatorType)creatorTypeByte;
  1245. in.read(creator);
  1246. in.read(whenCreated);
  1247. }
  1248. virtual byte getCollectionType() const { return SCroot; }
  1249. virtual unsigned __int64 queryWhenCreated() const
  1250. {
  1251. return whenCreated;
  1252. }
  1253. virtual void serialize(MemoryBuffer & out) const
  1254. {
  1255. CStatisticCollection::serialize(out);
  1256. out.append((byte)creatorType);
  1257. out.append(creator);
  1258. out.append(whenCreated);
  1259. }
  1260. public:
  1261. StatisticCreatorType creatorType;
  1262. StringAttr creator;
  1263. unsigned __int64 whenCreated;
  1264. };
  1265. //---------------------------------------------------------------------------------------------------------------------
  1266. void serializeStatisticCollection(MemoryBuffer & out, IStatisticCollection * collection)
  1267. {
  1268. out.append(currentStatisticsVersion);
  1269. collection->serialize(out);
  1270. }
  1271. static CStatisticCollection * deserializeCollection(CStatisticCollection * parent, MemoryBuffer & in, unsigned version)
  1272. {
  1273. byte kind;
  1274. in.read(kind);
  1275. switch (kind)
  1276. {
  1277. case SCroot:
  1278. assertex(!parent);
  1279. return new CRootStatisticCollection(in, version);
  1280. case SCintermediate:
  1281. return new CStatisticCollection(parent, in, version);
  1282. default:
  1283. UNIMPLEMENTED;
  1284. }
  1285. }
  1286. IStatisticCollection * createStatisticCollection(MemoryBuffer & in)
  1287. {
  1288. unsigned version;
  1289. in.read(version);
  1290. return deserializeCollection(NULL, in, version);
  1291. }
  1292. //--------------------------------------------------------------------------------------------------------------------
  1293. class StatisticGatherer : implements CInterfaceOf<IStatisticGatherer>
  1294. {
  1295. public:
  1296. StatisticGatherer(CStatisticCollection * scope) : rootScope(scope)
  1297. {
  1298. scopes.append(*scope);
  1299. }
  1300. virtual void beginScope(const StatsScopeId & id)
  1301. {
  1302. CStatisticCollection & tos = scopes.tos();
  1303. scopes.append(*tos.ensureSubScope(id, true));
  1304. }
  1305. virtual void beginActivityScope(unsigned id)
  1306. {
  1307. StatsScopeId scopeId(SSTactivity, id);
  1308. CStatisticCollection & tos = scopes.tos();
  1309. scopes.append(*tos.ensureSubScope(scopeId, false));
  1310. }
  1311. virtual void beginSubGraphScope(unsigned id)
  1312. {
  1313. StatsScopeId scopeId(SSTsubgraph, id);
  1314. CStatisticCollection & tos = scopes.tos();
  1315. scopes.append(*tos.ensureSubScope(scopeId, true));
  1316. }
  1317. virtual void beginEdgeScope(unsigned id, unsigned oid)
  1318. {
  1319. StatsScopeId scopeId(SSTedge, id, oid);
  1320. CStatisticCollection & tos = scopes.tos();
  1321. scopes.append(*tos.ensureSubScope(scopeId, false));
  1322. }
  1323. virtual void endScope()
  1324. {
  1325. scopes.tos().Release();
  1326. scopes.pop();
  1327. }
  1328. virtual void addStatistic(StatisticKind kind, unsigned __int64 value)
  1329. {
  1330. CStatisticCollection & tos = scopes.tos();
  1331. tos.addStatistic(kind, value);
  1332. }
  1333. virtual void updateStatistic(StatisticKind kind, unsigned __int64 value, StatsMergeAction mergeAction)
  1334. {
  1335. CStatisticCollection & tos = scopes.tos();
  1336. tos.updateStatistic(kind, value, mergeAction);
  1337. }
  1338. virtual IStatisticCollection * getResult()
  1339. {
  1340. return LINK(rootScope);
  1341. }
  1342. protected:
  1343. ICopyArrayOf<CStatisticCollection> scopes;
  1344. Linked<CStatisticCollection> rootScope;
  1345. };
  1346. extern IStatisticGatherer * createStatisticsGatherer(StatisticCreatorType creatorType, const char * creator, const StatsScopeId & rootScope)
  1347. {
  1348. //creator unused at the moment.
  1349. Owned<CStatisticCollection> rootCollection = new CRootStatisticCollection(creatorType, creator, rootScope);
  1350. return new StatisticGatherer(rootCollection);
  1351. }
  1352. //--------------------------------------------------------------------------------------------------------------------
  1353. extern IPropertyTree * selectTreeStat(IPropertyTree *node, const char *statName, const char *statType)
  1354. {
  1355. StringBuffer xpath;
  1356. xpath.appendf("att[@name='%s']", statName);
  1357. IPropertyTree *att = node->queryPropTree(xpath.str());
  1358. if (!att)
  1359. {
  1360. att = node->addPropTree("att", createPTree());
  1361. att->setProp("@name", statName);
  1362. att->setProp("@type", statType);
  1363. }
  1364. return att;
  1365. }
  1366. extern void putStatsTreeValue(IPropertyTree *node, const char *statName, const char *statType, unsigned __int64 val)
  1367. {
  1368. if (val)
  1369. selectTreeStat(node, statName, statType)->setPropInt64("@value", val);
  1370. }
  1371. class TreeNodeStatisticGatherer : public CInterfaceOf<IStatisticGatherer>
  1372. {
  1373. public:
  1374. TreeNodeStatisticGatherer(IPropertyTree & root) : node(&root) {}
  1375. virtual void beginScope(const StatsScopeId & id)
  1376. {
  1377. StringBuffer temp;
  1378. id.getScopeText(temp);
  1379. beginScope(temp.str());
  1380. }
  1381. virtual void beginSubGraphScope(unsigned id) { throwUnexpected(); }
  1382. virtual void beginActivityScope(unsigned id) { throwUnexpected(); }
  1383. virtual void beginEdgeScope(unsigned id, unsigned oid) { throwUnexpected(); }
  1384. virtual void endScope()
  1385. {
  1386. node = &stack.popGet();
  1387. }
  1388. virtual void addStatistic(StatisticKind kind, unsigned __int64 value)
  1389. {
  1390. putStatsTreeValue(node, queryStatisticName(kind), "sum", value);
  1391. }
  1392. virtual void updateStatistic(StatisticKind kind, unsigned __int64 value, StatsMergeAction mergeAction)
  1393. {
  1394. if (value)
  1395. {
  1396. IPropertyTree * stat = selectTreeStat(node, queryStatisticName(kind), "sum");
  1397. unsigned __int64 newValue = mergeStatisticValue(stat->getPropInt64("@value"), value, mergeAction);
  1398. stat->setPropInt64("@value", newValue);
  1399. }
  1400. }
  1401. virtual IStatisticCollection * getResult() { throwUnexpected(); }
  1402. protected:
  1403. void beginScope(const char * id)
  1404. {
  1405. stack.append(*node);
  1406. StringBuffer xpath;
  1407. xpath.appendf("scope[@name='%s']", id);
  1408. IPropertyTree *att = node->queryPropTree(xpath.str());
  1409. if (!att)
  1410. {
  1411. att = node->addPropTree("scope", createPTree());
  1412. att->setProp("@name", id);
  1413. }
  1414. node = att;
  1415. }
  1416. protected:
  1417. IPropertyTree * node;
  1418. ICopyArrayOf<IPropertyTree> stack;
  1419. };
  1420. //--------------------------------------------------------------------------------------------------------------------
  1421. void CRuntimeStatistic::merge(unsigned __int64 otherValue, StatsMergeAction mergeAction)
  1422. {
  1423. value = mergeStatisticValue(value, otherValue, mergeAction);
  1424. }
  1425. //--------------------------------------------------------------------------------------------------------------------
  1426. CRuntimeStatisticCollection::~CRuntimeStatisticCollection()
  1427. {
  1428. delete [] values;
  1429. delete nested;
  1430. }
  1431. void CRuntimeStatisticCollection::ensureNested()
  1432. {
  1433. if (!nested)
  1434. nested = new CNestedRuntimeStatisticMap;
  1435. }
  1436. void CRuntimeStatisticCollection::merge(const CRuntimeStatisticCollection & other)
  1437. {
  1438. ForEachItemIn(i, other)
  1439. {
  1440. StatisticKind kind = other.getKind(i);
  1441. unsigned __int64 value = other.getStatisticValue(kind);
  1442. if (value)
  1443. mergeStatistic(kind, other.getStatisticValue(kind));
  1444. }
  1445. if (other.nested)
  1446. {
  1447. ensureNested();
  1448. nested->merge(*other.nested);
  1449. }
  1450. }
  1451. void CRuntimeStatisticCollection::mergeStatistic(StatisticKind kind, unsigned __int64 value)
  1452. {
  1453. queryStatistic(kind).merge(value, queryMergeMode(kind));
  1454. }
  1455. CRuntimeStatisticCollection & CRuntimeStatisticCollection::registerNested(const StatsScopeId & scope, const StatisticsMapping & mapping)
  1456. {
  1457. ensureNested();
  1458. return nested->addNested(scope, mapping).queryStats();
  1459. }
  1460. void CRuntimeStatisticCollection::rollupStatistics(unsigned numTargets, IContextLogger * const * targets) const
  1461. {
  1462. ForEachItem(iStat)
  1463. {
  1464. unsigned __int64 value = values[iStat].getClear();
  1465. if (value)
  1466. {
  1467. StatisticKind kind = getKind(iStat);
  1468. for (unsigned iTarget = 0; iTarget < numTargets; iTarget++)
  1469. targets[iTarget]->noteStatistic(kind, value);
  1470. }
  1471. }
  1472. reportIgnoredStats();
  1473. }
  1474. void CRuntimeStatisticCollection::recordStatistics(IStatisticGatherer & target) const
  1475. {
  1476. ForEachItem(i)
  1477. {
  1478. unsigned __int64 value = values[i].get();
  1479. if (value)
  1480. {
  1481. StatisticKind kind = getKind(i);
  1482. StatisticKind serialKind= querySerializedKind(kind);
  1483. if (kind != serialKind)
  1484. value = convertMeasure(kind, serialKind, value);
  1485. StatsMergeAction mergeAction = queryMergeMode(serialKind);
  1486. target.updateStatistic(serialKind, value, mergeAction);
  1487. }
  1488. }
  1489. reportIgnoredStats();
  1490. if (nested)
  1491. nested->recordStatistics(target);
  1492. }
  1493. void CRuntimeStatisticCollection::reportIgnoredStats() const
  1494. {
  1495. if (values[mapping.numStatistics()].getClear())
  1496. DBGLOG("Some statistics were added but thrown away");
  1497. }
  1498. StringBuffer & CRuntimeStatisticCollection::toXML(StringBuffer &str) const
  1499. {
  1500. ForEachItem(iStat)
  1501. {
  1502. unsigned __int64 value = values[iStat].get();
  1503. if (value)
  1504. {
  1505. StatisticKind kind = getKind(iStat);
  1506. const char * name = queryStatisticName(kind);
  1507. str.appendf("<%s>%" I64F "d</%s>", name, value, name);
  1508. }
  1509. }
  1510. if (nested)
  1511. nested->toXML(str);
  1512. return str;
  1513. }
  1514. StringBuffer & CRuntimeStatisticCollection::toStr(StringBuffer &str) const
  1515. {
  1516. ForEachItem(iStat)
  1517. {
  1518. unsigned __int64 value = values[iStat].get();
  1519. if (value)
  1520. {
  1521. StatisticKind kind = getKind(iStat);
  1522. const char * name = queryStatisticName(kind);
  1523. str.append(' ').append(name).append("=");
  1524. formatStatistic(str, value, kind);
  1525. }
  1526. }
  1527. if (nested)
  1528. nested->toStr(str);
  1529. return str;
  1530. }
  1531. void CRuntimeStatisticCollection::deserialize(MemoryBuffer& in)
  1532. {
  1533. unsigned numValid;
  1534. in.readPacked(numValid);
  1535. for (unsigned i=0; i < numValid; i++)
  1536. {
  1537. unsigned kindVal;
  1538. unsigned __int64 value;
  1539. in.readPacked(kindVal).readPacked(value);
  1540. StatisticKind kind = (StatisticKind)kindVal;
  1541. setStatistic(kind, value);
  1542. }
  1543. bool hasNested;
  1544. in.read(hasNested);
  1545. if (hasNested)
  1546. {
  1547. ensureNested();
  1548. nested->deserializeMerge(in);
  1549. }
  1550. }
  1551. void CRuntimeStatisticCollection::deserializeMerge(MemoryBuffer& in)
  1552. {
  1553. unsigned numValid;
  1554. in.readPacked(numValid);
  1555. for (unsigned i=0; i < numValid; i++)
  1556. {
  1557. unsigned kindVal;
  1558. unsigned __int64 value;
  1559. in.readPacked(kindVal).readPacked(value);
  1560. StatisticKind kind = (StatisticKind)kindVal;
  1561. StatsMergeAction mergeAction = queryMergeMode(kind);
  1562. mergeStatistic(kind, value, mergeAction);
  1563. }
  1564. bool hasNested;
  1565. in.read(hasNested);
  1566. if (hasNested)
  1567. {
  1568. ensureNested();
  1569. nested->deserializeMerge(in);
  1570. }
  1571. }
  1572. void CRuntimeStatisticCollection::getNodeProgressInfo(IPropertyTree &node) const
  1573. {
  1574. TreeNodeStatisticGatherer gatherer(node);
  1575. recordStatistics(gatherer);
  1576. }
  1577. bool CRuntimeStatisticCollection::serialize(MemoryBuffer& out) const
  1578. {
  1579. unsigned numValid = 0;
  1580. ForEachItem(i1)
  1581. {
  1582. if (values[i1].get())
  1583. numValid++;
  1584. }
  1585. out.appendPacked(numValid);
  1586. ForEachItem(i2)
  1587. {
  1588. unsigned __int64 value = values[i2].get();
  1589. if (value)
  1590. {
  1591. StatisticKind kind = mapping.getKind(i2);
  1592. StatisticKind serialKind= querySerializedKind(kind);
  1593. if (kind != serialKind)
  1594. value = convertMeasure(kind, serialKind, value);
  1595. out.appendPacked((unsigned)serialKind);
  1596. out.appendPacked(value);
  1597. }
  1598. }
  1599. bool nonEmpty = (numValid != 0);
  1600. out.append(nested != nullptr);
  1601. if (nested)
  1602. {
  1603. if (nested->serialize(out))
  1604. nonEmpty = true;
  1605. }
  1606. return nonEmpty;
  1607. }
  1608. //---------------------------------------------------------------------------------------------------------------------
  1609. void CRuntimeSummaryStatisticCollection::DerivedStats::mergeStatistic(unsigned __int64 value, unsigned node)
  1610. {
  1611. if (count == 0)
  1612. {
  1613. min = value;
  1614. max = value;
  1615. minNode = node;
  1616. maxNode = node;
  1617. }
  1618. else
  1619. {
  1620. if (value < min)
  1621. {
  1622. min = value;
  1623. minNode = node;
  1624. }
  1625. if (value > max)
  1626. {
  1627. max = value;
  1628. maxNode = node;
  1629. }
  1630. }
  1631. count++;
  1632. double dvalue = (double)value;
  1633. sumSquares += dvalue * dvalue;
  1634. }
  1635. CRuntimeSummaryStatisticCollection::CRuntimeSummaryStatisticCollection(const StatisticsMapping & _mapping) : CRuntimeStatisticCollection(_mapping)
  1636. {
  1637. derived = new DerivedStats[ordinality()+1];
  1638. }
  1639. CRuntimeSummaryStatisticCollection::~CRuntimeSummaryStatisticCollection()
  1640. {
  1641. delete[] derived;
  1642. }
  1643. void CRuntimeSummaryStatisticCollection::ensureNested()
  1644. {
  1645. if (!nested)
  1646. nested = new CNestedSummaryRuntimeStatisticMap;
  1647. }
  1648. void CRuntimeSummaryStatisticCollection::mergeStatistic(StatisticKind kind, unsigned __int64 value)
  1649. {
  1650. CRuntimeStatisticCollection::mergeStatistic(kind, value);
  1651. unsigned index = queryMapping().getIndex(kind);
  1652. derived[index].mergeStatistic(value, 0);
  1653. }
  1654. static bool isSignificantSkew(StatisticKind kind, unsigned __int64 range, unsigned __int64 count)
  1655. {
  1656. //MORE: Could get more sophisticated!
  1657. return range > 1;
  1658. }
  1659. void CRuntimeSummaryStatisticCollection::recordStatistics(IStatisticGatherer & target) const
  1660. {
  1661. CRuntimeStatisticCollection::recordStatistics(target);
  1662. for (unsigned i = 0; i < ordinality(); i++)
  1663. {
  1664. DerivedStats & cur = derived[i];
  1665. if (cur.count)
  1666. {
  1667. StatisticKind kind = getKind(i);
  1668. StatisticKind serialKind= querySerializedKind(kind);
  1669. unsigned __int64 minValue = convertMeasure(kind, serialKind, cur.min);
  1670. unsigned __int64 maxValue = convertMeasure(kind, serialKind, cur.max);
  1671. if (minValue != maxValue)
  1672. {
  1673. double sum = (double)convertMeasure(kind, serialKind, values[i].get());
  1674. //Sum of squares needs to be translated twice
  1675. double sumSquares = convertSquareMeasure(kind, serialKind, cur.sumSquares);
  1676. double mean = (double)(sum / cur.count);
  1677. double variance = (sumSquares - sum * mean) / cur.count;
  1678. double stdDev = sqrt(variance);
  1679. double maxSkew = (10000.0 * ((maxValue-mean)/mean));
  1680. double minSkew = (10000.0 * ((mean-minValue)/mean));
  1681. unsigned __int64 range = maxValue - minValue;
  1682. target.addStatistic((StatisticKind)(serialKind|StMinX), minValue);
  1683. target.addStatistic((StatisticKind)(serialKind|StMaxX), maxValue);
  1684. target.addStatistic((StatisticKind)(serialKind|StAvgX), (unsigned __int64)mean);
  1685. target.addStatistic((StatisticKind)(serialKind|StDeltaX), range);
  1686. target.addStatistic((StatisticKind)(serialKind|StStdDevX), (unsigned __int64)stdDev);
  1687. //If all nodes are the same then we re actually merging results from multiple runs
  1688. //if the range is less than the count then
  1689. if ((cur.minNode != cur.maxNode) && isSignificantSkew(serialKind, range, cur.count))
  1690. {
  1691. target.addStatistic((StatisticKind)(serialKind|StSkewMin), (unsigned __int64)minSkew);
  1692. target.addStatistic((StatisticKind)(serialKind|StSkewMax), (unsigned __int64)maxSkew);
  1693. target.addStatistic((StatisticKind)(serialKind|StNodeMin), cur.minNode);
  1694. target.addStatistic((StatisticKind)(serialKind|StNodeMax), cur.maxNode);
  1695. }
  1696. }
  1697. else if (cur.count != 1)
  1698. target.addStatistic((StatisticKind)(serialKind|StAvgX), minValue);
  1699. }
  1700. }
  1701. }
  1702. bool CRuntimeSummaryStatisticCollection::serialize(MemoryBuffer & out) const
  1703. {
  1704. UNIMPLEMENTED; // NB: Need to convert sum squares twice.
  1705. }
  1706. void CRuntimeSummaryStatisticCollection::deserialize(MemoryBuffer & in)
  1707. {
  1708. UNIMPLEMENTED;
  1709. }
  1710. void CRuntimeSummaryStatisticCollection::deserializeMerge(MemoryBuffer& in)
  1711. {
  1712. UNIMPLEMENTED;
  1713. }
  1714. //---------------------------------------------------
  1715. bool CNestedRuntimeStatisticCollection::matches(const StatsScopeId & otherScope) const
  1716. {
  1717. return scope.matches(otherScope);
  1718. }
  1719. //NOTE: When deserializing, the scope is deserialized by the caller, and the correct target selected
  1720. //which is why there is no corresponding deserialize() ofthe scope at this point
  1721. void CNestedRuntimeStatisticCollection::deserialize(MemoryBuffer & in)
  1722. {
  1723. stats->deserialize(in);
  1724. }
  1725. void CNestedRuntimeStatisticCollection::deserializeMerge(MemoryBuffer& in)
  1726. {
  1727. stats->deserialize(in);
  1728. }
  1729. void CNestedRuntimeStatisticCollection::merge(const CNestedRuntimeStatisticCollection & other)
  1730. {
  1731. stats->merge(other.queryStats());
  1732. }
  1733. bool CNestedRuntimeStatisticCollection::serialize(MemoryBuffer& out) const
  1734. {
  1735. scope.serialize(out);
  1736. return stats->serialize(out);
  1737. }
  1738. void CNestedRuntimeStatisticCollection::recordStatistics(IStatisticGatherer & target) const
  1739. {
  1740. target.beginScope(scope);
  1741. stats->recordStatistics(target);
  1742. target.endScope();
  1743. }
  1744. StringBuffer & CNestedRuntimeStatisticCollection::toStr(StringBuffer &str) const
  1745. {
  1746. str.append(' ');
  1747. scope.getScopeText(str).append("={");
  1748. stats->toStr(str);
  1749. return str.append(" }");
  1750. }
  1751. StringBuffer & CNestedRuntimeStatisticCollection::toXML(StringBuffer &str) const
  1752. {
  1753. str.append("<Scope id=\"");
  1754. scope.getScopeText(str).append("\">");
  1755. stats->toXML(str);
  1756. return str.append("</Scope>");
  1757. }
  1758. //---------------------------------------------------
  1759. CNestedRuntimeStatisticCollection & CNestedRuntimeStatisticMap::addNested(const StatsScopeId & scope, const StatisticsMapping & mapping)
  1760. {
  1761. ForEachItemIn(i, map)
  1762. {
  1763. CNestedRuntimeStatisticCollection & cur = map.item(i);
  1764. if (cur.matches(scope))
  1765. return cur;
  1766. }
  1767. CNestedRuntimeStatisticCollection * stats = new CNestedRuntimeStatisticCollection(scope, createStats(mapping));
  1768. map.append(*stats);
  1769. return *stats;
  1770. }
  1771. void CNestedRuntimeStatisticMap::deserialize(MemoryBuffer& in)
  1772. {
  1773. unsigned numItems;
  1774. in.readPacked(numItems);
  1775. for (unsigned i=0; i < numItems; i++)
  1776. {
  1777. StatsScopeId scope;
  1778. scope.deserialize(in, currentStatisticsVersion);
  1779. //Use allStatistics as the default mapping if it hasn't already been added.
  1780. CNestedRuntimeStatisticCollection & child = addNested(scope, allStatistics);
  1781. child.deserialize(in);
  1782. }
  1783. }
  1784. void CNestedRuntimeStatisticMap::deserializeMerge(MemoryBuffer& in)
  1785. {
  1786. unsigned numItems;
  1787. in.readPacked(numItems);
  1788. for (unsigned i=0; i < numItems; i++)
  1789. {
  1790. StatsScopeId scope;
  1791. scope.deserialize(in, currentStatisticsVersion);
  1792. //Use allStatistics as the default mapping if it hasn't already been added.
  1793. CNestedRuntimeStatisticCollection & child = addNested(scope, allStatistics);
  1794. child.deserializeMerge(in);
  1795. }
  1796. }
  1797. void CNestedRuntimeStatisticMap::merge(const CNestedRuntimeStatisticMap & other)
  1798. {
  1799. ForEachItemIn(i, other.map)
  1800. {
  1801. CNestedRuntimeStatisticCollection & cur = other.map.item(i);
  1802. CNestedRuntimeStatisticCollection & target = addNested(cur.scope, cur.queryMapping());
  1803. target.merge(cur);
  1804. }
  1805. }
  1806. bool CNestedRuntimeStatisticMap::serialize(MemoryBuffer& out) const
  1807. {
  1808. out.appendPacked(map.ordinality());
  1809. bool nonEmpty = false;
  1810. ForEachItemIn(i, map)
  1811. {
  1812. if (map.item(i).serialize(out))
  1813. nonEmpty = true;
  1814. }
  1815. return nonEmpty;
  1816. }
  1817. void CNestedRuntimeStatisticMap::recordStatistics(IStatisticGatherer & target) const
  1818. {
  1819. ForEachItemIn(i, map)
  1820. map.item(i).recordStatistics(target);
  1821. }
  1822. StringBuffer & CNestedRuntimeStatisticMap::toStr(StringBuffer &str) const
  1823. {
  1824. ForEachItemIn(i, map)
  1825. map.item(i).toStr(str);
  1826. return str;
  1827. }
  1828. StringBuffer & CNestedRuntimeStatisticMap::toXML(StringBuffer &str) const
  1829. {
  1830. ForEachItemIn(i, map)
  1831. map.item(i).toXML(str);
  1832. return str;
  1833. }
  1834. CRuntimeStatisticCollection * CNestedRuntimeStatisticMap::createStats(const StatisticsMapping & mapping)
  1835. {
  1836. return new CRuntimeStatisticCollection(mapping);
  1837. }
  1838. CRuntimeStatisticCollection * CNestedSummaryRuntimeStatisticMap::createStats(const StatisticsMapping & mapping)
  1839. {
  1840. return new CRuntimeSummaryStatisticCollection(mapping);
  1841. }
  1842. //---------------------------------------------------
  1843. bool ScopedItemFilter::matchDepth(unsigned low, unsigned high) const
  1844. {
  1845. if (maxDepth && low && maxDepth < low)
  1846. return false;
  1847. if (minDepth && high && minDepth > high)
  1848. return false;
  1849. return true;
  1850. }
  1851. bool ScopedItemFilter::match(const char * search) const
  1852. {
  1853. if (search)
  1854. {
  1855. if (value)
  1856. {
  1857. if (hasWildcard)
  1858. {
  1859. //MORE: If wildcarding ends up being used a lot then this should be replaced with something that creates a DFA
  1860. if (!WildMatch(search, value, false))
  1861. return false;
  1862. }
  1863. else
  1864. {
  1865. return streq(search, value);
  1866. }
  1867. }
  1868. if (minDepth || maxDepth)
  1869. {
  1870. unsigned searchDepth = queryStatisticsDepth(search);
  1871. if (searchDepth < minDepth)
  1872. return false;
  1873. if (maxDepth && searchDepth > maxDepth)
  1874. return false;
  1875. }
  1876. }
  1877. return true;
  1878. }
  1879. bool ScopedItemFilter::recurseChildScopes(const char * curScope) const
  1880. {
  1881. if (maxDepth == 0 || !curScope)
  1882. return true;
  1883. if (queryStatisticsDepth(curScope) >= maxDepth)
  1884. return false;
  1885. return true;
  1886. }
  1887. void ScopedItemFilter::set(const char * _value)
  1888. {
  1889. if (_value && *_value && !streq(_value, "*") )
  1890. {
  1891. value.set(_value);
  1892. minDepth = queryStatisticsDepth(_value);
  1893. if (!strchr(_value, '*'))
  1894. {
  1895. maxDepth = minDepth;
  1896. hasWildcard = strchr(_value, '?') != NULL;
  1897. }
  1898. else
  1899. hasWildcard = true;
  1900. }
  1901. else
  1902. value.clear();
  1903. }
  1904. void ScopedItemFilter::setDepth(unsigned _depth)
  1905. {
  1906. minDepth = _depth;
  1907. maxDepth = _depth;
  1908. }
  1909. void ScopedItemFilter::setDepth(unsigned _minDepth, unsigned _maxDepth)
  1910. {
  1911. minDepth = _minDepth;
  1912. maxDepth = _maxDepth;
  1913. }
  1914. StatisticsFilter::StatisticsFilter()
  1915. {
  1916. init();
  1917. }
  1918. StatisticsFilter::StatisticsFilter(const char * filter)
  1919. {
  1920. init();
  1921. setFilter(filter);
  1922. }
  1923. StatisticsFilter::StatisticsFilter(StatisticCreatorType _creatorType, StatisticScopeType _scopeType, StatisticMeasure _measure, StatisticKind _kind)
  1924. {
  1925. init();
  1926. creatorType = _creatorType;
  1927. scopeType = _scopeType;
  1928. measure = _measure;
  1929. kind = _kind;
  1930. }
  1931. StatisticsFilter::StatisticsFilter(const char * _creatorType, const char * _scopeType, const char * _kind)
  1932. {
  1933. init();
  1934. set(_creatorType, _scopeType, _kind);
  1935. }
  1936. StatisticsFilter::StatisticsFilter(const char * _creatorTypeText, const char * _creator, const char * _scopeTypeText, const char * _scope, const char * _measureText, const char * _kindText)
  1937. {
  1938. init();
  1939. set(_creatorTypeText, _creator, _scopeTypeText, _scope, _measureText, _kindText);
  1940. }
  1941. StatisticsFilter::StatisticsFilter(StatisticCreatorType _creatorType, const char * _creator, StatisticScopeType _scopeType, const char * _scope, StatisticMeasure _measure, StatisticKind _kind)
  1942. {
  1943. init();
  1944. creatorType = _creatorType;
  1945. setCreator(_creator);
  1946. scopeType = _scopeType;
  1947. setScope(_scope);
  1948. measure = _measure;
  1949. kind = _kind;
  1950. }
  1951. void StatisticsFilter::init()
  1952. {
  1953. creatorType = SCTall;
  1954. scopeType = SSTall;
  1955. measure = SMeasureAll;
  1956. kind = StKindAll;
  1957. }
  1958. bool StatisticsFilter::matches(StatisticCreatorType curCreatorType, const char * curCreator, StatisticScopeType curScopeType, const char * curScope, StatisticMeasure curMeasure, StatisticKind curKind) const
  1959. {
  1960. if ((curCreatorType != SCTall) && (creatorType != SCTall) && (creatorType != curCreatorType))
  1961. return false;
  1962. if ((curScopeType != SSTall) && (scopeType != SSTall) && (scopeType != curScopeType))
  1963. return false;
  1964. if ((curMeasure != SMeasureAll) && (measure != SMeasureAll) && (measure != curMeasure))
  1965. return false;
  1966. if ((curKind!= StKindAll) && (kind != StKindAll) && (kind != curKind))
  1967. return false;
  1968. if (!creatorFilter.match(curCreator))
  1969. return false;
  1970. if (!scopeFilter.match(curScope))
  1971. return false;
  1972. return true;
  1973. }
  1974. bool StatisticsFilter::recurseChildScopes(StatisticScopeType curScopeType, const char * curScope) const
  1975. {
  1976. return scopeFilter.recurseChildScopes(curScope);
  1977. }
  1978. void StatisticsFilter::set(const char * creatorTypeText, const char * scopeTypeText, const char * kindText)
  1979. {
  1980. StatisticCreatorType creatorType = queryCreatorType(creatorTypeText);
  1981. StatisticScopeType scopeType = queryScopeType(scopeTypeText);
  1982. if (creatorType != SCTnone)
  1983. setCreatorType(creatorType);
  1984. if (scopeType != SSTnone)
  1985. setScopeType(scopeType);
  1986. setKind(kindText);
  1987. }
  1988. void StatisticsFilter::set(const char * _creatorTypeText, const char * _creator, const char * _scopeTypeText, const char * _scope, const char * _measureText, const char * _kindText)
  1989. {
  1990. StatisticMeasure newMeasure = queryMeasure(_measureText);
  1991. if (newMeasure != SMeasureNone)
  1992. setMeasure(newMeasure);
  1993. set(_creatorTypeText, _scopeTypeText, _kindText);
  1994. setCreator(_creator);
  1995. setScope(_scope);
  1996. }
  1997. void StatisticsFilter::setCreatorDepth(unsigned _minCreatorDepth, unsigned _maxCreatorDepth)
  1998. {
  1999. creatorFilter.setDepth(_minCreatorDepth, _maxCreatorDepth);
  2000. }
  2001. void StatisticsFilter::setCreator(const char * _creator)
  2002. {
  2003. creatorFilter.set(_creator);
  2004. }
  2005. void StatisticsFilter::setCreatorType(StatisticCreatorType _creatorType)
  2006. {
  2007. creatorType = _creatorType;
  2008. }
  2009. void StatisticsFilter::addFilter(const char * filter)
  2010. {
  2011. //Match a filter of the form category[value] (use square brackets to avoid bash grief)
  2012. const char * openBra = strchr(filter, '[');
  2013. if (!openBra)
  2014. return;
  2015. const char * closeBra = strchr(openBra, ']');
  2016. if (!closeBra)
  2017. return;
  2018. const char * start = openBra + 1;
  2019. StringBuffer value(closeBra - start, start);
  2020. if (hasPrefix(filter, "creator[", false))
  2021. setCreator(value);
  2022. else if (hasPrefix(filter, "creatortype[", false))
  2023. setCreatorType(queryCreatorType(value));
  2024. else if (hasPrefix(filter, "depth[", false))
  2025. {
  2026. const char * comma = strchr(value, ',');
  2027. if (comma)
  2028. setScopeDepth(atoi(value), atoi(comma+1));
  2029. else
  2030. setScopeDepth(atoi(value));
  2031. }
  2032. else if (hasPrefix(filter, "kind[", false))
  2033. setKind(value);
  2034. else if (hasPrefix(filter, "measure[", false))
  2035. setMeasure(queryMeasure(value));
  2036. else if (hasPrefix(filter, "scope[", false))
  2037. setScope(value);
  2038. else if (hasPrefix(filter, "scopetype[", false))
  2039. setScopeType(queryScopeType(value));
  2040. else
  2041. throw MakeStringException(1, "Unknown stats filter '%s' - expected creator,creatortype,depth,kind,measure,scope,scopetype", filter);
  2042. }
  2043. void StatisticsFilter::setFilter(const char * filter)
  2044. {
  2045. loop
  2046. {
  2047. const char * closeBra = strchr(filter, ']');
  2048. const char * comma = strchr(closeBra, ',');
  2049. if (comma)
  2050. {
  2051. //Take a copy - simplicity rather than efficiency
  2052. StringBuffer temp(comma - filter, filter);
  2053. addFilter(temp);
  2054. filter = comma + 1;
  2055. }
  2056. else
  2057. {
  2058. addFilter(filter);
  2059. return;
  2060. }
  2061. }
  2062. }
  2063. void StatisticsFilter::setScopeDepth(unsigned _scopeDepth)
  2064. {
  2065. scopeFilter.setDepth(_scopeDepth);
  2066. }
  2067. void StatisticsFilter::setScopeDepth(unsigned _minScopeDepth, unsigned _maxScopeDepth)
  2068. {
  2069. scopeFilter.setDepth(_minScopeDepth, _maxScopeDepth);
  2070. }
  2071. void StatisticsFilter::setScope(const char * _scope)
  2072. {
  2073. scopeFilter.set(_scope);
  2074. }
  2075. void StatisticsFilter::setScopeType(StatisticScopeType _scopeType)
  2076. {
  2077. scopeType = _scopeType;
  2078. }
  2079. void StatisticsFilter::setMeasure(StatisticMeasure _measure)
  2080. {
  2081. measure = _measure;
  2082. }
  2083. void StatisticsFilter::setKind(StatisticKind _kind)
  2084. {
  2085. kind = _kind;
  2086. if (measure == SMeasureAll)
  2087. measure = queryMeasure(kind);
  2088. }
  2089. void StatisticsFilter::setKind(const char * _kind)
  2090. {
  2091. if (!_kind || !*_kind || streq(_kind, "*"))
  2092. {
  2093. if (measure == SMeasureNone)
  2094. measure = SMeasureAll;
  2095. kind = StKindAll;
  2096. return;
  2097. }
  2098. //Convert a kind wildcard to a measure
  2099. for (unsigned i1=SMeasureAll+1; i1 < SMeasureMax; i1++)
  2100. {
  2101. const char * prefix = queryMeasurePrefix((StatisticMeasure)i1);
  2102. size_t len = strlen(prefix);
  2103. if (strnicmp(_kind, prefix, len) == 0)
  2104. {
  2105. setMeasure((StatisticMeasure)i1);
  2106. //Treat When* and When as filters on times.
  2107. if (streq(_kind + len, "*") || !_kind[len])
  2108. return;
  2109. }
  2110. }
  2111. //Other wildcards not currently supported
  2112. kind = queryStatisticKind(_kind);
  2113. }
  2114. //---------------------------------------------------
  2115. class CStatsCategory : public CInterface
  2116. {
  2117. public:
  2118. StringAttr longName;
  2119. StringAttr shortName;
  2120. CStatsCategory(const char *_longName, const char *_shortName)
  2121. : longName(_longName), shortName(_shortName)
  2122. {
  2123. }
  2124. bool match(const char *_longName, const char *_shortName)
  2125. {
  2126. bool lm = stricmp(_longName, longName)==0;
  2127. bool sm = stricmp(_shortName, shortName)==0;
  2128. if (lm || sm)
  2129. {
  2130. if (lm && sm)
  2131. return true;
  2132. throw MakeStringException(0, "A stats category %s (%s) is already registered", shortName.get(), longName.get());
  2133. }
  2134. return false;
  2135. }
  2136. };
  2137. static CIArrayOf<CStatsCategory> statsCategories;
  2138. static CriticalSection statsCategoriesCrit;
  2139. extern int registerStatsCategory(const char *longName, const char *shortName)
  2140. {
  2141. CriticalBlock b(statsCategoriesCrit);
  2142. ForEachItemIn(idx, statsCategories)
  2143. {
  2144. if (statsCategories.item(idx).match(longName, shortName))
  2145. return idx;
  2146. }
  2147. statsCategories.append(*new CStatsCategory(longName, shortName));
  2148. return statsCategories.ordinality()-1;
  2149. }
  2150. static void checkKind(StatisticKind kind)
  2151. {
  2152. if (kind < StMax)
  2153. {
  2154. const StatisticMeta & meta = statsMetaData[kind];
  2155. if (meta.kind != kind)
  2156. throw makeStringExceptionV(0, "Statistic %u in the wrong order", kind);
  2157. }
  2158. StatisticMeasure measure = queryMeasure(kind);
  2159. const char * shortName = queryStatisticName(kind);
  2160. StringBuffer longName;
  2161. queryLongStatisticName(longName, kind);
  2162. const char * tagName __attribute__ ((unused)) = queryTreeTag(kind);
  2163. const char * prefix = queryMeasurePrefix(measure);
  2164. //Check short names are all correctly prefixed.
  2165. assertex(strncmp(shortName, prefix, strlen(prefix)) == 0);
  2166. }
  2167. static void checkDistributedKind(StatisticKind kind)
  2168. {
  2169. checkKind(kind);
  2170. checkKind((StatisticKind)(kind|StMinX));
  2171. checkKind((StatisticKind)(kind|StMaxX));
  2172. checkKind((StatisticKind)(kind|StAvgX));
  2173. checkKind((StatisticKind)(kind|StSkew));
  2174. checkKind((StatisticKind)(kind|StSkewMin));
  2175. checkKind((StatisticKind)(kind|StSkewMax));
  2176. checkKind((StatisticKind)(kind|StNodeMin));
  2177. checkKind((StatisticKind)(kind|StNodeMax));
  2178. checkKind((StatisticKind)(kind|StDeltaX));
  2179. }
  2180. void verifyStatisticFunctions()
  2181. {
  2182. assertex(_elements_in(measureNames) == SMeasureMax+1 && !measureNames[SMeasureMax]);
  2183. assertex(_elements_in(creatorTypeNames) == SCTmax+1 && !creatorTypeNames[SCTmax]);
  2184. assertex(_elements_in(scopeTypeNames) == SSTmax+1 && !scopeTypeNames[SSTmax]);
  2185. //Check the various functions return values for all possible values.
  2186. for (unsigned i1=SMeasureAll; i1 < SMeasureMax; i1++)
  2187. {
  2188. const char * prefix __attribute__((unused)) = queryMeasurePrefix((StatisticMeasure)i1);
  2189. const char * name = queryMeasureName((StatisticMeasure)i1);
  2190. assertex(queryMeasure(name) == i1);
  2191. }
  2192. for (StatisticScopeType sst = SSTnone; sst < SSTmax; sst = (StatisticScopeType)(sst+1))
  2193. {
  2194. const char * name = queryScopeTypeName(sst);
  2195. assertex(queryScopeType(name) == sst);
  2196. }
  2197. for (StatisticCreatorType sct = SCTnone; sct < SCTmax; sct = (StatisticCreatorType)(sct+1))
  2198. {
  2199. const char * name = queryCreatorTypeName(sct);
  2200. assertex(queryCreatorType(name) == sct);
  2201. }
  2202. for (unsigned i2=StKindAll+1; i2 < StMax; i2++)
  2203. {
  2204. checkDistributedKind((StatisticKind)i2);
  2205. }
  2206. }
  2207. #if 0
  2208. MODULE_INIT(INIT_PRIORITY_STANDARD)
  2209. {
  2210. verifyStatisticFunctions();
  2211. return true;
  2212. }
  2213. #endif