jstats.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  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, // Is measurement in K appropriate?
  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. //---------------------------------------------------------------------------------------------------------------------
  161. interface IStatistic : extends IInterface
  162. {
  163. public:
  164. virtual StatisticKind queryKind() const = 0;
  165. virtual unsigned __int64 queryValue() const = 0;
  166. };
  167. interface IStatisticFilter
  168. {
  169. virtual bool matches(IStatistic * stats) = 0;
  170. virtual void getFilter(StringBuffer & out) = 0;
  171. };
  172. interface IStatisticIterator : public IIteratorOf<IStatistic>
  173. {
  174. };
  175. //Represents a single level of a scope
  176. class jlib_decl StatsScopeId
  177. {
  178. public:
  179. StatsScopeId() : id(0), extra(0), scopeType(SSTnone) {}
  180. StatsScopeId(StatisticScopeType _scopeType, unsigned _id, unsigned _extra = 0)
  181. : id(_id), extra(_extra), scopeType(_scopeType)
  182. {
  183. }
  184. StatisticScopeType queryScopeType() const { return scopeType; }
  185. StringBuffer & getScopeText(StringBuffer & out) const;
  186. unsigned getHash() const;
  187. bool matches(const StatsScopeId & other) const;
  188. unsigned queryActivity() const;
  189. void deserialize(MemoryBuffer & in, unsigned version);
  190. void serialize(MemoryBuffer & out) const;
  191. bool setScopeText(const char * text);
  192. void setId(StatisticScopeType _scopeType, unsigned _id, unsigned _extra = 0);
  193. void setActivityId(unsigned _id);
  194. void setEdgeId(unsigned _id, unsigned _output);
  195. void setSubgraphId(unsigned _id);
  196. bool operator == (const StatsScopeId & other) const { return matches(other); }
  197. protected:
  198. //If any more items are added then this could become a union...
  199. unsigned id;
  200. unsigned extra;
  201. StatisticScopeType scopeType;
  202. };
  203. interface IStatisticCollectionIterator;
  204. interface IStatisticCollection : public IInterface
  205. {
  206. public:
  207. virtual StatisticScopeType queryScopeType() const = 0;
  208. virtual StringBuffer & getFullScope(StringBuffer & str) const = 0;
  209. virtual StringBuffer & getScope(StringBuffer & str) const = 0;
  210. virtual unsigned __int64 queryStatistic(StatisticKind kind) const = 0;
  211. virtual unsigned getNumStatistics() const = 0;
  212. virtual void getStatistic(StatisticKind & kind, unsigned __int64 & value, unsigned idx) const = 0;
  213. virtual IStatisticCollectionIterator & getScopes(const char * filter) = 0;
  214. virtual void getMinMaxScope(IStringVal & minValue, IStringVal & maxValue, StatisticScopeType searchScopeType) const = 0;
  215. virtual void getMinMaxActivity(unsigned & minValue, unsigned & maxValue) const = 0;
  216. virtual void serialize(MemoryBuffer & out) const = 0;
  217. virtual unsigned __int64 queryWhenCreated() const = 0;
  218. };
  219. interface IStatisticCollectionIterator : public IIteratorOf<IStatisticCollection>
  220. {
  221. };
  222. enum StatsMergeAction
  223. {
  224. StatsMergeKeep,
  225. StatsMergeReplace,
  226. StatsMergeSum,
  227. StatsMergeMin,
  228. StatsMergeMax,
  229. StatsMergeAppend,
  230. };
  231. interface IStatisticGatherer : public IInterface
  232. {
  233. public:
  234. virtual void beginScope(const StatsScopeId & id) = 0;
  235. virtual void beginSubGraphScope(unsigned id) = 0;
  236. virtual void beginActivityScope(unsigned id) = 0;
  237. virtual void beginEdgeScope(unsigned id, unsigned oid) = 0;
  238. virtual void endScope() = 0;
  239. virtual void addStatistic(StatisticKind kind, unsigned __int64 value) = 0;
  240. virtual void updateStatistic(StatisticKind kind, unsigned __int64 value, StatsMergeAction mergeAction) = 0;
  241. virtual IStatisticCollection * getResult() = 0;
  242. };
  243. //All filtering should go through this interface - so we can extend and allow AND/OR filters at a later date.
  244. interface IStatisticsFilter : public IInterface
  245. {
  246. public:
  247. virtual bool matches(StatisticCreatorType curCreatorType, const char * curCreator, StatisticScopeType curScopeType, const char * curScope, StatisticMeasure curMeasure, StatisticKind curKind) const = 0;
  248. //These are a bit arbitrary...
  249. virtual bool queryMergeSources() 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. const char * queryValue() const { return value ? value.get() : "*"; }
  298. void set(const char * value);
  299. void setDepth(unsigned _minDepth);
  300. void setDepth(unsigned _minDepth, unsigned _maxDepth);
  301. protected:
  302. unsigned minDepth;
  303. unsigned maxDepth;
  304. StringAttr value;
  305. bool hasWildcard;
  306. };
  307. class jlib_decl StatisticsFilter : public CInterfaceOf<IStatisticsFilter>
  308. {
  309. public:
  310. StatisticsFilter();
  311. StatisticsFilter(const char * filter);
  312. StatisticsFilter(StatisticCreatorType _creatorType, StatisticScopeType _scopeType, StatisticMeasure _measure, StatisticKind _kind);
  313. StatisticsFilter(const char * _creatorType, const char * _scopeType, const char * _kind);
  314. StatisticsFilter(const char * _creatorTypeText, const char * _creator, const char * _scopeTypeText, const char * _scope, const char * _measureText, const char * _kindText);
  315. StatisticsFilter(StatisticCreatorType _creatorType, const char * _creator, StatisticScopeType _scopeType, const char * _scope, StatisticMeasure _measure, StatisticKind _kind);
  316. virtual bool matches(StatisticCreatorType curCreatorType, const char * curCreator, StatisticScopeType curScopeType, const char * curScope, StatisticMeasure curMeasure, StatisticKind curKind) const;
  317. virtual bool queryMergeSources() const { return mergeSources && scopeFilter.matchDepth(2,0); }
  318. virtual const char * queryScope() const { return scopeFilter.queryValue(); }
  319. void set(const char * _creatorTypeText, const char * _scopeTypeText, const char * _kindText);
  320. void set(const char * _creatorTypeText, const char * _creator, const char * _scopeTypeText, const char * _scope, const char * _measureText, const char * _kindText);
  321. void setCreatorDepth(unsigned _minCreatorDepth, unsigned _maxCreatorDepth);
  322. void setCreator(const char * _creator);
  323. void setCreatorType(StatisticCreatorType _creatorType);
  324. void setFilter(const char * filter);
  325. void setScopeDepth(unsigned _minScopeDepth);
  326. void setScopeDepth(unsigned _minScopeDepth, unsigned _maxScopeDepth);
  327. void setScope(const char * _scope);
  328. void setScopeType(StatisticScopeType _scopeType);
  329. void setKind(StatisticKind _kind);
  330. void setKind(const char * _kind);
  331. void setMeasure(StatisticMeasure _measure);
  332. void setMergeSources(bool _value); // set to false for legacy timing semantics
  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. bool mergeSources;
  343. };
  344. //---------------------------------------------------------------------------------------------------------------------
  345. class jlib_decl StatisticsMapping
  346. {
  347. public:
  348. //Takes a list of StatisticKind terminated by StKindNone
  349. StatisticsMapping(StatisticKind kind, ...);
  350. //Takes an existing Mapping, and extends it with a list of StatisticKind terminated by StKindNone
  351. StatisticsMapping(const StatisticsMapping &, ...);
  352. //Accepts all StatisticKind values
  353. StatisticsMapping();
  354. inline unsigned getIndex(StatisticKind kind) const
  355. {
  356. dbgassertex(kind >= StKindNone && kind < StMax);
  357. return kindToIndex.item(kind);
  358. }
  359. inline StatisticKind getKind(unsigned index) const { return (StatisticKind)indexToKind.item(index); }
  360. inline unsigned numStatistics() const { return indexToKind.ordinality(); }
  361. protected:
  362. void createMappings();
  363. protected:
  364. UnsignedArray kindToIndex;
  365. UnsignedArray indexToKind;
  366. };
  367. extern const jlib_decl StatisticsMapping allStatistics;
  368. //---------------------------------------------------------------------------------------------------------------------
  369. //MORE: We probably want to have functions that perform the atomic equivalents
  370. class jlib_decl CRuntimeStatistic
  371. {
  372. public:
  373. CRuntimeStatistic() : value(0) {}
  374. inline void add(unsigned __int64 delta) { value += delta; }
  375. inline void addAtomic(unsigned __int64 delta) { value += delta; }
  376. inline unsigned __int64 get() const { return value; }
  377. inline unsigned __int64 getClear()
  378. {
  379. unsigned __int64 ret = value;
  380. value -= ret;
  381. return ret;
  382. }
  383. inline unsigned __int64 getClearAtomic()
  384. {
  385. unsigned __int64 ret = value;
  386. value -= ret; // should be atomic dec...
  387. return ret;
  388. }
  389. inline void clear() { set(0); }
  390. void merge(unsigned __int64 otherValue, StatsMergeAction mergeAction);
  391. inline void set(unsigned __int64 delta) { value = delta; }
  392. protected:
  393. unsigned __int64 value;
  394. };
  395. //This class is used to gather statistics for an activity - it has no notion of scope.
  396. interface IContextLogger;
  397. class jlib_decl CRuntimeStatisticCollection
  398. {
  399. public:
  400. CRuntimeStatisticCollection(const StatisticsMapping & _mapping) : mapping(_mapping)
  401. {
  402. unsigned num = mapping.numStatistics();
  403. values = new CRuntimeStatistic[num+1]; // extra entry is to gather unexpected stats
  404. }
  405. ~CRuntimeStatisticCollection()
  406. {
  407. delete [] values;
  408. }
  409. inline CRuntimeStatistic & queryStatistic(StatisticKind kind)
  410. {
  411. unsigned index = queryMapping().getIndex(kind);
  412. dbgassertex(index < mapping.numStatistics());
  413. return values[index];
  414. }
  415. inline const CRuntimeStatistic & queryStatistic(StatisticKind kind) const
  416. {
  417. unsigned index = queryMapping().getIndex(kind);
  418. dbgassertex(index < mapping.numStatistics());
  419. return values[index];
  420. }
  421. void addStatistic(StatisticKind kind, unsigned __int64 value)
  422. {
  423. queryStatistic(kind).add(value);
  424. }
  425. void addStatisticAtomic(StatisticKind kind, unsigned __int64 value)
  426. {
  427. queryStatistic(kind).addAtomic(value);
  428. }
  429. void mergeStatistic(StatisticKind kind, unsigned __int64 value, StatsMergeAction mergeAction)
  430. {
  431. queryStatistic(kind).merge(value, mergeAction);
  432. }
  433. void setStatistic(StatisticKind kind, unsigned __int64 value)
  434. {
  435. queryStatistic(kind).set(value);
  436. }
  437. unsigned __int64 getStatisticValue(StatisticKind kind) const
  438. {
  439. return queryStatistic(kind).get();
  440. }
  441. void reset()
  442. {
  443. unsigned num = mapping.numStatistics();
  444. for (unsigned i = 0; i <= num; i++)
  445. values[i].clear();
  446. }
  447. inline const StatisticsMapping & queryMapping() const { return mapping; };
  448. inline unsigned ordinality() const { return mapping.numStatistics(); }
  449. inline StatisticKind getKind(unsigned i) const { return mapping.getKind(i); }
  450. inline unsigned __int64 getValue(unsigned i) const { return values[i].get(); }
  451. void merge(const CRuntimeStatisticCollection & other);
  452. void rollupStatistics(IContextLogger * target) { rollupStatistics(1, &target); }
  453. void rollupStatistics(unsigned num, IContextLogger * const * targets) const;
  454. void recordStatistics(IStatisticGatherer & target) const;
  455. // Print out collected stats to string
  456. StringBuffer &toStr(StringBuffer &str) const;
  457. // Print out collected stats to string as XML
  458. StringBuffer &toXML(StringBuffer &str) const;
  459. // Serialize/deserialize
  460. bool serialize(MemoryBuffer & out) const; // Returns true if any non-zero
  461. void deserialize(MemoryBuffer & in);
  462. void deserializeMerge(MemoryBuffer& in);
  463. protected:
  464. void reportIgnoredStats() const;
  465. private:
  466. const StatisticsMapping & mapping;
  467. CRuntimeStatistic * values;
  468. };
  469. //---------------------------------------------------------------------------------------------------------------------
  470. //A class for minimizing the overhead of collecting timestamps.
  471. class jlib_decl OptimizedTimestamp
  472. {
  473. public:
  474. OptimizedTimestamp();
  475. unsigned __int64 getTimeStampNowValue();
  476. protected:
  477. cycle_t lastCycles;
  478. unsigned __int64 lastTimestamp;
  479. };
  480. class IpAddress;
  481. extern jlib_decl unsigned __int64 getTimeStampNowValue();
  482. extern jlib_decl unsigned __int64 getIPV4StatsValue(const IpAddress & ip);
  483. extern jlib_decl void formatStatistic(StringBuffer & out, unsigned __int64 value, StatisticMeasure measure);
  484. extern jlib_decl void formatStatistic(StringBuffer & out, unsigned __int64 value, StatisticKind kind);
  485. extern jlib_decl unsigned __int64 mergeStatistic(StatisticMeasure measure, unsigned __int64 value, unsigned __int64 otherValue);
  486. extern jlib_decl unsigned __int64 mergeStatisticValue(unsigned __int64 prevValue, unsigned __int64 newValue, StatsMergeAction mergeAction);
  487. extern jlib_decl StatisticMeasure queryMeasure(StatisticKind kind);
  488. extern jlib_decl const char * queryStatisticName(StatisticKind kind);
  489. extern jlib_decl void queryLongStatisticName(StringBuffer & out, StatisticKind kind);
  490. extern jlib_decl const char * queryTreeTag(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. //This interface is primarily here to reduce the dependency between the different components.
  510. interface IStatisticTarget
  511. {
  512. virtual void addStatistic(StatisticScopeType scopeType, const char * scope, StatisticKind kind, char * description, unsigned __int64 value, unsigned __int64 count, unsigned __int64 maxValue, StatsMergeAction mergeAction) = 0;
  513. };
  514. #endif