aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llfloaterlagmeter.cpp
blob: 35e679d85f8b67e5468969d0848605113ea59c6e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
/** 
 * @file llfloaterlagmeter.cpp
 * @brief The "Lag-o-Meter" floater used to tell users what is causing lag.
 *
 * $LicenseInfo:firstyear=2007&license=viewergpl$
 * 
 * Copyright (c) 2007-2008, Linden Research, Inc.
 * 
 * Second Life Viewer Source Code
 * The source code in this file ("Source Code") is provided by Linden Lab
 * to you under the terms of the GNU General Public License, version 2.0
 * ("GPL"), unless you have obtained a separate licensing agreement
 * ("Other License"), formally executed by you and Linden Lab.  Terms of
 * the GPL can be found in doc/GPL-license.txt in this distribution, or
 * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
 * 
 * There are special exceptions to the terms and conditions of the GPL as
 * it is applied to this Source Code. View the full text of the exception
 * in the file doc/FLOSS-exception.txt in this software distribution, or
 * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception
 * 
 * By copying, modifying or distributing this software, you acknowledge
 * that you have read and understood your obligations described above,
 * and agree to abide by those obligations.
 * 
 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
 * COMPLETENESS OR PERFORMANCE.
 * $/LicenseInfo$
 */

#include "llviewerprecompiledheaders.h"

#include "llfloaterlagmeter.h"

#include "lluictrlfactory.h"
#include "llviewerstats.h"
#include "llviewerimage.h"
#include "llviewercontrol.h"
#include "llappviewer.h"

#include "lltexturefetch.h"

#include "llbutton.h"
#include "llfocusmgr.h"
#include "lltextbox.h"

const std::string LAG_CRITICAL_IMAGE_NAME = "lag_status_critical.tga";
const std::string LAG_WARNING_IMAGE_NAME  = "lag_status_warning.tga";
const std::string LAG_GOOD_IMAGE_NAME     = "lag_status_good.tga";

LLFloaterLagMeter::LLFloaterLagMeter(const LLSD& key)
	:	LLFloater(std::string("floater_lagmeter"))
{
	LLUICtrlFactory::getInstance()->buildFloater(this, "floater_lagmeter.xml");

	// Don't let this window take keyboard focus -- it's confusing to
	// lose arrow-key driving when testing lag.
	setIsChrome(TRUE);

	mClientButton = getChild<LLButton>("client_lagmeter");
	mClientText = getChild<LLTextBox>("client_text");
	mClientCause = getChild<LLTextBox>("client_lag_cause");

	mNetworkButton = getChild<LLButton>("network_lagmeter");
	mNetworkText = getChild<LLTextBox>("network_text");
	mNetworkCause = getChild<LLTextBox>("network_lag_cause");

	mServerButton = getChild<LLButton>("server_lagmeter");
	mServerText = getChild<LLTextBox>("server_text");
	mServerCause = getChild<LLTextBox>("server_lag_cause");

	std::string config_string = getString("client_frame_rate_critical_fps", mStringArgs);
	mClientFrameTimeCritical = 1.0f / (float)atof( config_string.c_str() );
	config_string = getString("client_frame_rate_warning_fps", mStringArgs);
	mClientFrameTimeWarning = 1.0f / (float)atof( config_string.c_str() );

	config_string = getString("network_packet_loss_critical_pct", mStringArgs);
	mNetworkPacketLossCritical = (float)atof( config_string.c_str() );
	config_string = getString("network_packet_loss_warning_pct", mStringArgs);
	mNetworkPacketLossWarning = (float)atof( config_string.c_str() );

	config_string = getString("network_ping_critical_ms", mStringArgs);
	mNetworkPingCritical = (float)atof( config_string.c_str() );
	config_string = getString("network_ping_warning_ms", mStringArgs);
	mNetworkPingWarning = (float)atof( config_string.c_str() );
	config_string = getString("server_frame_rate_critical_fps", mStringArgs);

	mServerFrameTimeCritical = 1000.0f / (float)atof( config_string.c_str() );
	config_string = getString("server_frame_rate_warning_fps", mStringArgs);
	mServerFrameTimeWarning = 1000.0f / (float)atof( config_string.c_str() );
	config_string = getString("server_single_process_max_time_ms", mStringArgs);
	mServerSingleProcessMaxTime = (float)atof( config_string.c_str() );

	mShrunk = false;
	config_string = getString("max_width_px", mStringArgs);
	mMaxWidth = atoi( config_string.c_str() );
	config_string = getString("min_width_px", mStringArgs);
	mMinWidth = atoi( config_string.c_str() );

	mStringArgs["[CLIENT_FRAME_RATE_CRITICAL]"] = getString("client_frame_rate_critical_fps");
	mStringArgs["[CLIENT_FRAME_RATE_CRITICAL]"] = getString("client_frame_rate_critical_fps");
	mStringArgs["[CLIENT_FRAME_RATE_WARNING]"] = getString("client_frame_rate_warning_fps");

	mStringArgs["[NETWORK_PACKET_LOSS_CRITICAL]"] = getString("network_packet_loss_critical_pct");
	mStringArgs["[NETWORK_PACKET_LOSS_CRITICAL]"] = getString("network_packet_loss_critical_pct");
	mStringArgs["[NETWORK_PACKET_LOSS_WARNING]"] = getString("network_packet_loss_warning_pct");

	mStringArgs["[NETWORK_PING_CRITICAL]"] = getString("network_ping_critical_ms");
	mStringArgs["[NETWORK_PING_CRITICAL]"] = getString("network_ping_critical_ms");
	mStringArgs["[NETWORK_PING_WARNING]"] = getString("network_ping_warning_ms");

	mStringArgs["[SERVER_FRAME_RATE_CRITICAL]"] = getString("server_frame_rate_critical_fps");
	mStringArgs["[SERVER_FRAME_RATE_CRITICAL]"] = getString("server_frame_rate_critical_fps");
	mStringArgs["[SERVER_FRAME_RATE_WARNING]"] = getString("server_frame_rate_warning_fps");

	childSetAction("minimize", onClickShrink, this);

	// were we shrunk last time?
	if (gSavedSettings.getBOOL("LagMeterShrunk"))
	{
		onClickShrink(this);
	}
}

