PageRenderTime 31ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llcommon/llmetricperformancetester.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 215 lines | 60 code | 29 blank | 126 comment | 0 complexity | 2fd909c0268d97b71d2543c65c58983f MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llmetricperformancetester.h
  3. * @brief LLMetricPerformanceTesterBasic and LLMetricPerformanceTesterWithSession classes definition
  4. *
  5. * $LicenseInfo:firstyear=2004&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #ifndef LL_METRICPERFORMANCETESTER_H
  27. #define LL_METRICPERFORMANCETESTER_H
  28. char const* const DEFAULT_METRIC_NAME = "metric";
  29. /**
  30. * @class LLMetricPerformanceTesterBasic
  31. * @brief Performance Metric Base Class
  32. */
  33. class LL_COMMON_API LLMetricPerformanceTesterBasic
  34. {
  35. public:
  36. /**
  37. * @brief Creates a basic tester instance.
  38. * @param[in] name - Unique string identifying this tester instance.
  39. */
  40. LLMetricPerformanceTesterBasic(std::string name);
  41. virtual ~LLMetricPerformanceTesterBasic();
  42. /**
  43. * @return Returns true if the instance has been added to the tester map.
  44. * Need to be tested after creation of a tester instance so to know if the tester is correctly handled.
  45. * A tester might not be added to the map if another tester with the same name already exists.
  46. */
  47. BOOL isValid() const { return mValidInstance; }
  48. /**
  49. * @brief Write a set of test results to the log LLSD.
  50. */
  51. void outputTestResults() ;
  52. /**
  53. * @brief Compare the test results.
  54. * By default, compares the test results against the baseline one by one, item by item,
  55. * in the increasing order of the LLSD record counter, starting from the first one.
  56. */
  57. virtual void analyzePerformance(std::ofstream* os, LLSD* base, LLSD* current) ;
  58. static void doAnalysisMetrics(std::string baseline, std::string target, std::string output) ;
  59. /**
  60. * @return Returns the number of the test metrics in this tester instance.
  61. */
  62. S32 getNumberOfMetrics() const { return mMetricStrings.size() ;}
  63. /**
  64. * @return Returns the metric name at index
  65. * @param[in] index - Index on the list of metrics managed by this tester instance.
  66. */
  67. std::string getMetricName(S32 index) const { return mMetricStrings[index] ;}
  68. protected:
  69. /**
  70. * @return Returns the name of this tester instance.
  71. */
  72. std::string getTesterName() const { return mName ;}
  73. /**
  74. * @brief Insert a new metric to be managed by this tester instance.
  75. * @param[in] str - Unique string identifying the new metric.
  76. */
  77. void addMetric(std::string str) ;
  78. /**
  79. * @brief Compare test results, provided in 2 flavors: compare integers and compare floats.
  80. * @param[out] os - Formatted output string holding the compared values.
  81. * @param[in] metric_string - Name of the metric.
  82. * @param[in] v_base - Base value of the metric.
  83. * @param[in] v_current - Current value of the metric.
  84. */
  85. virtual void compareTestResults(std::ofstream* os, std::string metric_string, S32 v_base, S32 v_current) ;
  86. virtual void compareTestResults(std::ofstream* os, std::string metric_string, F32 v_base, F32 v_current) ;
  87. /**
  88. * @brief Reset internal record count. Count starts with 1.
  89. */
  90. void resetCurrentCount() { mCount = 1; }
  91. /**
  92. * @brief Increment internal record count.
  93. */
  94. void incrementCurrentCount() { mCount++; }
  95. /**
  96. * @return Returns the label to be used for the current count. It's "TesterName"-"Count".
  97. */
  98. std::string getCurrentLabelName() const { return llformat("%s-%d", mName.c_str(), mCount) ;}
  99. /**
  100. * @brief Write a test record to the LLSD. Implementers need to overload this method.
  101. * @param[out] sd - The LLSD record to store metric data into.
  102. */
  103. virtual void outputTestRecord(LLSD* sd) = 0 ;
  104. private:
  105. void preOutputTestResults(LLSD* sd) ;
  106. void postOutputTestResults(LLSD* sd) ;
  107. static LLSD analyzeMetricPerformanceLog(std::istream& is) ;
  108. std::string mName ; // Name of this tester instance
  109. S32 mCount ; // Current record count
  110. BOOL mValidInstance; // TRUE if the instance is managed by the map
  111. std::vector< std::string > mMetricStrings ; // Metrics strings
  112. // Static members managing the collection of testers
  113. public:
  114. // Map of all the tester instances in use
  115. typedef std::map< std::string, LLMetricPerformanceTesterBasic* > name_tester_map_t;
  116. static name_tester_map_t sTesterMap ;
  117. /**
  118. * @return Returns a pointer to the tester
  119. * @param[in] name - Name of the tester instance queried.
  120. */
  121. static LLMetricPerformanceTesterBasic* getTester(std::string name) ;
  122. /**
  123. * @return Delete the named tester from the list
  124. * @param[in] name - Name of the tester instance to delete.
  125. */
  126. static void deleteTester(std::string name);
  127. /**
  128. * @return Returns TRUE if that metric *or* the default catch all metric has been requested to be logged
  129. * @param[in] name - Name of the tester queried.
  130. */
  131. static BOOL isMetricLogRequested(std::string name);
  132. /**
  133. * @return Returns TRUE if there's a tester defined, FALSE otherwise.
  134. */
  135. static BOOL hasMetricPerformanceTesters() { return !sTesterMap.empty() ;}
  136. /**
  137. * @brief Delete all testers and reset the tester map
  138. */
  139. static void cleanClass() ;
  140. private:
  141. // Add a tester to the map. Returns false if adding fails.
  142. static BOOL addTester(LLMetricPerformanceTesterBasic* tester) ;
  143. };
  144. /**
  145. * @class LLMetricPerformanceTesterWithSession
  146. * @brief Performance Metric Class with custom session
  147. */
  148. class LL_COMMON_API LLMetricPerformanceTesterWithSession : public LLMetricPerformanceTesterBasic
  149. {
  150. public:
  151. /**
  152. * @param[in] name - Unique string identifying this tester instance.
  153. */
  154. LLMetricPerformanceTesterWithSession(std::string name);
  155. virtual ~LLMetricPerformanceTesterWithSession();
  156. /**
  157. * @brief Compare the test results.
  158. * This will be loading the base and current sessions and compare them using the virtual
  159. * abstract methods loadTestSession() and compareTestSessions()
  160. */
  161. virtual void analyzePerformance(std::ofstream* os, LLSD* base, LLSD* current) ;
  162. protected:
  163. /**
  164. * @class LLMetricPerformanceTesterWithSession::LLTestSession
  165. * @brief Defines an interface for the two abstract virtual functions loadTestSession() and compareTestSessions()
  166. */
  167. class LL_COMMON_API LLTestSession
  168. {
  169. public:
  170. virtual ~LLTestSession() ;
  171. };
  172. /**
  173. * @brief Convert an LLSD log into a test session.
  174. * @param[in] log - The LLSD record
  175. * @return Returns the record as a test session
  176. */
  177. virtual LLMetricPerformanceTesterWithSession::LLTestSession* loadTestSession(LLSD* log) = 0;
  178. /**
  179. * @brief Compare the base session and the target session. Assumes base and current sessions have been loaded.
  180. * @param[out] os - The comparison result as a standard stream
  181. */
  182. virtual void compareTestSessions(std::ofstream* os) = 0;
  183. LLTestSession* mBaseSessionp;
  184. LLTestSession* mCurrentSessionp;
  185. };
  186. #endif