jstats.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  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. #ifndef JSTATS_H
  14. #define JSTATS_H
  15. #include "jlib.hpp"
  16. #define ActivityScopePrefix "a"
  17. #define EdgeScopePrefix "e"
  18. #define SubGraphScopePrefix "sg"
  19. #define GraphScopePrefix "graph"
  20. #define CONST_STRLEN(x) (sizeof(x)-1) // sizeof(const-string) = strlen(const-string) + 1 byte for the \0 terminator
  21. #define MATCHES_CONST_PREFIX(search, prefix) (strncmp(search, prefix, CONST_STRLEN(prefix)) == 0)
  22. enum CombineStatsAction
  23. {
  24. MergeStats,
  25. ReplaceStats,
  26. AppendStats,
  27. };
  28. enum StatisticCreatorType
  29. {
  30. SCTnone,
  31. SCTall,
  32. SCTunknown,
  33. SCThthor,
  34. SCTroxie,
  35. SCTroxieSlave,
  36. SCTthor,
  37. SCTthorMaster,
  38. SCTthorSlave,
  39. SCTeclcc,
  40. SCTesp,
  41. SCTsummary, // used to maintain the summary time over all thors (mainly for sorting)
  42. SCTmax,
  43. };
  44. enum StatisticScopeType
  45. {
  46. SSTnone,
  47. SSTall,
  48. SSTglobal, // root scope
  49. SSTgraph, // identifies a graph
  50. SSTsubgraph,
  51. SSTactivity,
  52. SSTallocator, // identifies an allocator
  53. SSTsection, // A section within the query - not a great differentiator
  54. SSTcompilestage, // a stage within the compilation process
  55. SSTdfuworkunit, // a reference to an executing dfu workunit
  56. SSTedge,
  57. SSTmax
  58. };
  59. enum StatisticMeasure
  60. {
  61. SMeasureNone,
  62. SMeasureAll,
  63. SMeasureTimeNs, // Elapsed time in nanoseconds
  64. SMeasureTimestampUs, // timestamp/when - a point in time (to the microsecond)
  65. SMeasureCount, // a count of the number of occurrences
  66. SMeasureSize, // a quantity of memory (or disk) measured in bytes
  67. SMeasureLoad, // measure of cpu activity (stored as 1/1000000 core)
  68. SMeasureSkew, // a measure of skew. 0 = perfectly balanced, range [-10000..infinity]
  69. SMeasureNode, // A node number within a cluster (0 = master)
  70. SMeasurePercent, // actually stored as parts per million, displayed as a percentage
  71. SMeasureIPV4,
  72. SMeasureMax,
  73. };
  74. //This macro can be used to generate multiple variations of a statistics kind, but probably not needed any more
  75. //e.g., DEFINE_SKEW_STAT(Time, Elapsed)
  76. #define DEFINE_SKEW_STAT(x, y) \
  77. St ## x ## Min ## y = (St ## x ## y | StMinX), \
  78. St ## x ## Max ## y = (St ## x ## y | StMaxX), \
  79. St ## x ## Ave ## y = (St ## x ## y | StAvgX), \
  80. St ## Skew ## y = (St ## x ## y | StSkew), \
  81. St ## SkewMin ## y = (St ## x ## y | StSkewMin), \
  82. St ## SkewMax ## y = (St ## x ## y | StSkewMax), \
  83. St ## NodeMin ## y = (St ## x ## y | StNodeMin), \
  84. St ## NodeMax ## y = (St ## x ## y | StNodeMax),
  85. //The values in this enumeration are stored persistently. The associated values must not be changed.
  86. //If you add an entry here you must also update statsMetaData
  87. //NOTE: All statistic names should be unique with the type prefix removed. Since the prefix is replaced with Skew/Min/etc.
  88. enum StatisticKind
  89. {
  90. StKindNone,
  91. StKindAll,
  92. StWhenGraphStarted, // When a graph starts
  93. StWhenGraphFinished, // When a graph stopped
  94. StWhenFirstRow, // When the first row is processed by slave activity
  95. StWhenQueryStarted,
  96. StWhenQueryFinished,
  97. StWhenCreated,
  98. StWhenCompiled,
  99. StWhenWorkunitModified, // Not sure this is very useful
  100. StTimeElapsed, // Elapsed wall time between first row and last row
  101. StTimeLocalExecute, // Time spend processing just this activity
  102. StTimeTotalExecute, // Time executing this activity and all inputs
  103. StTimeRemaining,
  104. StSizeGeneratedCpp,
  105. StSizePeakMemory,
  106. StSizeMaxRowSize,
  107. StNumRowsProcessed, // on edge
  108. StNumSlaves, // on edge
  109. StNumStarted, // on edge
  110. StNumStopped, // on edge
  111. StNumIndexSeeks,
  112. StNumIndexScans,
  113. StNumIndexWildSeeks,
  114. StNumIndexSkips,
  115. StNumIndexNullSkips,
  116. StNumIndexMerges,
  117. StNumIndexMergeCompares,
  118. StNumPreFiltered,
  119. StNumPostFiltered,
  120. StNumBlobCacheHits,
  121. StNumLeafCacheHits,
  122. StNumNodeCacheHits,
  123. StNumBlobCacheAdds,
  124. StNumLeafCacheAdds,
  125. StNumNodeCacheAdds,
  126. StNumPreloadCacheHits,
  127. StNumPreloadCacheAdds,
  128. StNumServerCacheHits,
  129. StNumIndexAccepted,
  130. StNumIndexRejected,
  131. StNumAtmostTriggered,
  132. StNumDiskSeeks,
  133. StNumIterations,
  134. StLoadWhileSorting, // Average load while processing a sort?
  135. StNumLeftRows,
  136. StNumRightRows,
  137. StPerReplicated,
  138. StNumDiskRowsRead,
  139. StNumIndexRowsRead,
  140. StNumDiskAccepted,
  141. StNumDiskRejected,
  142. StTimeSoapcall, // Time spent waiting for soapcalls
  143. StTimeFirstExecute, // Time waiting for first record from this activity
  144. StMax,
  145. //For any quantity there is potentially the following variants.
  146. //These modifiers ORd with the values above to form a compound type.
  147. StKindMask = 0x0ffff,
  148. StVariantScale = (StKindMask+1),
  149. StMinX = 0x10000, // the minimum value
  150. StMaxX = 0x20000, // the maximum value
  151. StAvgX = 0x30000, // the average value
  152. StSkew = 0x40000, // the skew on a particular node
  153. StSkewMin = 0x50000, // the minimum skew
  154. StSkewMax = 0x60000, // the maximum skew
  155. StNodeMin = 0x70000, // the node containing the minimum
  156. StNodeMax = 0x80000, // the node containing the maximum
  157. StDeltaX = 0x90000, // a difference in the value of X
  158. StNextModifier = 0xa0000,
  159. };
  160. inline StatisticKind queryStatsVariant(StatisticKind kind) { return (StatisticKind)(kind & ~StKindMask); }
  161. //---------------------------------------------------------------------------------------------------------------------
  162. interface IStatistic : extends IInterface
  163. {
  164. public:
  165. virtual StatisticKind queryKind() const = 0;
  166. virtual unsigned __int64 queryValue() const = 0;
  167. };
  168. interface IStatisticFilter
  169. {
  170. virtual bool matches(IStatistic * stats) = 0;
  171. virtual void getFilter(StringBuffer & out) = 0;
  172. };
  173. interface IStatisticIterator : public IIteratorOf<IStatistic>
  174. {
  175. };
  176. //Represents a single level of a scope
  177. class jlib_decl StatsScopeId
  178. {
  179. public:
  180. StatsScopeId() : id(0), extra(0), scopeType(SSTnone) {}
  181. StatsScopeId(StatisticScopeType _scopeType, unsigned _id, unsigned _extra = 0)
  182. : id(_id), extra(_extra), scopeType(_scopeType)
  183. {
  184. }
  185. StatisticScopeType queryScopeType() const { return scopeType; }
  186. StringBuffer & getScopeText(StringBuffer & out) const;
  187. unsigned getHash() const;
  188. bool matches(const StatsScopeId & other) const;
  189. unsigned queryActivity() const;
  190. void deserialize(MemoryBuffer & in, unsigned version);
  191. void serialize(MemoryBuffer & out) const;
  192. bool setScopeText(const char * text);
  193. void setId(StatisticScopeType _scopeType, unsigned _id, unsigned _extra = 0);
  194. void setActivityId(unsigned _id);
  195. void setEdgeId(unsigned _id, unsigned _output);
  196. void setSubgraphId(unsigned _id);
  197. bool operator == (const StatsScopeId & other) const { return matches(other); }
  198. protected:
  199. //If any more items are added then this could become a union...
  200. unsigned id;
  201. unsigned extra;
  202. StatisticScopeType scopeType;
  203. };
  204. interface IStatisticCollectionIterator;
  205. interface IStatisticCollection : public IInterface
  206. {
  207. public:
  208. virtual StatisticScopeType queryScopeType() const = 0;
  209. virtual StringBuffer & getFullScope(StringBuffer & str) const = 0;
  210. virtual StringBuffer & getScope(StringBuffer & str) const = 0;
  211. virtual unsigned __int64 queryStatistic(StatisticKind kind) const = 0;
  212. virtual unsigned getNumStatistics() const = 0;
  213. virtual void getStatistic(StatisticKind & kind, unsigned __int64 & value, unsigned idx) const = 0;
  214. virtual IStatisticCollectionIterator & getScopes(const char * filter) = 0;
  215. virtual void getMinMaxScope(IStringVal & minValue, IStringVal & maxValue, StatisticScopeType searchScopeType) const = 0;
  216. virtual void getMinMaxActivity(unsigned & minValue, unsigned & maxValue) const = 0;
  217. virtual void serialize(MemoryBuffer & out) const = 0;
  218. virtual unsigned __int64 queryWhenCreated() const = 0;
  219. };
  220. interface IStatisticCollectionIterator : public IIteratorOf<IStatisticCollection>
  221. {
  222. };
  223. enum StatsMergeAction
  224. {
  225. StatsMergeKeep,
  226. StatsMergeReplace,
  227. StatsMergeSum,
  228. StatsMergeMin,
  229. StatsMergeMax,
  230. StatsMergeAppend,
  231. };
  232. interface IStatisticGatherer : public IInterface
  233. {
  234. public:
  235. virtual void beginScope(const StatsScopeId & id) = 0;
  236. virtual void beginSubGraphScope(unsigned id) = 0;
  237. virtual void beginActivityScope(unsigned id) = 0;
  238. virtual void beginEdgeScope(unsigned id, unsigned oid) = 0;
  239. virtual void endScope() = 0;
  240. virtual void addStatistic(StatisticKind kind, unsigned __int64 value) = 0;
  241. virtual void updateStatistic(StatisticKind kind, unsigned __int64 value, StatsMergeAction mergeAction) = 0;
  242. virtual IStatisticCollection * getResult() = 0;
  243. };
  244. //All filtering should go through this interface - so we can extend and allow AND/OR filters at a later date.
  245. interface IStatisticsFilter : public IInterface
  246. {
  247. public:
  248. virtual bool matches(StatisticCreatorType curCreatorType, const char * curCreator, StatisticScopeType curScopeType, const char * curScope, StatisticMeasure curMeasure, StatisticKind curKind) const = 0;
  249. virtual bool recurseChildScopes(StatisticScopeType curScopeType, const char * curScope) const = 0;
  250. virtual const char * queryScope() const = 0;
  251. };
  252. class StatsScopeBlock
  253. {
  254. public:
  255. inline StatsScopeBlock(IStatisticGatherer & _gatherer) : gatherer(_gatherer)
  256. {
  257. }
  258. inline ~StatsScopeBlock()
  259. {
  260. gatherer.endScope();
  261. }
  262. protected:
  263. IStatisticGatherer & gatherer;
  264. };
  265. //---------------------------------------------------------------------------------------------------------------------
  266. class StatsSubgraphScope : public StatsScopeBlock
  267. {
  268. public:
  269. inline StatsSubgraphScope(IStatisticGatherer & _gatherer, unsigned id) : StatsScopeBlock(_gatherer)
  270. {
  271. gatherer.beginSubGraphScope(id);
  272. }
  273. };
  274. class StatsActivityScope : public StatsScopeBlock
  275. {
  276. public:
  277. inline StatsActivityScope(IStatisticGatherer & _gatherer, unsigned id) : StatsScopeBlock(_gatherer)
  278. {
  279. gatherer.beginActivityScope(id);
  280. }
  281. };
  282. class StatsEdgeScope : public StatsScopeBlock
  283. {
  284. public:
  285. inline StatsEdgeScope(IStatisticGatherer & _gatherer, unsigned id, unsigned oid) : StatsScopeBlock(_gatherer)
  286. {
  287. gatherer.beginEdgeScope(id, oid);
  288. }
  289. };
  290. //---------------------------------------------------------------------------------------------------------------------
  291. class ScopedItemFilter
  292. {
  293. public:
  294. ScopedItemFilter() : minDepth(0), maxDepth(0), hasWildcard(false) {}
  295. bool match(const char * search) const;
  296. bool matchDepth(unsigned low, unsigned high) const;
  297. bool recurseChildScopes(const char * curScope) const;
  298. const char * queryValue() const { return value ? value.get() : "*"; }
  299. void set(const char * value);
  300. void setDepth(unsigned _minDepth);
  301. void setDepth(unsigned _minDepth, unsigned _maxDepth);
  302. protected:
  303. unsigned minDepth;
  304. unsigned maxDepth;
  305. StringAttr value;
  306. bool hasWildcard;
  307. };
  308. class jlib_decl StatisticsFilter : public CInterfaceOf<IStatisticsFilter>
  309. {
  310. public:
  311. StatisticsFilter();
  312. StatisticsFilter(const char * filter);
  313. StatisticsFilter(StatisticCreatorType _creatorType, StatisticScopeType _scopeType, StatisticMeasure _measure, StatisticKind _kind);
  314. StatisticsFilter(const char * _creatorType, const char * _scopeType, const char * _kind);
  315. StatisticsFilter(const char * _creatorTypeText, const char * _creator, const char * _scopeTypeText, const char * _scope, const char * _measureText, const char * _kindText);
  316. StatisticsFilter(StatisticCreatorType _creatorType, const char * _creator, StatisticScopeType _scopeType, const char * _scope, StatisticMeasure _measure, StatisticKind _kind);
  317. virtual bool matches(StatisticCreatorType curCreatorType, const char * curCreator, StatisticScopeType curScopeType, const char * curScope, StatisticMeasure curMeasure, StatisticKind curKind) const;
  318. virtual bool recurseChildScopes(StatisticScopeType curScopeType, const char * curScope) const;
  319. virtual const char * queryScope() const { return scopeFilter.queryValue(); }
  320. void set(const char * _creatorTypeText, const char * _scopeTypeText, const char * _kindText);
  321. void set(const char * _creatorTypeText, const char * _creator, const char * _scopeTypeText, const char * _scope, const char * _measureText, const char * _kindText);
  322. void setCreatorDepth(unsigned _minCreatorDepth, unsigned _maxCreatorDepth);
  323. void setCreator(const char * _creator);
  324. void setCreatorType(StatisticCreatorType _creatorType);
  325. void setFilter(const char * filter);
  326. void setScopeDepth(unsigned _minScopeDepth);
  327. void setScopeDepth(unsigned _minScopeDepth, unsigned _maxScopeDepth);
  328. void setScope(const char * _scope);
  329. void setScopeType(StatisticScopeType _scopeType);
  330. void setKind(StatisticKind _kind);
  331. void setKind(const char * _kind);
  332. void setMeasure(StatisticMeasure _measure);
  333. protected:
  334. void init();
  335. protected:
  336. StatisticCreatorType creatorType;
  337. StatisticScopeType scopeType;
  338. StatisticMeasure measure;
  339. StatisticKind kind;
  340. ScopedItemFilter creatorFilter;
  341. ScopedItemFilter scopeFilter;
  342. };
  343. //---------------------------------------------------------------------------------------------------------------------
  344. class jlib_decl StatisticsMapping
  345. {
  346. public:
  347. //Takes a list of StatisticKind terminated by StKindNone
  348. StatisticsMapping(StatisticKind kind, ...);
  349. //Takes an existing Mapping, and extends it with a list of StatisticKind terminated by StKindNone
  350. StatisticsMapping(const StatisticsMapping * from, ...);
  351. //Accepts all StatisticKind values
  352. StatisticsMapping();
  353. inline unsigned getIndex(StatisticKind kind) const
  354. {
  355. dbgassertex(kind >= StKindNone && kind < StMax);
  356. return kindToIndex.item(kind);
  357. }
  358. inline StatisticKind getKind(unsigned index) const { return (StatisticKind)indexToKind.item(index); }
  359. inline unsigned numStatistics() const { return indexToKind.ordinality(); }
  360. protected:
  361. void createMappings();
  362. protected:
  363. UnsignedArray kindToIndex;
  364. UnsignedArray indexToKind;
  365. };
  366. extern const jlib_decl StatisticsMapping allStatistics;
  367. //---------------------------------------------------------------------------------------------------------------------
  368. //MORE: We probably want to have functions that perform the atomic equivalents
  369. class jlib_decl CRuntimeStatistic
  370. {
  371. public:
  372. CRuntimeStatistic() : value(0) {}
  373. inline void add(unsigned __int64 delta) { value += delta; }
  374. inline void addAtomic(unsigned __int64 delta) { value += delta; }
  375. inline unsigned __int64 get() const { return value; }
  376. inline unsigned __int64 getClear()
  377. {
  378. unsigned __int64 ret = value;
  379. value -= ret;
  380. return ret;
  381. }
  382. inline unsigned __int64 getClearAtomic()
  383. {
  384. unsigned __int64 ret = value;
  385. value -= ret; // should be atomic dec...
  386. return ret;
  387. }
  388. inline void clear() { set(0); }
  389. void merge(unsigned __int64 otherValue, StatsMergeAction mergeAction);
  390. inline void set(unsigned __int64 delta) { value = delta; }
  391. protected:
  392. unsigned __int64 value;
  393. };
  394. //This class is used to gather statistics for an activity - it has no notion of scope.
  395. interface IContextLogger;
  396. class jlib_decl CRuntimeStatisticCollection
  397. {
  398. public:
  399. CRuntimeStatisticCollection(const StatisticsMapping & _mapping) : mapping(_mapping)
  400. {
  401. unsigned num = mapping.numStatistics();
  402. values = new CRuntimeStatistic[num+1]; // extra entry is to gather unexpected stats
  403. }
  404. ~CRuntimeStatisticCollection()
  405. {
  406. delete [] values;
  407. }
  408. inline CRuntimeStatistic & queryStatistic(StatisticKind kind)
  409. {
  410. unsigned index = queryMapping().getIndex(kind);
  411. dbgassertex(index < mapping.numStatistics());
  412. return values[index];
  413. }
  414. inline const CRuntimeStatistic & queryStatistic(StatisticKind kind) const
  415. {
  416. unsigned index = queryMapping().getIndex(kind);
  417. dbgassertex(index < mapping.numStatistics());
  418. return values[index];
  419. }
  420. void addStatistic(StatisticKind kind, unsigned __int64 value)
  421. {
  422. queryStatistic(kind).add(value);
  423. }
  424. void addStatisticAtomic(StatisticKind kind, unsigned __int64 value)
  425. {
  426. queryStatistic(kind).addAtomic(value);
  427. }
  428. void mergeStatistic(StatisticKind kind, unsigned __int64 value, StatsMergeAction mergeAction)
  429. {
  430. queryStatistic(kind).merge(value, mergeAction);
  431. }
  432. void setStatistic(StatisticKind kind, unsigned __int64 value)
  433. {
  434. queryStatistic(kind).set(value);
  435. }
  436. unsigned __int64 getStatisticValue(StatisticKind kind) const
  437. {
  438. return queryStatistic(kind).get();
  439. }
  440. void reset()
  441. {
  442. unsigned num = mapping.numStatistics();
  443. for (unsigned i = 0; i <= num; i++)
  444. values[i].clear();
  445. }
  446. inline const StatisticsMapping & queryMapping() const { return mapping; };
  447. inline unsigned ordinality() const { return mapping.numStatistics(); }
  448. inline StatisticKind getKind(unsigned i) const { return mapping.getKind(i); }
  449. inline unsigned __int64 getValue(unsigned i) const { return values[i].get(); }
  450. void merge(const CRuntimeStatisticCollection & other);
  451. void rollupStatistics(IContextLogger * target) { rollupStatistics(1, &target); }
  452. void rollupStatistics(unsigned num, IContextLogger * const * targets) const;
  453. void recordStatistics(IStatisticGatherer & target) const;
  454. // Print out collected stats to string
  455. StringBuffer &toStr(StringBuffer &str) const;
  456. // Print out collected stats to string as XML
  457. StringBuffer &toXML(StringBuffer &str) const;
  458. // Serialize/deserialize
  459. bool serialize(MemoryBuffer & out) const; // Returns true if any non-zero
  460. void deserialize(MemoryBuffer & in);
  461. void deserializeMerge(MemoryBuffer& in);
  462. protected:
  463. void reportIgnoredStats() const;
  464. private:
  465. const StatisticsMapping & mapping;
  466. CRuntimeStatistic * values;
  467. };
  468. //---------------------------------------------------------------------------------------------------------------------
  469. //A class for minimizing the overhead of collecting timestamps.
  470. class jlib_decl OptimizedTimestamp
  471. {
  472. public:
  473. OptimizedTimestamp();
  474. unsigned __int64 getTimeStampNowValue();
  475. protected:
  476. cycle_t lastCycles;
  477. unsigned __int64 lastTimestamp;
  478. };
  479. class IpAddress;
  480. extern jlib_decl unsigned __int64 getTimeStampNowValue();
  481. extern jlib_decl unsigned __int64 getIPV4StatsValue(const IpAddress & ip);
  482. extern jlib_decl void formatStatistic(StringBuffer & out, unsigned __int64 value, StatisticMeasure measure);
  483. extern jlib_decl void formatStatistic(StringBuffer & out, unsigned __int64 value, StatisticKind kind);
  484. extern jlib_decl unsigned __int64 mergeStatistic(StatisticMeasure measure, unsigned __int64 value, unsigned __int64 otherValue);
  485. extern jlib_decl unsigned __int64 mergeStatisticValue(unsigned __int64 prevValue, unsigned __int64 newValue, StatsMergeAction mergeAction);
  486. extern jlib_decl StatisticMeasure queryMeasure(StatisticKind kind);
  487. extern jlib_decl const char * queryStatisticName(StatisticKind kind);
  488. extern jlib_decl void queryLongStatisticName(StringBuffer & out, StatisticKind kind);
  489. extern jlib_decl const char * queryTreeTag(StatisticKind kind);
  490. extern jlib_decl const char * queryLegacyTreeTag(StatisticKind kind);
  491. extern jlib_decl const char * queryCreatorTypeName(StatisticCreatorType sct);
  492. extern jlib_decl const char * queryScopeTypeName(StatisticScopeType sst);
  493. extern jlib_decl const char * queryMeasureName(StatisticMeasure measure);
  494. extern jlib_decl StatsMergeAction queryMergeMode(StatisticMeasure measure);
  495. extern jlib_decl StatsMergeAction queryMergeMode(StatisticKind kind);
  496. extern jlib_decl StatisticMeasure queryMeasure(const char * measure);
  497. extern jlib_decl StatisticKind queryStatisticKind(const char * kind);
  498. extern jlib_decl StatisticCreatorType queryCreatorType(const char * sct);
  499. extern jlib_decl StatisticScopeType queryScopeType(const char * sst);
  500. extern jlib_decl IStatisticGatherer * createStatisticsGatherer(StatisticCreatorType creatorType, const char * creator, const StatsScopeId & rootScope);
  501. extern jlib_decl void serializeStatisticCollection(MemoryBuffer & out, IStatisticCollection * collection);
  502. extern jlib_decl IStatisticCollection * createStatisticCollection(MemoryBuffer & in);
  503. inline unsigned __int64 milliToNano(unsigned __int64 value) { return value * 1000000; } // call avoids need to upcast values
  504. inline unsigned __int64 nanoToMilli(unsigned __int64 value) { return value / 1000000; }
  505. extern jlib_decl StatisticCreatorType queryStatisticsComponentType();
  506. extern jlib_decl const char * queryStatisticsComponentName();
  507. extern jlib_decl void setStatisticsComponentName(StatisticCreatorType processType, const char * processName, bool appendIP);
  508. extern jlib_decl void verifyStatisticFunctions();
  509. extern jlib_decl void formatTimeCollatable(StringBuffer & out, unsigned __int64 value, bool nano);
  510. extern jlib_decl unsigned __int64 extractTimeCollatable(const char *s, bool nano);
  511. //This interface is primarily here to reduce the dependency between the different components.
  512. interface IStatisticTarget
  513. {
  514. virtual void addStatistic(StatisticScopeType scopeType, const char * scope, StatisticKind kind, char * description, unsigned __int64 value, unsigned __int64 count, unsigned __int64 maxValue, StatsMergeAction mergeAction) = 0;
  515. };
  516. #endif