00001
00034 #include "linden_common.h"
00035 #include "llmetrics.h"
00036
00037 #include "llsd.h"
00038 #include "llsdserialize.h"
00039 #include "llframetimer.h"
00040
00041 class LLMetricsImpl
00042 {
00043 public:
00044 LLMetricsImpl() { }
00045 ~LLMetricsImpl();
00046
00047 void recordEvent(const std::string& location, const std::string& mesg, bool success);
00048 void printTotals(LLSD metadata);
00049 void recordEventDetails(const std::string& location,
00050 const std::string& mesg,
00051 bool success,
00052 LLSD stats);
00053 private:
00054 LLFrameTimer mLastPrintTimer;
00055 LLSD mMetricsMap;
00056 };
00057
00058 LLMetricsImpl::~LLMetricsImpl()
00059 {
00060 }
00061
00062 void LLMetricsImpl::recordEventDetails(const std::string& location,
00063 const std::string& mesg,
00064 bool success,
00065 LLSD stats)
00066 {
00067 recordEvent(location,mesg,success);
00068
00069 LLSD metrics = LLSD::emptyMap();
00070 metrics["location"] = location;
00071 metrics["stats"] = stats;
00072
00073 llinfos << "LLMETRICS: " << LLSDNotationStreamer(metrics) << llendl;
00074 }
00075
00076
00077
00078
00079
00080 void LLMetricsImpl::recordEvent(const std::string& location, const std::string& mesg, bool success)
00081 {
00082 LLSD& stats = mMetricsMap[location][mesg];
00083 if (success)
00084 {
00085 stats["success"] = stats["success"].asInteger() + 1;
00086 }
00087 else
00088 {
00089 stats["fail"] = stats["fail"].asInteger() + 1;
00090 }
00091 }
00092
00093
00094
00095
00096
00097
00098
00099
00100 void LLMetricsImpl::printTotals(LLSD metadata)
00101 {
00102 F32 elapsed_time = mLastPrintTimer.getElapsedTimeAndResetF32();
00103 metadata["elapsed_time"] = elapsed_time;
00104
00105 LLSD out_sd = LLSD::emptyMap();
00106 out_sd["meta"] = metadata;
00107
00108 LLSD stats = LLSD::emptyArray();
00109
00110 LLSD::map_const_iterator loc_it = mMetricsMap.beginMap();
00111 LLSD::map_const_iterator loc_end = mMetricsMap.endMap();
00112 for ( ; loc_it != loc_end; ++loc_it)
00113 {
00114 const std::string& location = (*loc_it).first;
00115
00116 const LLSD& loc_map = (*loc_it).second;
00117 LLSD::map_const_iterator mesg_it = loc_map.beginMap();
00118 LLSD::map_const_iterator mesg_end = loc_map.endMap();
00119 for ( ; mesg_it != mesg_end; ++mesg_it)
00120 {
00121 const std::string& mesg = (*mesg_it).first;
00122 const LLSD& mesg_map = (*mesg_it).second;
00123
00124 LLSD entry = LLSD::emptyMap();
00125 entry["location"] = location;
00126 entry["mesg"] = mesg;
00127 entry["success"] = mesg_map["success"];
00128 entry["fail"] = mesg_map["fail"];
00129
00130 stats.append(entry);
00131 }
00132 }
00133
00134 out_sd["stats"] = stats;
00135
00136 llinfos << "LLMETRICS: AGGREGATE: " << LLSDOStreamer<LLSDNotationFormatter>(out_sd) << llendl;
00137 }
00138
00139 LLMetrics::LLMetrics()
00140 {
00141 mImpl = new LLMetricsImpl();
00142 }
00143
00144 LLMetrics::~LLMetrics()
00145 {
00146 delete mImpl;
00147 mImpl = NULL;
00148 }
00149
00150 void LLMetrics::recordEvent(const std::string& location, const std::string& mesg, bool success)
00151 {
00152 if (mImpl) mImpl->recordEvent(location,mesg,success);
00153 }
00154
00155 void LLMetrics::printTotals(LLSD meta)
00156 {
00157 if (mImpl) mImpl->printTotals(meta);
00158 }
00159
00160
00161 void LLMetrics::recordEventDetails(const std::string& location,
00162 const std::string& mesg,
00163 bool success,
00164 LLSD stats)
00165 {
00166 if (mImpl) mImpl->recordEventDetails(location,mesg,success,stats);
00167 }
00168