diff options
Diffstat (limited to '')
-rw-r--r-- | linden/indra/llcommon/llmetrics.cpp | 165 |
1 files changed, 165 insertions, 0 deletions
diff --git a/linden/indra/llcommon/llmetrics.cpp b/linden/indra/llcommon/llmetrics.cpp new file mode 100644 index 0000000..583f840 --- /dev/null +++ b/linden/indra/llcommon/llmetrics.cpp | |||
@@ -0,0 +1,165 @@ | |||
1 | /** | ||
2 | * @file llmetrics.cpp | ||
3 | * @author Kelly | ||
4 | * @date 2007-05-25 | ||
5 | * @brief Metrics accumulation and associated functions | ||
6 | * | ||
7 | * Copyright (c) 2007-2007, Linden Research, Inc. | ||
8 | * | ||
9 | * Second Life Viewer Source Code | ||
10 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
11 | * to you under the terms of the GNU General Public License, version 2.0 | ||
12 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
13 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
14 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
15 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
16 | * | ||
17 | * There are special exceptions to the terms and conditions of the GPL as | ||
18 | * it is applied to this Source Code. View the full text of the exception | ||
19 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
20 | * online at http://secondlife.com/developers/opensource/flossexception | ||
21 | * | ||
22 | * By copying, modifying or distributing this software, you acknowledge | ||
23 | * that you have read and understood your obligations described above, | ||
24 | * and agree to abide by those obligations. | ||
25 | * | ||
26 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
27 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
28 | * COMPLETENESS OR PERFORMANCE. | ||
29 | */ | ||
30 | |||
31 | #include "linden_common.h" | ||
32 | #include "llmetrics.h" | ||
33 | |||
34 | #include "llsd.h" | ||
35 | #include "llsdserialize.h" | ||
36 | #include "llframetimer.h" | ||
37 | |||
38 | class LLMetricsImpl | ||
39 | { | ||
40 | public: | ||
41 | LLMetricsImpl() { } | ||
42 | ~LLMetricsImpl(); | ||
43 | |||
44 | void recordEvent(const std::string& location, const std::string& mesg, bool success); | ||
45 | void printTotals(LLSD metadata); | ||
46 | void recordEventDetails(const std::string& location, | ||
47 | const std::string& mesg, | ||
48 | bool success, | ||
49 | LLSD stats); | ||
50 | private: | ||
51 | LLFrameTimer mLastPrintTimer; | ||
52 | LLSD mMetricsMap; | ||
53 | }; | ||
54 | |||
55 | LLMetricsImpl::~LLMetricsImpl() | ||
56 | { | ||
57 | } | ||
58 | |||
59 | void LLMetricsImpl::recordEventDetails(const std::string& location, | ||
60 | const std::string& mesg, | ||
61 | bool success, | ||
62 | LLSD stats) | ||
63 | { | ||
64 | recordEvent(location,mesg,success); | ||
65 | |||
66 | LLSD metrics = LLSD::emptyMap(); | ||
67 | metrics["location"] = location; | ||
68 | metrics["stats"] = stats; | ||
69 | |||
70 | llinfos << "LLMETRICS: " << LLSDOStreamer<LLSDNotationFormatter>(metrics) << llendl; | ||
71 | } | ||
72 | |||
73 | // Store this: | ||
74 | // [ {'location_1':{'mesg_1':{'success':i10, 'fail':i0}, | ||
75 | // 'mesg_2':{'success':i10, 'fail':i0}}, | ||
76 | // {'location_2',{'mesg_3':{'success':i10, 'fail':i0}} ] | ||
77 | void LLMetricsImpl::recordEvent(const std::string& location, const std::string& mesg, bool success) | ||
78 | { | ||
79 | LLSD& stats = mMetricsMap[location][mesg]; | ||
80 | if (success) | ||
81 | { | ||
82 | stats["success"] = stats["success"].asInteger() + 1; | ||
83 | } | ||
84 | else | ||
85 | { | ||
86 | stats["fail"] = stats["fail"].asInteger() + 1; | ||
87 | } | ||
88 | } | ||
89 | |||
90 | // Print this: | ||
91 | // { 'meta': | ||
92 | // { 'elapsed_time':r3600.000 } | ||
93 | // 'stats': | ||
94 | // [ {'location':'location_1', 'mesg':'mesg_1', 'success':i10, 'fail':i0}, | ||
95 | // {'location':'location_1', 'mesg':'mesg_2', 'success':i10, 'fail':i0}, | ||
96 | // {'location':'location_2', 'mesg':'mesg_3', 'success':i10, 'fail':i0} ] } | ||
97 | void LLMetricsImpl::printTotals(LLSD metadata) | ||
98 | { | ||
99 | F32 elapsed_time = mLastPrintTimer.getElapsedTimeAndResetF32(); | ||
100 | metadata["elapsed_time"] = elapsed_time; | ||
101 | |||
102 | LLSD out_sd = LLSD::emptyMap(); | ||
103 | out_sd["meta"] = metadata; | ||
104 | |||
105 | LLSD stats = LLSD::emptyArray(); | ||
106 | |||
107 | LLSD::map_const_iterator loc_it = mMetricsMap.beginMap(); | ||
108 | LLSD::map_const_iterator loc_end = mMetricsMap.endMap(); | ||
109 | for ( ; loc_it != loc_end; ++loc_it) | ||
110 | { | ||
111 | const std::string& location = (*loc_it).first; | ||
112 | |||
113 | const LLSD& loc_map = (*loc_it).second; | ||
114 | LLSD::map_const_iterator mesg_it = loc_map.beginMap(); | ||
115 | LLSD::map_const_iterator mesg_end = loc_map.endMap(); | ||
116 | for ( ; mesg_it != mesg_end; ++mesg_it) | ||
117 | { | ||
118 | const std::string& mesg = (*mesg_it).first; | ||
119 | const LLSD& mesg_map = (*mesg_it).second; | ||
120 | |||
121 | LLSD entry = LLSD::emptyMap(); | ||
122 | entry["location"] = location; | ||
123 | entry["mesg"] = mesg; | ||
124 | entry["success"] = mesg_map["success"]; | ||
125 | entry["fail"] = mesg_map["fail"]; | ||
126 | |||
127 | stats.append(entry); | ||
128 | } | ||
129 | } | ||
130 | |||
131 | out_sd["stats"] = stats; | ||
132 | |||
133 | llinfos << "LLMETRICS: AGGREGATE: " << LLSDOStreamer<LLSDNotationFormatter>(out_sd) << llendl; | ||
134 | } | ||
135 | |||
136 | LLMetrics::LLMetrics() | ||
137 | { | ||
138 | mImpl = new LLMetricsImpl(); | ||
139 | } | ||
140 | |||
141 | LLMetrics::~LLMetrics() | ||
142 | { | ||
143 | delete mImpl; | ||
144 | mImpl = NULL; | ||
145 | } | ||
146 | |||
147 | void LLMetrics::recordEvent(const std::string& location, const std::string& mesg, bool success) | ||
148 | { | ||
149 | if (mImpl) mImpl->recordEvent(location,mesg,success); | ||
150 | } | ||
151 | |||
152 | void LLMetrics::printTotals(LLSD meta) | ||
153 | { | ||
154 | if (mImpl) mImpl->printTotals(meta); | ||
155 | } | ||
156 | |||
157 | |||
158 | void LLMetrics::recordEventDetails(const std::string& location, | ||
159 | const std::string& mesg, | ||
160 | bool success, | ||
161 | LLSD stats) | ||
162 | { | ||
163 | if (mImpl) mImpl->recordEventDetails(location,mesg,success,stats); | ||
164 | } | ||
165 | |||