llfloaterlagmeter.cpp
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:13k
源码类别:

游戏引擎

开发平台:

C++ Builder

  1. /** 
  2.  * @file llfloaterlagmeter.cpp
  3.  * @brief The "Lag-o-Meter" floater used to tell users what is causing lag.
  4.  *
  5.  * $LicenseInfo:firstyear=2007&license=viewergpl$
  6.  * 
  7.  * Copyright (c) 2007-2010, 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://secondlifegrid.net/programs/open_source/licensing/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
  21.  * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22.  * 
  23.  * By copying, modifying or distributing this software, you acknowledge
  24.  * that you have read and understood your obligations described above,
  25.  * and agree to abide by those obligations.
  26.  * 
  27.  * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28.  * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29.  * COMPLETENESS OR PERFORMANCE.
  30.  * $/LicenseInfo$
  31.  */
  32. #include "llviewerprecompiledheaders.h"
  33. #include "llfloaterlagmeter.h"
  34. #include "lluictrlfactory.h"
  35. #include "llviewerstats.h"
  36. #include "llviewertexture.h"
  37. #include "llviewercontrol.h"
  38. #include "llappviewer.h"
  39. #include "lltexturefetch.h"
  40. #include "llbutton.h"
  41. #include "llfocusmgr.h"
  42. #include "lltextbox.h"
  43. const std::string LAG_CRITICAL_IMAGE_NAME = "lag_status_critical.tga";
  44. const std::string LAG_WARNING_IMAGE_NAME  = "lag_status_warning.tga";
  45. const std::string LAG_GOOD_IMAGE_NAME     = "lag_status_good.tga";
  46. LLFloaterLagMeter::LLFloaterLagMeter(const LLSD& key)
  47. : LLFloater(key)
  48. {
  49. // LLUICtrlFactory::getInstance()->buildFloater(this, "floater_lagmeter.xml");
  50. mCommitCallbackRegistrar.add("LagMeter.ClickShrink",  boost::bind(&LLFloaterLagMeter::onClickShrink, this));
  51. }
  52. BOOL LLFloaterLagMeter::postBuild()
  53. {
  54. // Don't let this window take keyboard focus -- it's confusing to
  55. // lose arrow-key driving when testing lag.
  56. setIsChrome(TRUE);
  57. // were we shrunk last time?
  58. if (gSavedSettings.getBOOL("LagMeterShrunk"))
  59. {
  60. onClickShrink();
  61. }
  62. mClientButton = getChild<LLButton>("client_lagmeter");
  63. mClientText = getChild<LLTextBox>("client_text");
  64. mClientCause = getChild<LLTextBox>("client_lag_cause");
  65. mNetworkButton = getChild<LLButton>("network_lagmeter");
  66. mNetworkText = getChild<LLTextBox>("network_text");
  67. mNetworkCause = getChild<LLTextBox>("network_lag_cause");
  68. mServerButton = getChild<LLButton>("server_lagmeter");
  69. mServerText = getChild<LLTextBox>("server_text");
  70. mServerCause = getChild<LLTextBox>("server_lag_cause");
  71. std::string config_string = getString("client_frame_rate_critical_fps", mStringArgs);
  72. mClientFrameTimeCritical = 1.0f / (float)atof( config_string.c_str() );
  73. config_string = getString("client_frame_rate_warning_fps", mStringArgs);
  74. mClientFrameTimeWarning = 1.0f / (float)atof( config_string.c_str() );
  75. config_string = getString("network_packet_loss_critical_pct", mStringArgs);
  76. mNetworkPacketLossCritical = (float)atof( config_string.c_str() );
  77. config_string = getString("network_packet_loss_warning_pct", mStringArgs);
  78. mNetworkPacketLossWarning = (float)atof( config_string.c_str() );
  79. config_string = getString("network_ping_critical_ms", mStringArgs);
  80. mNetworkPingCritical = (float)atof( config_string.c_str() );
  81. config_string = getString("network_ping_warning_ms", mStringArgs);
  82. mNetworkPingWarning = (float)atof( config_string.c_str() );
  83. config_string = getString("server_frame_rate_critical_fps", mStringArgs);
  84. mServerFrameTimeCritical = 1000.0f / (float)atof( config_string.c_str() );
  85. config_string = getString("server_frame_rate_warning_fps", mStringArgs);
  86. mServerFrameTimeWarning = 1000.0f / (float)atof( config_string.c_str() );
  87. config_string = getString("server_single_process_max_time_ms", mStringArgs);
  88. mServerSingleProcessMaxTime = (float)atof( config_string.c_str() );
  89. // mShrunk = false;
  90. config_string = getString("max_width_px", mStringArgs);
  91. mMaxWidth = atoi( config_string.c_str() );
  92. config_string = getString("min_width_px", mStringArgs);
  93. mMinWidth = atoi( config_string.c_str() );
  94. mStringArgs["[CLIENT_FRAME_RATE_CRITICAL]"] = getString("client_frame_rate_critical_fps");
  95. mStringArgs["[CLIENT_FRAME_RATE_WARNING]"] = getString("client_frame_rate_warning_fps");
  96. mStringArgs["[NETWORK_PACKET_LOSS_CRITICAL]"] = getString("network_packet_loss_critical_pct");
  97. mStringArgs["[NETWORK_PACKET_LOSS_WARNING]"] = getString("network_packet_loss_warning_pct");
  98. mStringArgs["[NETWORK_PING_CRITICAL]"] = getString("network_ping_critical_ms");
  99. mStringArgs["[NETWORK_PING_WARNING]"] = getString("network_ping_warning_ms");
  100. mStringArgs["[SERVER_FRAME_RATE_CRITICAL]"] = getString("server_frame_rate_critical_fps");
  101. mStringArgs["[SERVER_FRAME_RATE_WARNING]"] = getString("server_frame_rate_warning_fps");
  102. // childSetAction("minimize", onClickShrink, this);
  103. return TRUE;
  104. }
  105. LLFloaterLagMeter::~LLFloaterLagMeter()
  106. {
  107. // save shrunk status for next time
  108. // gSavedSettings.setBOOL("LagMeterShrunk", mShrunk);
  109. // expand so we save the large window rectangle
  110. if (gSavedSettings.getBOOL("LagMeterShrunk"))
  111. {
  112. onClickShrink();
  113. }
  114. }
  115. void LLFloaterLagMeter::draw()
  116. {
  117. determineClient();
  118. determineNetwork();
  119. determineServer();
  120. LLFloater::draw();
  121. }
  122. void LLFloaterLagMeter::determineClient()
  123. {
  124. F32 client_frame_time = LLViewerStats::getInstance()->mFPSStat.getMeanDuration();
  125. bool find_cause = false;
  126. if (!gFocusMgr.getAppHasFocus())
  127. {
  128. mClientButton->setImageUnselected(LLUI::getUIImage(LAG_GOOD_IMAGE_NAME));
  129. mClientText->setText( getString("client_frame_time_window_bg_msg", mStringArgs) );
  130. mClientCause->setText( LLStringUtil::null );
  131. }
  132. else if(client_frame_time >= mClientFrameTimeCritical)
  133. {
  134. mClientButton->setImageUnselected(LLUI::getUIImage(LAG_CRITICAL_IMAGE_NAME));
  135. mClientText->setText( getString("client_frame_time_critical_msg", mStringArgs) );
  136. find_cause = true;
  137. }
  138. else if(client_frame_time >= mClientFrameTimeWarning)
  139. {
  140. mClientButton->setImageUnselected(LLUI::getUIImage(LAG_WARNING_IMAGE_NAME));
  141. mClientText->setText( getString("client_frame_time_warning_msg", mStringArgs) );
  142. find_cause = true;
  143. }
  144. else
  145. {
  146. mClientButton->setImageUnselected(LLUI::getUIImage(LAG_GOOD_IMAGE_NAME));
  147. mClientText->setText( getString("client_frame_time_normal_msg", mStringArgs) );
  148. mClientCause->setText( LLStringUtil::null );
  149. }
  150. if(find_cause)
  151. {
  152. if(gSavedSettings.getF32("RenderFarClip") > 128)
  153. {
  154. mClientCause->setText( getString("client_draw_distance_cause_msg", mStringArgs) );
  155. }
  156. else if(LLAppViewer::instance()->getTextureFetch()->getNumRequests() > 2)
  157. {
  158. mClientCause->setText( getString("client_texture_loading_cause_msg", mStringArgs) );
  159. }
  160. else if((BYTES_TO_MEGA_BYTES(LLViewerTexture::sBoundTextureMemoryInBytes)) > LLViewerTexture::sMaxBoundTextureMemInMegaBytes)
  161. {
  162. mClientCause->setText( getString("client_texture_memory_cause_msg", mStringArgs) );
  163. }
  164. else 
  165. {
  166. mClientCause->setText( getString("client_complex_objects_cause_msg", mStringArgs) );
  167. }
  168. }
  169. }
  170. void LLFloaterLagMeter::determineNetwork()
  171. {
  172. F32 packet_loss = LLViewerStats::getInstance()->mPacketsLostPercentStat.getMean();
  173. F32 ping_time = LLViewerStats::getInstance()->mSimPingStat.getMean();
  174. bool find_cause_loss = false;
  175. bool find_cause_ping = false;
  176. // *FIXME: We can't blame a large ping time on anything in
  177. // particular if the frame rate is low, because a low frame
  178. // rate is a sure recipe for crappy ping times right now until
  179. // the network handlers are de-synched from the rendering.
  180. F32 client_frame_time_ms = 1000.0f * LLViewerStats::getInstance()->mFPSStat.getMeanDuration();
  181. if(packet_loss >= mNetworkPacketLossCritical)
  182. {
  183. mNetworkButton->setImageUnselected(LLUI::getUIImage(LAG_CRITICAL_IMAGE_NAME));
  184. mNetworkText->setText( getString("network_packet_loss_critical_msg", mStringArgs) );
  185. find_cause_loss = true;
  186. }
  187. else if(ping_time >= mNetworkPingCritical)
  188. {
  189. mNetworkButton->setImageUnselected(LLUI::getUIImage(LAG_CRITICAL_IMAGE_NAME));
  190. if (client_frame_time_ms < mNetworkPingCritical)
  191. {
  192. mNetworkText->setText( getString("network_ping_critical_msg", mStringArgs) );
  193. find_cause_ping = true;
  194. }
  195. }
  196. else if(packet_loss >= mNetworkPacketLossWarning)
  197. {
  198. mNetworkButton->setImageUnselected(LLUI::getUIImage(LAG_WARNING_IMAGE_NAME));
  199. mNetworkText->setText( getString("network_packet_loss_warning_msg", mStringArgs) );
  200. find_cause_loss = true;
  201. }
  202. else if(ping_time >= mNetworkPingWarning)
  203. {
  204. mNetworkButton->setImageUnselected(LLUI::getUIImage(LAG_WARNING_IMAGE_NAME));
  205. if (client_frame_time_ms < mNetworkPingWarning)
  206. {
  207. mNetworkText->setText( getString("network_ping_warning_msg", mStringArgs) );
  208. find_cause_ping = true;
  209. }
  210. }
  211. else
  212. {
  213. mNetworkButton->setImageUnselected(LLUI::getUIImage(LAG_GOOD_IMAGE_NAME));
  214. mNetworkText->setText( getString("network_performance_normal_msg", mStringArgs) );
  215. }
  216. if(find_cause_loss)
  217.   {
  218. mNetworkCause->setText( getString("network_packet_loss_cause_msg", mStringArgs) );
  219.   }
  220. else if(find_cause_ping)
  221. {
  222. mNetworkCause->setText( getString("network_ping_cause_msg", mStringArgs) );
  223. }
  224. else
  225. {
  226. mNetworkCause->setText( LLStringUtil::null );
  227. }
  228. }
  229. void LLFloaterLagMeter::determineServer()
  230. {
  231. F32 sim_frame_time = LLViewerStats::getInstance()->mSimFrameMsec.getCurrent();
  232. bool find_cause = false;
  233. if(sim_frame_time >= mServerFrameTimeCritical)
  234. {
  235. mServerButton->setImageUnselected(LLUI::getUIImage(LAG_CRITICAL_IMAGE_NAME));
  236. mServerText->setText( getString("server_frame_time_critical_msg", mStringArgs) );
  237. find_cause = true;
  238. }
  239. else if(sim_frame_time >= mServerFrameTimeWarning)
  240. {
  241. mServerButton->setImageUnselected(LLUI::getUIImage(LAG_WARNING_IMAGE_NAME));
  242. mServerText->setText( getString("server_frame_time_warning_msg", mStringArgs) );
  243. find_cause = true;
  244. }
  245. else
  246. {
  247. mServerButton->setImageUnselected(LLUI::getUIImage(LAG_GOOD_IMAGE_NAME));
  248. mServerText->setText( getString("server_frame_time_normal_msg", mStringArgs) );
  249. mServerCause->setText( LLStringUtil::null );
  250. }
  251. if(find_cause)
  252. {
  253. if(LLViewerStats::getInstance()->mSimSimPhysicsMsec.getCurrent() > mServerSingleProcessMaxTime)
  254. {
  255. mServerCause->setText( getString("server_physics_cause_msg", mStringArgs) );
  256. }
  257. else if(LLViewerStats::getInstance()->mSimScriptMsec.getCurrent() > mServerSingleProcessMaxTime)
  258. {
  259. mServerCause->setText( getString("server_scripts_cause_msg", mStringArgs) );
  260. }
  261. else if(LLViewerStats::getInstance()->mSimNetMsec.getCurrent() > mServerSingleProcessMaxTime)
  262. {
  263. mServerCause->setText( getString("server_net_cause_msg", mStringArgs) );
  264. }
  265. else if(LLViewerStats::getInstance()->mSimAgentMsec.getCurrent() > mServerSingleProcessMaxTime)
  266. {
  267. mServerCause->setText( getString("server_agent_cause_msg", mStringArgs) );
  268. }
  269. else if(LLViewerStats::getInstance()->mSimImagesMsec.getCurrent() > mServerSingleProcessMaxTime)
  270. {
  271. mServerCause->setText( getString("server_images_cause_msg", mStringArgs) );
  272. }
  273. else
  274. {
  275. mServerCause->setText( getString("server_generic_cause_msg", mStringArgs) );
  276. }
  277. }
  278. }
  279. void LLFloaterLagMeter::onClickShrink()  // toggle "LagMeterShrunk"
  280. {
  281. // LLFloaterLagMeter * self = (LLFloaterLagMeter*)data;
  282. LLButton * button = getChild<LLButton>("minimize");
  283. S32 delta_width = mMaxWidth -mMinWidth;
  284. LLRect r = getRect();
  285. bool shrunk = gSavedSettings.getBOOL("LagMeterShrunk");
  286. if(shrunk)
  287. {
  288. setTitle(getString("max_title_msg", mStringArgs) );
  289. // make left edge appear to expand
  290. r.translate(-delta_width, 0);
  291. setRect(r);
  292. reshape(mMaxWidth, getRect().getHeight());
  293. childSetText("client", getString("client_text_msg", mStringArgs) + ":");
  294. childSetText("network", getString("network_text_msg",mStringArgs) + ":");
  295. childSetText("server", getString("server_text_msg", mStringArgs) + ":");
  296. // usually "<<"
  297. button->setLabel( getString("smaller_label", mStringArgs) );
  298. }
  299. else
  300. {
  301. setTitle( getString("min_title_msg", mStringArgs) );
  302. // make left edge appear to collapse
  303. r.translate(delta_width, 0);
  304. setRect(r);
  305. reshape(mMinWidth, getRect().getHeight());
  306. childSetText("client", getString("client_text_msg", mStringArgs) );
  307. childSetText("network",getString("network_text_msg",mStringArgs) );
  308. childSetText("server", getString("server_text_msg", mStringArgs) );
  309. // usually ">>"
  310. button->setLabel( getString("bigger_label", mStringArgs) );
  311. }
  312. // Don't put keyboard focus on the button
  313. button->setFocus(FALSE);
  314. // self->mClientText->setVisible(self->mShrunk);
  315. // self->mClientCause->setVisible(self->mShrunk);
  316. // self->childSetVisible("client_help", self->mShrunk);
  317. // self->mNetworkText->setVisible(self->mShrunk);
  318. // self->mNetworkCause->setVisible(self->mShrunk);
  319. // self->childSetVisible("network_help", self->mShrunk);
  320. // self->mServerText->setVisible(self->mShrunk);
  321. // self->mServerCause->setVisible(self->mShrunk);
  322. // self->childSetVisible("server_help", self->mShrunk);
  323. // self->mShrunk = !self->mShrunk;
  324. gSavedSettings.setBOOL("LagMeterShrunk", !gSavedSettings.getBOOL("LagMeterShrunk"));
  325. }