LLFloaterLagMeter::~LLFloaterLagMeter()
{
	// save shrunk status for next time
	gSavedSettings.setBOOL("LagMeterShrunk", mShrunk);
	// expand so we save the large window rectangle
	if (mShrunk)
	{
		onClickShrink(this);
	}
}

void LLFloaterLagMeter::draw()
{
	determineClient();
	determineNetwork();
	determineServer();

	LLFloater::draw();
}

void LLFloaterLagMeter::determineClient()
{
	F32 client_frame_time = LLViewerStats::getInstance()->mFPSStat.getMeanDuration();
	bool find_cause = false;

	if (!gFocusMgr.getAppHasFocus())
	{
		mClientButton->setImageUnselected(LAG_GOOD_IMAGE_NAME);
		mClientText->setText( getString("client_frame_time_window_bg_msg", mStringArgs) );
		mClientCause->setText( LLStringUtil::null );
	}
	else if(client_frame_time >= mClientFrameTimeCritical)
	{
		mClientButton->setImageUnselected(LAG_CRITICAL_IMAGE_NAME);
		mClientText->setText( getString("client_frame_time_critical_msg", mStringArgs) );
		find_cause = true;
	}
	else if(client_frame_time >= mClientFrameTimeWarning)
	{
		mClientButton->setImageUnselected(LAG_WARNING_IMAGE_NAME);
		mClientText->setText( getString("client_frame_time_warning_msg", mStringArgs) );
		find_cause = true;
	}
	else
	{
		mClientButton->setImageUnselected(LAG_GOOD_IMAGE_NAME);
		mClientText->setText( getString("client_frame_time_normal_msg", mStringArgs) );
		mClientCause->setText( LLStringUtil::null );
	}	

	if(find_cause)
	{
		if(gSavedSettings.getF32("RenderFarClip") > 128)
		{
			mClientCause->setText( getString("client_draw_distance_cause_msg", mStringArgs) );
		}
		else if(LLAppViewer::instance()->getTextureFetch()->getNumRequests() > 2)
		{
			mClientCause->setText( getString("client_texture_loading_cause_msg", mStringArgs) );
		}
		else if(LLViewerImage::sBoundTextureMemory > LLViewerImage::sMaxBoundTextureMem)
		{
			mClientCause->setText( getString("client_texture_memory_cause_msg", mStringArgs) );
		}
		else 
		{
			mClientCause->setText( getString("client_complex_objects_cause_msg", mStringArgs) );
		}
	}
}

void LLFloaterLagMeter::determineNetwork()
{
	F32 packet_loss = LLViewerStats::getInstance()->mPacketsLostPercentStat.getMean();
	F32 ping_time = LLViewerStats::getInstance()->mSimPingStat.getMean();
	bool find_cause_loss = false;
	bool find_cause_ping = false;

	if(packet_loss >= mNetworkPacketLossCritical)
	{
		mNetworkButton->setImageUnselected(LAG_CRITICAL_IMAGE_NAME);
		mNetworkText->setText( getString("network_packet_loss_critical_msg", mStringArgs) );
		find_cause_loss = true;
	}
	else if(ping_time >= mNetworkPingCritical)
	{
		mNetworkButton->setImageUnselected(LAG_CRITICAL_IMAGE_NAME);
		mNetworkText->setText( getString("network_ping_critical_msg", mStringArgs) );
		find_cause_ping = true;
	}
	else if(packet_loss >= mNetworkPacketLossWarning)
	{
		mNetworkButton->setImageUnselected(LAG_WARNING_IMAGE_NAME);
		mNetworkText->setText( getString("network_packet_loss_warning_msg", mStringArgs) );
		find_cause_loss = true;
	}
	else if(ping_time >= mNetworkPingWarning)
	{
		mNetworkButton->setImageUnselected(LAG_WARNING_IMAGE_NAME);
		mNetworkText->setText( getString("network_ping_warning_msg", mStringArgs) );
		find_cause_ping = true;
	}
	else
	{
		mNetworkButton->setImageUnselected(LAG_GOOD_IMAGE_NAME);
		mNetworkText->setText( getString("network_performance_normal_msg", mStringArgs) );
	}

	if(find_cause_loss)
 	{
		mNetworkCause->setText( getString("network_packet_loss_cause_msg", mStringArgs) );
 	}
	else if(find_cause_ping)
	{
		mNetworkCause->setText( getString("network_ping_cause_msg", mStringArgs) );
	}
	else
	{
		mNetworkCause->setText( LLStringUtil::null );
	}
}

