PageRenderTime 39ms CodeModel.GetById 6ms app.highlight 24ms RepoModel.GetById 2ms 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
  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
 27#ifndef LL_METRICPERFORMANCETESTER_H 
 28#define LL_METRICPERFORMANCETESTER_H 
 29
 30char const* const DEFAULT_METRIC_NAME = "metric";
 31
 32/**
 33 * @class LLMetricPerformanceTesterBasic
 34 * @brief Performance Metric Base Class
 35 */
 36class LL_COMMON_API LLMetricPerformanceTesterBasic
 37{
 38public:
 39	/**
 40	 * @brief Creates a basic tester instance.
 41	 * @param[in] name - Unique string identifying this tester instance.
 42	 */
 43	LLMetricPerformanceTesterBasic(std::string name);
 44	virtual ~LLMetricPerformanceTesterBasic();
 45
 46	/**
 47	 * @return Returns true if the instance has been added to the tester map.
 48	 * Need to be tested after creation of a tester instance so to know if the tester is correctly handled.
 49	 * A tester might not be added to the map if another tester with the same name already exists.
 50	 */
 51	BOOL isValid() const { return mValidInstance; }
 52
 53	/**
 54	 * @brief Write a set of test results to the log LLSD.
 55	 */
 56	void outputTestResults() ;
 57
 58	/**
 59	 * @brief Compare the test results.
 60	 * By default, compares the test results against the baseline one by one, item by item, 
 61	 * in the increasing order of the LLSD record counter, starting from the first one.
 62	 */
 63	virtual void analyzePerformance(std::ofstream* os, LLSD* base, LLSD* current) ;
 64
 65	static void doAnalysisMetrics(std::string baseline, std::string target, std::string output) ;
 66
 67	/**
 68	 * @return Returns the number of the test metrics in this tester instance.
 69	 */
 70	S32 getNumberOfMetrics() const { return mMetricStrings.size() ;}
 71	/**
 72	 * @return Returns the metric name at index
 73	 * @param[in] index - Index on the list of metrics managed by this tester instance.
 74	 */
 75	std::string getMetricName(S32 index) const { return mMetricStrings[index] ;}
 76
 77protected:
 78	/**
 79	 * @return Returns the name of this tester instance.
 80	 */
 81	std::string getTesterName() const { return mName ;}
 82
 83	/**
 84	 * @brief Insert a new metric to be managed by this tester instance.
 85	 * @param[in] str - Unique string identifying the new metric.
 86	 */
 87	void addMetric(std::string str) ;
 88
 89	/**
 90	 * @brief Compare test results, provided in 2 flavors: compare integers and compare floats.
 91	 * @param[out] os - Formatted output string holding the compared values.
 92	 * @param[in] metric_string - Name of the metric.
 93	 * @param[in] v_base - Base value of the metric.
 94	 * @param[in] v_current - Current value of the metric.
 95	 */
 96	virtual void compareTestResults(std::ofstream* os, std::string metric_string, S32 v_base, S32 v_current) ;
 97	virtual void compareTestResults(std::ofstream* os, std::string metric_string, F32 v_base, F32 v_current) ;
 98
 99	/**
100	 * @brief Reset internal record count. Count starts with 1.
101	 */
102	void resetCurrentCount() { mCount = 1; }
103	/**
104	 * @brief Increment internal record count.
105	 */
106	void incrementCurrentCount() { mCount++; }
107	/**
108	 * @return Returns the label to be used for the current count. It's "TesterName"-"Count".
109	 */
110	std::string getCurrentLabelName() const { return llformat("%s-%d", mName.c_str(), mCount) ;}
111
112	/**
113	 * @brief Write a test record to the LLSD. Implementers need to overload this method.
114	 * @param[out] sd - The LLSD record to store metric data into.
115	 */
116	virtual void outputTestRecord(LLSD* sd) = 0 ;
117
118private:
119	void preOutputTestResults(LLSD* sd) ;
120	void postOutputTestResults(LLSD* sd) ;
121	static LLSD analyzeMetricPerformanceLog(std::istream& is) ;
122
123	std::string mName ;							// Name of this tester instance
124	S32 mCount ;								// Current record count
125	BOOL mValidInstance;						// TRUE if the instance is managed by the map
126	std::vector< std::string > mMetricStrings ; // Metrics strings
127
128// Static members managing the collection of testers
129public:	
130	// Map of all the tester instances in use
131	typedef std::map< std::string, LLMetricPerformanceTesterBasic* > name_tester_map_t;	
132	static name_tester_map_t sTesterMap ;
133
134	/**
135	 * @return Returns a pointer to the tester
136	 * @param[in] name - Name of the tester instance queried.
137	 */
138	static LLMetricPerformanceTesterBasic* getTester(std::string name) ;
139	
140	/**
141	 * @return Delete the named tester from the list 
142	 * @param[in] name - Name of the tester instance to delete.
143	 */
144	static void deleteTester(std::string name);
145
146	/**
147	 * @return Returns TRUE if that metric *or* the default catch all metric has been requested to be logged
148	 * @param[in] name - Name of the tester queried.
149	 */
150	static BOOL isMetricLogRequested(std::string name);
151	
152	/**
153	 * @return Returns TRUE if there's a tester defined, FALSE otherwise.
154	 */
155	static BOOL hasMetricPerformanceTesters() { return !sTesterMap.empty() ;}
156	/**
157	 * @brief Delete all testers and reset the tester map
158	 */
159	static void cleanClass() ;
160
161private:
162	// Add a tester to the map. Returns false if adding fails.
163	static BOOL addTester(LLMetricPerformanceTesterBasic* tester) ;
164};
165
166/**
167 * @class LLMetricPerformanceTesterWithSession
168 * @brief Performance Metric Class with custom session 
169 */
170class LL_COMMON_API LLMetricPerformanceTesterWithSession : public LLMetricPerformanceTesterBasic
171{
172public:
173	/**
174	 * @param[in] name - Unique string identifying this tester instance.
175	 */
176	LLMetricPerformanceTesterWithSession(std::string name);
177	virtual ~LLMetricPerformanceTesterWithSession();
178
179	/**
180	 * @brief Compare the test results.
181	 * This will be loading the base and current sessions and compare them using the virtual 
182	 * abstract methods loadTestSession() and compareTestSessions()
183	 */
184	virtual void analyzePerformance(std::ofstream* os, LLSD* base, LLSD* current) ;
185
186protected:
187	/**
188	 * @class LLMetricPerformanceTesterWithSession::LLTestSession
189	 * @brief Defines an interface for the two abstract virtual functions loadTestSession() and compareTestSessions()
190	 */
191	class LL_COMMON_API LLTestSession
192		{
193		public:
194			virtual ~LLTestSession() ;
195		};
196
197	/**
198	 * @brief Convert an LLSD log into a test session.
199	 * @param[in] log - The LLSD record
200	 * @return Returns the record as a test session
201	 */
202	virtual LLMetricPerformanceTesterWithSession::LLTestSession* loadTestSession(LLSD* log) = 0;
203
204	/**
205	 * @brief Compare the base session and the target session. Assumes base and current sessions have been loaded.
206	 * @param[out] os - The comparison result as a standard stream
207	 */
208	virtual void compareTestSessions(std::ofstream* os) = 0;
209
210	LLTestSession* mBaseSessionp;
211	LLTestSession* mCurrentSessionp;
212};
213
214#endif
215