PageRenderTime 28ms CodeModel.GetById 14ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llcommon/llmetrics.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 163 lines | 100 code | 25 blank | 38 comment | 8 complexity | 0084eb874d78cac12e0d89fa519dc37b MD5 | raw file
  1/** 
  2 * @file llmetrics.cpp
  3 * @author Kelly
  4 * @date 2007-05-25
  5 * @brief Metrics accumulation and associated functions
  6 *
  7 * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  8 * Second Life Viewer Source Code
  9 * Copyright (C) 2010, Linden Research, Inc.
 10 * 
 11 * This library is free software; you can redistribute it and/or
 12 * modify it under the terms of the GNU Lesser General Public
 13 * License as published by the Free Software Foundation;
 14 * version 2.1 of the License only.
 15 * 
 16 * This library is distributed in the hope that it will be useful,
 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 19 * Lesser General Public License for more details.
 20 * 
 21 * You should have received a copy of the GNU Lesser General Public
 22 * License along with this library; if not, write to the Free Software
 23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 24 * 
 25 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 26 * $/LicenseInfo$
 27 */
 28
 29#include "linden_common.h"
 30#include "llmetrics.h"
 31
 32#include "llsd.h"
 33#include "llsdserialize.h"
 34#include "llframetimer.h"
 35
 36class LLMetricsImpl
 37{
 38public:
 39	LLMetricsImpl() { }
 40	~LLMetricsImpl();
 41
 42	void recordEvent(const std::string& location, const std::string& mesg, bool success);
 43	void printTotals(LLSD metadata);
 44	void recordEventDetails(const std::string& location, 
 45									const std::string& mesg, 
 46									bool success, 
 47									LLSD stats);
 48private:
 49	LLFrameTimer mLastPrintTimer;
 50	LLSD mMetricsMap;
 51};
 52
 53LLMetricsImpl::~LLMetricsImpl()
 54{
 55}
 56
 57void LLMetricsImpl::recordEventDetails(const std::string& location, 
 58									const std::string& mesg, 
 59									bool success, 
 60									LLSD stats)
 61{
 62	recordEvent(location,mesg,success);
 63
 64	LLSD metrics = LLSD::emptyMap();
 65	metrics["location"] = location;
 66	metrics["stats"]  = stats;
 67	
 68	llinfos << "LLMETRICS: " << (LLSDNotationStreamer(metrics)) << llendl; 
 69}
 70
 71// Store this:
 72// [ {'location_1':{'mesg_1':{'success':i10, 'fail':i0},
 73//					'mesg_2':{'success':i10, 'fail':i0}},
 74//   {'location_2',{'mesg_3':{'success':i10, 'fail':i0}} ]
 75void LLMetricsImpl::recordEvent(const std::string& location, const std::string& mesg, bool success)
 76{
 77	LLSD& stats = mMetricsMap[location][mesg];
 78	if (success)
 79	{
 80		stats["success"] = stats["success"].asInteger() + 1;
 81	}
 82	else
 83	{
 84		stats["fail"] = stats["fail"].asInteger() + 1;
 85	}
 86}
 87
 88// Print this:
 89// { 'meta':
 90//		{ 'elapsed_time':r3600.000 }
 91//   'stats':
 92//		[ {'location':'location_1', 'mesg':'mesg_1', 'success':i10, 'fail':i0},
 93//		  {'location':'location_1', 'mesg':'mesg_2', 'success':i10, 'fail':i0},
 94//		  {'location':'location_2', 'mesg':'mesg_3', 'success':i10, 'fail':i0} ] }
 95void LLMetricsImpl::printTotals(LLSD metadata)
 96{
 97	F32 elapsed_time = mLastPrintTimer.getElapsedTimeAndResetF32();
 98	metadata["elapsed_time"] = elapsed_time;
 99
100	LLSD out_sd = LLSD::emptyMap();
101	out_sd["meta"] = metadata;
102		
103	LLSD stats = LLSD::emptyArray();
104
105	LLSD::map_const_iterator loc_it = mMetricsMap.beginMap();
106	LLSD::map_const_iterator loc_end = mMetricsMap.endMap();
107	for ( ; loc_it != loc_end; ++loc_it)
108	{
109		const std::string& location = (*loc_it).first;
110		
111		const LLSD& loc_map = (*loc_it).second;
112		LLSD::map_const_iterator mesg_it = loc_map.beginMap();
113		LLSD::map_const_iterator mesg_end = loc_map.endMap();
114		for ( ; mesg_it != mesg_end; ++mesg_it)
115		{
116			const std::string& mesg = (*mesg_it).first;
117			const LLSD& mesg_map = (*mesg_it).second;
118
119			LLSD entry = LLSD::emptyMap();
120			entry["location"] = location;
121			entry["mesg"] = mesg;
122			entry["success"] = mesg_map["success"];
123			entry["fail"] = mesg_map["fail"];
124		
125			stats.append(entry);
126		}
127	}
128
129	out_sd["stats"] = stats;
130
131	llinfos << "LLMETRICS: AGGREGATE: " << LLSDOStreamer<LLSDNotationFormatter>(out_sd) << llendl;
132}
133
134LLMetrics::LLMetrics()
135{
136	mImpl = new LLMetricsImpl();
137}
138
139LLMetrics::~LLMetrics()
140{
141	delete mImpl;
142	mImpl = NULL;
143}
144
145void LLMetrics::recordEvent(const std::string& location, const std::string& mesg, bool success)
146{
147	if (mImpl) mImpl->recordEvent(location,mesg,success);
148}
149
150void LLMetrics::printTotals(LLSD meta)
151{
152	if (mImpl) mImpl->printTotals(meta);
153}
154
155
156void LLMetrics::recordEventDetails(const std::string& location, 
157									const std::string& mesg, 
158									bool success, 
159									LLSD stats)
160{
161	if (mImpl) mImpl->recordEventDetails(location,mesg,success,stats);
162}
163