RegexStats.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #pragma once
  6. #if ENABLE_REGEX_CONFIG_OPTIONS
  7. namespace UnifiedRegex
  8. {
  9. struct RegexStats
  10. {
  11. typedef long long Ticks;
  12. enum Phase
  13. {
  14. Parse,
  15. Compile,
  16. Execute,
  17. NumPhases
  18. };
  19. static const wchar_t* PhaseNames[NumPhases];
  20. enum Use
  21. {
  22. Match,
  23. Exec,
  24. Test,
  25. Replace,
  26. Split,
  27. Search,
  28. NumUses
  29. };
  30. static const wchar_t* UseNames[NumUses];
  31. RegexPattern* pattern; // null => total record
  32. // Time spent on regex
  33. Ticks phaseTicks[NumPhases];
  34. // How is regex used?
  35. uint64 useCounts[NumUses];
  36. // Total input length
  37. uint64 inputLength;
  38. // Total chars looked at (may be > length if backtrack, < length if using Boyer-Moore)
  39. uint64 numCompares;
  40. // Number of continuation stack pushes
  41. uint64 numPushes;
  42. // Number of continuation stack pops
  43. uint64 numPops;
  44. // Continuation stack high-water-mark
  45. uint64 stackHWM;
  46. // Number of instructions executed
  47. uint64 numInsts;
  48. RegexStats(RegexPattern* pattern);
  49. void Print(DebugWriter* w, RegexStats* totals, Ticks ticksPerMillisecond);
  50. void Add(RegexStats* other);
  51. };
  52. typedef JsUtil::BaseDictionary<Js::InternalString, RegexStats*, ArenaAllocator, PrimeSizePolicy, DefaultComparer, JsUtil::DictionaryEntry> RegexStatsMap;
  53. class RegexStatsDatabase
  54. {
  55. private:
  56. RegexStats::Ticks ticksPerMillisecond;
  57. RegexStats::Ticks start;
  58. ArenaAllocator* allocator;
  59. RegexStatsMap* map;
  60. static RegexStats::Ticks Now();
  61. static RegexStats::Ticks Freq();
  62. public:
  63. RegexStatsDatabase(ArenaAllocator* allocator);
  64. RegexStats* GetRegexStats(RegexPattern* pattern);
  65. void BeginProfile();
  66. void EndProfile(RegexStats* stats, RegexStats::Phase phase);
  67. void Print(DebugWriter* w);
  68. };
  69. }
  70. #endif