00001
00032 #include "llviewerprecompiledheaders.h"
00033
00034 #include "llfloaterlagmeter.h"
00035
00036 #include "llvieweruictrlfactory.h"
00037 #include "llviewerstats.h"
00038 #include "llviewerimage.h"
00039 #include "llviewercontrol.h"
00040 #include "viewer.h"
00041 #include "lltexturefetch.h"
00042
00043 #include "llbutton.h"
00044 #include "llfocusmgr.h"
00045 #include "lltextbox.h"
00046
00047 const LLString LAG_CRITICAL_IMAGE_NAME = "lag_status_critical.tga";
00048 const LLString LAG_WARNING_IMAGE_NAME = "lag_status_warning.tga";
00049 const LLString LAG_GOOD_IMAGE_NAME = "lag_status_good.tga";
00050
00051 LLFloaterLagMeter * LLFloaterLagMeter::sInstance = NULL;
00052
00053 LLFloaterLagMeter::LLFloaterLagMeter()
00054 : LLFloater("floater_lagmeter")
00055 {
00056 gUICtrlFactory->buildFloater(this, "floater_lagmeter.xml");
00057
00058
00059
00060 setIsChrome(TRUE);
00061
00062 mClientButton = LLUICtrlFactory::getButtonByName(this, "client_lagmeter");
00063 mClientText = LLUICtrlFactory::getTextBoxByName(this, "client_text");
00064 mClientCause = LLUICtrlFactory::getTextBoxByName(this, "client_lag_cause");
00065
00066 mNetworkButton = LLUICtrlFactory::getButtonByName(this, "network_lagmeter");
00067 mNetworkText = LLUICtrlFactory::getTextBoxByName(this, "network_text");
00068 mNetworkCause = LLUICtrlFactory::getTextBoxByName(this, "network_lag_cause");
00069
00070 mServerButton = LLUICtrlFactory::getButtonByName(this, "server_lagmeter");
00071 mServerText = LLUICtrlFactory::getTextBoxByName(this, "server_text");
00072 mServerCause = LLUICtrlFactory::getTextBoxByName(this, "server_lag_cause");
00073
00074 LLString config_string = childGetText("client_frame_rate_critical_fps");
00075 mClientFrameTimeCritical = 1.0f / (float)atof( config_string.c_str() );
00076 config_string = childGetText("client_frame_rate_warning_fps");
00077 mClientFrameTimeWarning = 1.0f / (float)atof( config_string.c_str() );
00078
00079 config_string = childGetText("network_packet_loss_critical_pct");
00080 mNetworkPacketLossCritical = (float)atof( config_string.c_str() );
00081 config_string = childGetText("network_packet_loss_warning_pct");
00082 mNetworkPacketLossWarning = (float)atof( config_string.c_str() );
00083
00084 config_string = childGetText("network_ping_critical_ms");
00085 mNetworkPingCritical = (float)atof( config_string.c_str() );
00086 config_string = childGetText("network_ping_warning_ms");
00087 mNetworkPingWarning = (float)atof( config_string.c_str() );
00088 config_string = childGetText("server_frame_rate_critical_fps");
00089
00090 mServerFrameTimeCritical = 1000.0f / (float)atof( config_string.c_str() );
00091 config_string = childGetText("server_frame_rate_warning_fps");
00092 mServerFrameTimeWarning = 1000.0f / (float)atof( config_string.c_str() );
00093 config_string = childGetText("server_single_process_max_time_ms");
00094 mServerSingleProcessMaxTime = (float)atof( config_string.c_str() );
00095
00096 mShrunk = false;
00097 config_string = childGetText("max_width_px");
00098 mMaxWidth = atoi( config_string.c_str() );
00099 config_string = childGetText("min_width_px");
00100 mMinWidth = atoi( config_string.c_str() );
00101
00102 childSetTextArg("client_frame_time_critical_msg", "[CLIENT_FRAME_RATE_CRITICAL]", childGetText("client_frame_rate_critical_fps"));
00103 childSetTextArg("client_frame_time_warning_msg", "[CLIENT_FRAME_RATE_CRITICAL]", childGetText("client_frame_rate_critical_fps"));
00104 childSetTextArg("client_frame_time_warning_msg", "[CLIENT_FRAME_RATE_WARNING]", childGetText("client_frame_rate_warning_fps"));
00105
00106 childSetTextArg("network_packet_loss_critical_msg", "[NETWORK_PACKET_LOSS_CRITICAL]", childGetText("network_packet_loss_critical_pct"));
00107 childSetTextArg("network_packet_loss_warning_msg", "[NETWORK_PACKET_LOSS_CRITICAL]", childGetText("network_packet_loss_critical_pct"));
00108 childSetTextArg("network_packet_loss_warning_msg", "[NETWORK_PACKET_LOSS_WARNING]", childGetText("network_packet_loss_warning_pct"));
00109
00110 childSetTextArg("network_ping_critical_msg", "[NETWORK_PING_CRITICAL]", childGetText("network_ping_critical_ms"));
00111 childSetTextArg("network_ping_warning_msg", "[NETWORK_PING_CRITICAL]", childGetText("network_ping_critical_ms"));
00112 childSetTextArg("network_ping_warning_msg", "[NETWORK_PING_WARNING]", childGetText("network_ping_warning_ms"));
00113
00114 childSetTextArg("server_frame_time_critical_msg", "[SERVER_FRAME_RATE_CRITICAL]", childGetText("server_frame_rate_critical_fps"));
00115 childSetTextArg("server_frame_time_warning_msg", "[SERVER_FRAME_RATE_CRITICAL]", childGetText("server_frame_rate_critical_fps"));
00116 childSetTextArg("server_frame_time_warning_msg", "[SERVER_FRAME_RATE_WARNING]", childGetText("server_frame_rate_warning_fps"));
00117
00118 childSetAction("minimize", onClickShrink, this);
00119
00120
00121 if (gSavedSettings.getBOOL("LagMeterShrunk"))
00122 {
00123 onClickShrink(this);
00124 }
00125 }
00126
00127 LLFloaterLagMeter::~LLFloaterLagMeter()
00128 {
00129 sInstance = NULL;
00130
00131
00132 gSavedSettings.setBOOL("LagMeterShrunk", mShrunk);
00133
00134 if (mShrunk)
00135 {
00136 onClickShrink(this);
00137 }
00138 }
00139
00140 void LLFloaterLagMeter::draw()
00141 {
00142 determineClient();
00143 determineNetwork();
00144 determineServer();
00145
00146 LLFloater::draw();
00147 }
00148
00149
00150 void LLFloaterLagMeter::show(void *data)
00151 {
00152 if(!sInstance) sInstance = new LLFloaterLagMeter();
00153 sInstance->open();
00154 }
00155
00156 void LLFloaterLagMeter::determineClient()
00157 {
00158 F32 client_frame_time = gViewerStats->mFPSStat.getMeanDuration();
00159 bool find_cause = false;
00160
00161 if (!gFocusMgr.getAppHasFocus())
00162 {
00163 mClientButton->setImageUnselected(LAG_GOOD_IMAGE_NAME);
00164 mClientText->setText( childGetText("client_frame_time_window_bg_msg") );
00165 mClientCause->setText( LLString::null );
00166 }
00167 else if(client_frame_time >= mClientFrameTimeCritical)
00168 {
00169 mClientButton->setImageUnselected(LAG_CRITICAL_IMAGE_NAME);
00170 mClientText->setText( childGetText("client_frame_time_critical_msg") );
00171 find_cause = true;
00172 }
00173 else if(client_frame_time >= mClientFrameTimeWarning)
00174 {
00175 mClientButton->setImageUnselected(LAG_WARNING_IMAGE_NAME);
00176 mClientText->setText( childGetText("client_frame_time_warning_msg") );
00177 find_cause = true;
00178 }
00179 else
00180 {
00181 mClientButton->setImageUnselected(LAG_GOOD_IMAGE_NAME);
00182 mClientText->setText( childGetText("client_frame_time_normal_msg") );
00183 mClientCause->setText( LLString::null );
00184 }
00185
00186 if(find_cause)
00187 {
00188 if(gSavedSettings.getF32("RenderFarClip") > 128)
00189 {
00190 mClientCause->setText( childGetText("client_draw_distance_cause_msg") );
00191 }
00192 else if(gTextureFetch->getNumRequests() > 2)
00193 {
00194 mClientCause->setText( childGetText("client_texture_loading_cause_msg") );
00195 }
00196 else if(LLViewerImage::sBoundTextureMemory > LLViewerImage::sMaxBoundTextureMem)
00197 {
00198 mClientCause->setText( childGetText("client_texture_memory_cause_msg") );
00199 }
00200 else
00201 {
00202 mClientCause->setText( childGetText("client_complex_objects_cause_msg") );
00203 }
00204 }
00205 }
00206
00207 void LLFloaterLagMeter::determineNetwork()
00208 {
00209 F32 packet_loss = gViewerStats->mPacketsLostPercentStat.getMean();
00210 F32 ping_time = gViewerStats->mSimPingStat.getMean();
00211 bool find_cause_loss = false;
00212 bool find_cause_ping = false;
00213
00214 if(packet_loss >= mNetworkPacketLossCritical)
00215 {
00216 mNetworkButton->setImageUnselected(LAG_CRITICAL_IMAGE_NAME);
00217 mNetworkText->setText( childGetText("network_packet_loss_critical_msg") );
00218 find_cause_loss = true;
00219 }
00220 else if(ping_time >= mNetworkPingCritical)
00221 {
00222 mNetworkButton->setImageUnselected(LAG_CRITICAL_IMAGE_NAME);
00223 mNetworkText->setText( childGetText("network_ping_critical_msg") );
00224 find_cause_ping = true;
00225 }
00226 else if(packet_loss >= mNetworkPacketLossWarning)
00227 {
00228 mNetworkButton->setImageUnselected(LAG_WARNING_IMAGE_NAME);
00229 mNetworkText->setText( childGetText("network_packet_loss_warning_msg") );
00230 find_cause_loss = true;
00231 }
00232 else if(ping_time >= mNetworkPingWarning)
00233 {
00234 mNetworkButton->setImageUnselected(LAG_WARNING_IMAGE_NAME);
00235 mNetworkText->setText( childGetText("network_ping_warning_msg") );
00236 find_cause_ping = true;
00237 }
00238 else
00239 {
00240 mNetworkButton->setImageUnselected(LAG_GOOD_IMAGE_NAME);
00241 mNetworkText->setText( childGetText("network_performance_normal_msg") );
00242 }
00243
00244 if(find_cause_loss)
00245 {
00246 mNetworkCause->setText( childGetText("network_packet_loss_cause_msg") );
00247 }
00248 else if(find_cause_ping)
00249 {
00250 mNetworkCause->setText( childGetText("network_ping_cause_msg") );
00251 }
00252 else
00253 {
00254 mNetworkCause->setText( LLString::null );
00255 }
00256 }
00257
00258 void LLFloaterLagMeter::determineServer()
00259 {
00260 F32 sim_frame_time = gViewerStats->mSimFrameMsec.getCurrent();
00261 bool find_cause = false;
00262
00263 if(sim_frame_time >= mServerFrameTimeCritical)
00264 {
00265 mServerButton->setImageUnselected(LAG_CRITICAL_IMAGE_NAME);
00266 mServerText->setText( childGetText("server_frame_time_critical_msg") );
00267 find_cause = true;
00268 }
00269 else if(sim_frame_time >= mServerFrameTimeWarning)
00270 {
00271 mServerButton->setImageUnselected(LAG_WARNING_IMAGE_NAME);
00272 mServerText->setText( childGetText("server_frame_time_warning_msg") );
00273 find_cause = true;
00274 }
00275 else
00276 {
00277 mServerButton->setImageUnselected(LAG_GOOD_IMAGE_NAME);
00278 mServerText->setText( childGetText("server_frame_time_normal_msg") );
00279 mServerCause->setText( LLString::null );
00280 }
00281
00282 if(find_cause)
00283 {
00284 if(gViewerStats->mSimSimPhysicsMsec.getCurrent() > mServerSingleProcessMaxTime)
00285 {
00286 mServerCause->setText( childGetText("server_physics_cause_msg") );
00287 }
00288 else if(gViewerStats->mSimScriptMsec.getCurrent() > mServerSingleProcessMaxTime)
00289 {
00290 mServerCause->setText( childGetText("server_scripts_cause_msg") );
00291 }
00292 else if(gViewerStats->mSimNetMsec.getCurrent() > mServerSingleProcessMaxTime)
00293 {
00294 mServerCause->setText( childGetText("server_net_cause_msg") );
00295 }
00296 else if(gViewerStats->mSimAgentMsec.getCurrent() > mServerSingleProcessMaxTime)
00297 {
00298 mServerCause->setText( childGetText("server_agent_cause_msg") );
00299 }
00300 else if(gViewerStats->mSimImagesMsec.getCurrent() > mServerSingleProcessMaxTime)
00301 {
00302 mServerCause->setText( childGetText("server_images_cause_msg") );
00303 }
00304 else
00305 {
00306 mServerCause->setText( childGetText("server_generic_cause_msg") );
00307 }
00308 }
00309 }
00310
00311
00312 void LLFloaterLagMeter::onClickShrink(void * data)
00313 {
00314 LLFloaterLagMeter * self = (LLFloaterLagMeter*)data;
00315
00316 LLButton * button = (LLButton*)self->getChildByName("minimize");
00317 S32 delta_width = self->mMaxWidth - self->mMinWidth;
00318 LLRect r = self->getRect();
00319 if(self->mShrunk)
00320 {
00321 self->setTitle( self->childGetText("max_title_msg") );
00322
00323 r.translate(-delta_width, 0);
00324 self->setRect(r);
00325 self->reshape(self->mMaxWidth, self->getRect().getHeight());
00326
00327 self->childSetText("client", self->childGetText("client_text_msg") + ":");
00328 self->childSetText("network", self->childGetText("network_text_msg") + ":");
00329 self->childSetText("server", self->childGetText("server_text_msg") + ":");
00330
00331
00332 button->setLabel( self->childGetText("smaller_label") );
00333 }
00334 else
00335 {
00336 self->setTitle( self->childGetText("min_title_msg") );
00337
00338 r.translate(delta_width, 0);
00339 self->setRect(r);
00340 self->reshape(self->mMinWidth, self->getRect().getHeight());
00341
00342 self->childSetText("client", self->childGetText("client_text_msg") );
00343 self->childSetText("network", self->childGetText("network_text_msg") );
00344 self->childSetText("server", self->childGetText("server_text_msg") );
00345
00346
00347 button->setLabel( self->childGetText("bigger_label") );
00348 }
00349
00350 button->setFocus(FALSE);
00351
00352 self->mClientText->setVisible(self->mShrunk);
00353 self->mClientCause->setVisible(self->mShrunk);
00354 self->childSetVisible("client_help", self->mShrunk);
00355
00356 self->mNetworkText->setVisible(self->mShrunk);
00357 self->mNetworkCause->setVisible(self->mShrunk);
00358 self->childSetVisible("network_help", self->mShrunk);
00359
00360 self->mServerText->setVisible(self->mShrunk);
00361 self->mServerCause->setVisible(self->mShrunk);
00362 self->childSetVisible("server_help", self->mShrunk);
00363
00364 self->mShrunk = !self->mShrunk;
00365 }