void LLFloaterLagMeter::determineServer()
{
	F32 sim_frame_time = LLViewerStats::getInstance()->mSimFrameMsec.getCurrent();
	bool find_cause = false;

	if(sim_frame_time >= mServerFrameTimeCritical)
	{
		mServerButton->setImageUnselected(LAG_CRITICAL_IMAGE_NAME);
		mServerText->setText( getString("server_frame_time_critical_msg", mStringArgs) );
		find_cause = true;
	}
	else if(sim_frame_time >= mServerFrameTimeWarning)
	{
		mServerButton->setImageUnselected(LAG_WARNING_IMAGE_NAME);
		mServerText->setText( getString("server_frame_time_warning_msg", mStringArgs) );
		find_cause = true;
	}
	else
	{
		mServerButton->setImageUnselected(LAG_GOOD_IMAGE_NAME);
		mServerText->setText( getString("server_frame_time_normal_msg", mStringArgs) );
		mServerCause->setText( LLStringUtil::null );
	}	

	if(find_cause)
	{
		if(LLViewerStats::getInstance()->mSimSimPhysicsMsec.getCurrent() > mServerSingleProcessMaxTime)
		{
			mServerCause->setText( getString("server_physics_cause_msg", mStringArgs) );
		}
		else if(LLViewerStats::getInstance()->mSimScriptMsec.getCurrent() > mServerSingleProcessMaxTime)
		{
			mServerCause->setText( getString("server_scripts_cause_msg", mStringArgs) );
		}
		else if(LLViewerStats::getInstance()->mSimNetMsec.getCurrent() > mServerSingleProcessMaxTime)
		{
			mServerCause->setText( getString("server_net_cause_msg", mStringArgs) );
		}
		else if(LLViewerStats::getInstance()->mSimAgentMsec.getCurrent() > mServerSingleProcessMaxTime)
		{
			mServerCause->setText( getString("server_agent_cause_msg", mStringArgs) );
		}
		else if(LLViewerStats::getInstance()->mSimImagesMsec.getCurrent() > mServerSingleProcessMaxTime)
		{
			mServerCause->setText( getString("server_images_cause_msg", mStringArgs) );
		}
		else
		{
			mServerCause->setText( getString("server_generic_cause_msg", mStringArgs) );
		}
	}
}

//static
void LLFloaterLagMeter::onClickShrink(void * data)
{
	LLFloaterLagMeter * self = (LLFloaterLagMeter*)data;

	LLButton * button = self->getChild<LLButton>("minimize");
	S32 delta_width = self->mMaxWidth - self->mMinWidth;
	LLRect r = self->getRect();
	if(self->mShrunk)
	{
		self->setTitle( self->getString("max_title_msg", self->mStringArgs) );
		// make left edge appear to expand
		r.translate(-delta_width, 0);
		self->setRect(r);
		self->reshape(self->mMaxWidth, self->getRect().getHeight());
		
		self->childSetText("client", self->getString("client_text_msg", self->mStringArgs) + ":");
		self->childSetText("network", self->getString("network_text_msg", self->mStringArgs) + ":");
		self->childSetText("server", self->getString("server_text_msg", self->mStringArgs) + ":");

		// usually "<<"
		button->setLabel( self->getString("smaller_label", self->mStringArgs) );
	}
	else
	{
		self->setTitle( self->getString("min_title_msg", self->mStringArgs) );
		// make left edge appear to collapse
		r.translate(delta_width, 0);
		self->setRect(r);
		self->reshape(self->mMinWidth, self->getRect().getHeight());
		
		self->childSetText("client", self->getString("client_text_msg", self->mStringArgs) );
		self->childSetText("network", self->getString("network_text_msg", self->mStringArgs) );
		self->childSetText("server", self->getString("server_text_msg", self->mStringArgs) );

		// usually ">>"
		button->setLabel( self->getString("bigger_label", self->mStringArgs) );
	}
	// Don't put keyboard focus on the button
	button->setFocus(FALSE);

	self->mClientText->setVisible(self->mShrunk);
	self->mClientCause->setVisible(self->mShrunk);
	self->childSetVisible("client_help", self->mShrunk);

	self->mNetworkText->setVisible(self->mShrunk);
	self->mNetworkCause->setVisible(self->mShrunk);
	self->childSetVisible("network_help", self->mShrunk);

	self->mServerText->setVisible(self->mShrunk);
	self->mServerCause->setVisible(self->mShrunk);
	self->childSetVisible("server_help", self->mShrunk);

	self->mShrunk = !self->mShrunk;
}