PageRenderTime 51ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/lltextureinfo.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 284 lines | 229 code | 30 blank | 25 comment | 19 complexity | 6993341b218cc6b304ac8853bf844d18 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file lltextureinfo.cpp
  3. * @brief Object which handles local texture info
  4. *
  5. * $LicenseInfo:firstyear=2000&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. #include "llviewerprecompiledheaders.h"
  27. #include "lltextureinfo.h"
  28. #include "lltexturestats.h"
  29. #include "llviewercontrol.h"
  30. LLTextureInfo::LLTextureInfo() :
  31. mLogTextureDownloadsToViewerLog(false),
  32. mLogTextureDownloadsToSimulator(false),
  33. mTotalBytes(0),
  34. mTotalMilliseconds(0),
  35. mTextureDownloadsStarted(0),
  36. mTextureDownloadsCompleted(0),
  37. mTextureDownloadProtocol("NONE"),
  38. mTextureLogThreshold(100 * 1024),
  39. mCurrentStatsBundleStartTime(0)
  40. {
  41. mTextures.clear();
  42. }
  43. void LLTextureInfo::setUpLogging(bool writeToViewerLog, bool sendToSim, U32 textureLogThreshold)
  44. {
  45. mLogTextureDownloadsToViewerLog = writeToViewerLog;
  46. mLogTextureDownloadsToSimulator = sendToSim;
  47. mTextureLogThreshold = textureLogThreshold;
  48. }
  49. LLTextureInfo::~LLTextureInfo()
  50. {
  51. std::map<LLUUID, LLTextureInfoDetails *>::iterator iterator;
  52. for (iterator = mTextures.begin(); iterator != mTextures.end(); iterator++)
  53. {
  54. LLTextureInfoDetails *info = (*iterator).second;
  55. delete info;
  56. }
  57. mTextures.clear();
  58. }
  59. void LLTextureInfo::addRequest(const LLUUID& id)
  60. {
  61. LLTextureInfoDetails *info = new LLTextureInfoDetails();
  62. mTextures[id] = info;
  63. }
  64. U32 LLTextureInfo::getTextureInfoMapSize()
  65. {
  66. return mTextures.size();
  67. }
  68. bool LLTextureInfo::has(const LLUUID& id)
  69. {
  70. std::map<LLUUID, LLTextureInfoDetails *>::iterator iterator = mTextures.find(id);
  71. if (iterator == mTextures.end())
  72. {
  73. return false;
  74. }
  75. else
  76. {
  77. return true;
  78. }
  79. }
  80. void LLTextureInfo::setRequestStartTime(const LLUUID& id, U64 startTime)
  81. {
  82. if (!has(id))
  83. {
  84. addRequest(id);
  85. }
  86. mTextures[id]->mStartTime = startTime;
  87. mTextureDownloadsStarted++;
  88. }
  89. void LLTextureInfo::setRequestSize(const LLUUID& id, U32 size)
  90. {
  91. if (!has(id))
  92. {
  93. addRequest(id);
  94. }
  95. mTextures[id]->mSize = size;
  96. }
  97. void LLTextureInfo::setRequestOffset(const LLUUID& id, U32 offset)
  98. {
  99. if (!has(id))
  100. {
  101. addRequest(id);
  102. }
  103. mTextures[id]->mOffset = offset;
  104. }
  105. void LLTextureInfo::setRequestType(const LLUUID& id, LLTextureInfoDetails::LLRequestType type)
  106. {
  107. if (!has(id))
  108. {
  109. addRequest(id);
  110. }
  111. mTextures[id]->mType = type;
  112. }
  113. void LLTextureInfo::setRequestCompleteTimeAndLog(const LLUUID& id, U64 completeTime)
  114. {
  115. if (!has(id))
  116. {
  117. addRequest(id);
  118. }
  119. mTextures[id]->mCompleteTime = completeTime;
  120. std::string protocol = "NONE";
  121. switch(mTextures[id]->mType)
  122. {
  123. case LLTextureInfoDetails::REQUEST_TYPE_HTTP:
  124. protocol = "HTTP";
  125. break;
  126. case LLTextureInfoDetails::REQUEST_TYPE_UDP:
  127. protocol = "UDP";
  128. break;
  129. case LLTextureInfoDetails::REQUEST_TYPE_NONE:
  130. default:
  131. break;
  132. }
  133. if (mLogTextureDownloadsToViewerLog)
  134. {
  135. llinfos << "texture=" << id
  136. << " start=" << mTextures[id]->mStartTime
  137. << " end=" << mTextures[id]->mCompleteTime
  138. << " size=" << mTextures[id]->mSize
  139. << " offset=" << mTextures[id]->mOffset
  140. << " length_in_ms=" << (mTextures[id]->mCompleteTime - mTextures[id]->mStartTime) / 1000
  141. << " protocol=" << protocol
  142. << llendl;
  143. }
  144. if(mLogTextureDownloadsToSimulator)
  145. {
  146. S32 texture_stats_upload_threshold = mTextureLogThreshold;
  147. mTotalBytes += mTextures[id]->mSize;
  148. mTotalMilliseconds += mTextures[id]->mCompleteTime - mTextures[id]->mStartTime;
  149. mTextureDownloadsCompleted++;
  150. mTextureDownloadProtocol = protocol;
  151. if (mTotalBytes >= texture_stats_upload_threshold)
  152. {
  153. LLSD texture_data;
  154. std::stringstream startTime;
  155. startTime << mCurrentStatsBundleStartTime;
  156. texture_data["start_time"] = startTime.str();
  157. std::stringstream endTime;
  158. endTime << completeTime;
  159. texture_data["end_time"] = endTime.str();
  160. texture_data["averages"] = getAverages();
  161. send_texture_stats_to_sim(texture_data);
  162. resetTextureStatistics();
  163. }
  164. }
  165. mTextures.erase(id);
  166. }
  167. LLSD LLTextureInfo::getAverages()
  168. {
  169. LLSD averagedTextureData;
  170. S32 averageDownloadRate;
  171. if(mTotalMilliseconds == 0)
  172. {
  173. averageDownloadRate = 0;
  174. }
  175. else
  176. {
  177. averageDownloadRate = (mTotalBytes * 8) / mTotalMilliseconds;
  178. }
  179. averagedTextureData["bits_per_second"] = averageDownloadRate;
  180. averagedTextureData["bytes_downloaded"] = mTotalBytes;
  181. averagedTextureData["texture_downloads_started"] = mTextureDownloadsStarted;
  182. averagedTextureData["texture_downloads_completed"] = mTextureDownloadsCompleted;
  183. averagedTextureData["transport"] = mTextureDownloadProtocol;
  184. return averagedTextureData;
  185. }
  186. void LLTextureInfo::resetTextureStatistics()
  187. {
  188. mTotalMilliseconds = 0;
  189. mTotalBytes = 0;
  190. mTextureDownloadsStarted = 0;
  191. mTextureDownloadsCompleted = 0;
  192. mTextureDownloadProtocol = "NONE";
  193. mCurrentStatsBundleStartTime = LLTimer::getTotalTime();
  194. }
  195. U32 LLTextureInfo::getRequestStartTime(const LLUUID& id)
  196. {
  197. if (!has(id))
  198. {
  199. return 0;
  200. }
  201. else
  202. {
  203. std::map<LLUUID, LLTextureInfoDetails *>::iterator iterator = mTextures.find(id);
  204. return (*iterator).second->mStartTime;
  205. }
  206. }
  207. U32 LLTextureInfo::getRequestSize(const LLUUID& id)
  208. {
  209. if (!has(id))
  210. {
  211. return 0;
  212. }
  213. else
  214. {
  215. std::map<LLUUID, LLTextureInfoDetails *>::iterator iterator = mTextures.find(id);
  216. return (*iterator).second->mSize;
  217. }
  218. }
  219. U32 LLTextureInfo::getRequestOffset(const LLUUID& id)
  220. {
  221. if (!has(id))
  222. {
  223. return 0;
  224. }
  225. else
  226. {
  227. std::map<LLUUID, LLTextureInfoDetails *>::iterator iterator = mTextures.find(id);
  228. return (*iterator).second->mOffset;
  229. }
  230. }
  231. LLTextureInfoDetails::LLRequestType LLTextureInfo::getRequestType(const LLUUID& id)
  232. {
  233. if (!has(id))
  234. {
  235. return LLTextureInfoDetails::REQUEST_TYPE_NONE;
  236. }
  237. else
  238. {
  239. std::map<LLUUID, LLTextureInfoDetails *>::iterator iterator = mTextures.find(id);
  240. return (*iterator).second->mType;
  241. }
  242. }
  243. U32 LLTextureInfo::getRequestCompleteTime(const LLUUID& id)
  244. {
  245. if (!has(id))
  246. {
  247. return 0;
  248. }
  249. else
  250. {
  251. std::map<LLUUID, LLTextureInfoDetails *>::iterator iterator = mTextures.find(id);
  252. return (*iterator).second->mCompleteTime;
  253. }
  254. }