PageRenderTime 45ms CodeModel.GetById 22ms RepoModel.GetById 0ms 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
Possible License(s): LGPL-2.1
  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. #include "linden_common.h"
  29. #include "llmetrics.h"
  30. #include "llsd.h"
  31. #include "llsdserialize.h"
  32. #include "llframetimer.h"
  33. class LLMetricsImpl
  34. {
  35. public:
  36. LLMetricsImpl() { }
  37. ~LLMetricsImpl();
  38. void recordEvent(const std::string& location, const std::string& mesg, bool success);
  39. void printTotals(LLSD metadata);
  40. void recordEventDetails(const std::string& location,
  41. const std::string& mesg,
  42. bool success,
  43. LLSD stats);
  44. private:
  45. LLFrameTimer mLastPrintTimer;
  46. LLSD mMetricsMap;
  47. };
  48. LLMetricsImpl::~LLMetricsImpl()
  49. {
  50. }
  51. void LLMetricsImpl::recordEventDetails(const std::string& location,
  52. const std::string& mesg,
  53. bool success,
  54. LLSD stats)
  55. {
  56. recordEvent(location,mesg,success);
  57. LLSD metrics = LLSD::emptyMap();
  58. metrics["location"] = location;
  59. metrics["stats"] = stats;
  60. llinfos << "LLMETRICS: " << (LLSDNotationStreamer(metrics)) << llendl;
  61. }
  62. // Store this:
  63. // [ {'location_1':{'mesg_1':{'success':i10, 'fail':i0},
  64. // 'mesg_2':{'success':i10, 'fail':i0}},
  65. // {'location_2',{'mesg_3':{'success':i10, 'fail':i0}} ]
  66. void LLMetricsImpl::recordEvent(const std::string& location, const std::string& mesg, bool success)
  67. {
  68. LLSD& stats = mMetricsMap[location][mesg];
  69. if (success)
  70. {
  71. stats["success"] = stats["success"].asInteger() + 1;
  72. }
  73. else
  74. {
  75. stats["fail"] = stats["fail"].asInteger() + 1;
  76. }
  77. }
  78. // Print this:
  79. // { 'meta':
  80. // { 'elapsed_time':r3600.000 }
  81. // 'stats':
  82. // [ {'location':'location_1', 'mesg':'mesg_1', 'success':i10, 'fail':i0},
  83. // {'location':'location_1', 'mesg':'mesg_2', 'success':i10, 'fail':i0},
  84. // {'location':'location_2', 'mesg':'mesg_3', 'success':i10, 'fail':i0} ] }
  85. void LLMetricsImpl::printTotals(LLSD metadata)
  86. {
  87. F32 elapsed_time = mLastPrintTimer.getElapsedTimeAndResetF32();
  88. metadata["elapsed_time"] = elapsed_time;
  89. LLSD out_sd = LLSD::emptyMap();
  90. out_sd["meta"] = metadata;
  91. LLSD stats = LLSD::emptyArray();
  92. LLSD::map_const_iterator loc_it = mMetricsMap.beginMap();
  93. LLSD::map_const_iterator loc_end = mMetricsMap.endMap();
  94. for ( ; loc_it != loc_end; ++loc_it)
  95. {
  96. const std::string& location = (*loc_it).first;
  97. const LLSD& loc_map = (*loc_it).second;
  98. LLSD::map_const_iterator mesg_it = loc_map.beginMap();
  99. LLSD::map_const_iterator mesg_end = loc_map.endMap();
  100. for ( ; mesg_it != mesg_end; ++mesg_it)
  101. {
  102. const std::string& mesg = (*mesg_it).first;
  103. const LLSD& mesg_map = (*mesg_it).second;
  104. LLSD entry = LLSD::emptyMap();
  105. entry["location"] = location;
  106. entry["mesg"] = mesg;
  107. entry["success"] = mesg_map["success"];
  108. entry["fail"] = mesg_map["fail"];
  109. stats.append(entry);
  110. }
  111. }
  112. out_sd["stats"] = stats;
  113. llinfos << "LLMETRICS: AGGREGATE: " << LLSDOStreamer<LLSDNotationFormatter>(out_sd) << llendl;
  114. }
  115. LLMetrics::LLMetrics()
  116. {
  117. mImpl = new LLMetricsImpl();
  118. }
  119. LLMetrics::~LLMetrics()
  120. {
  121. delete mImpl;
  122. mImpl = NULL;
  123. }
  124. void LLMetrics::recordEvent(const std::string& location, const std::string& mesg, bool success)
  125. {
  126. if (mImpl) mImpl->recordEvent(location,mesg,success);
  127. }
  128. void LLMetrics::printTotals(LLSD meta)
  129. {
  130. if (mImpl) mImpl->printTotals(meta);
  131. }
  132. void LLMetrics::recordEventDetails(const std::string& location,
  133. const std::string& mesg,
  134. bool success,
  135. LLSD stats)
  136. {
  137. if (mImpl) mImpl->recordEventDetails(location,mesg,success,stats);
  138. }