aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llfloatermemleak.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/newview/llfloatermemleak.cpp')
-rw-r--r--linden/indra/newview/llfloatermemleak.cpp265
1 files changed, 265 insertions, 0 deletions
diff --git a/linden/indra/newview/llfloatermemleak.cpp b/linden/indra/newview/llfloatermemleak.cpp
new file mode 100644
index 0000000..16be9df
--- /dev/null
+++ b/linden/indra/newview/llfloatermemleak.cpp
@@ -0,0 +1,265 @@
1/**
2 * @file llfloatermemleak.cpp
3 * @brief LLFloatermemleak class definition
4 *
5 * $LicenseInfo:firstyear=2007&license=viewergpl$
6 *
7 * Copyright (c) 2007-2008, 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 http://secondlifegrid.net/programs/open_source/licensing/flossexception
21 *
22 * By copying, modifying or distributing this software, you acknowledge
23 * that you have read and understood your obligations described above,
24 * and agree to abide by those obligations.
25 *
26 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
27 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
28 * COMPLETENESS OR PERFORMANCE.
29 * $/LicenseInfo$
30 */
31
32#include "llviewerprecompiledheaders.h"
33
34#include "llfloatermemleak.h"
35
36#include "lluictrlfactory.h"
37#include "llbutton.h"
38#include "llspinctrl.h"
39#include "llresmgr.h"
40
41#include "llmath.h"
42#include "llviewerwindow.h"
43
44LLFloaterMemLeak* LLFloaterMemLeak::sInstance = NULL;
45U32 LLFloaterMemLeak::sMemLeakingSpeed = 0 ; //bytes leaked per frame
46U32 LLFloaterMemLeak::sMaxLeakedMem = 0 ; //maximum allowed leaked memory
47U32 LLFloaterMemLeak::sTotalLeaked = 0 ;
48S32 LLFloaterMemLeak::sStatus = LLFloaterMemLeak::STOP ;
49BOOL LLFloaterMemLeak::sbAllocationFailed = FALSE ;
50
51LLFloaterMemLeak::LLFloaterMemLeak() : LLFloater("Memory Leaking Simulation Floater")
52{
53}
54
55LLFloaterMemLeak::~LLFloaterMemLeak()
56{
57 release() ;
58
59 sMemLeakingSpeed = 0 ; //bytes leaked per frame
60 sMaxLeakedMem = 0 ; //maximum allowed leaked memory
61 sInstance = NULL ;
62}
63
64void LLFloaterMemLeak::release()
65{
66 for(S32 i = 0 ; i < (S32)mLeakedMem.size() ; i++)
67 {
68 delete[] mLeakedMem[i] ;
69 }
70 mLeakedMem.clear() ;
71
72 sStatus = STOP ;
73 sTotalLeaked = 0 ;
74 sbAllocationFailed = FALSE ;
75}
76
77void LLFloaterMemLeak::stop()
78{
79 sStatus = STOP ;
80 sbAllocationFailed = TRUE ;
81}
82
83void LLFloaterMemLeak::idle()
84{
85 if(STOP == sStatus)
86 {
87 return ;
88 }
89
90 sbAllocationFailed = FALSE ;
91
92 if(RELEASE == sStatus)
93 {
94 release() ;
95 return ;
96 }
97
98 char* p = NULL ;
99 if(sMemLeakingSpeed > 0 && sTotalLeaked < sMaxLeakedMem)
100 {
101 p = new char[sMemLeakingSpeed] ;
102
103 if(p)
104 {
105 mLeakedMem.push_back(p) ;
106 sTotalLeaked += sMemLeakingSpeed ;
107 }
108 }
109 if(!p)
110 {
111 sStatus = STOP ;
112 sbAllocationFailed = TRUE ;
113 }
114}
115
116//----------------------
117void LLFloaterMemLeak::onChangeLeakingSpeed(LLUICtrl* ctrl, void* userData)
118{
119 LLFloaterMemLeak *mem_leak = (LLFloaterMemLeak *)userData;
120 if (mem_leak)
121 {
122 F32 tmp ;
123 tmp = mem_leak->childGetValue("leak_speed").asReal();
124
125 if(tmp > (F32)0xFFFFFFFF)
126 {
127 sMemLeakingSpeed = 0xFFFFFFFF ;
128 }
129 else
130 {
131 sMemLeakingSpeed = (U32)tmp ;
132 }
133 }
134}
135
136void LLFloaterMemLeak::onChangeMaxMemLeaking(LLUICtrl* ctrl, void* userData)
137{
138 LLFloaterMemLeak *mem_leak = (LLFloaterMemLeak *)userData;
139 if (mem_leak)
140 {
141 F32 tmp ;
142 tmp = mem_leak->childGetValue("max_leak").asReal();
143 if(tmp > (F32)0xFFF)
144 {
145 sMaxLeakedMem = 0xFFFFFFFF ;
146 }
147 else
148 {
149 sMaxLeakedMem = ((U32)tmp) << 20 ;
150 }
151 }
152}
153
154void LLFloaterMemLeak::onClickStart(void* userData)
155{
156 sStatus = START ;
157}
158
159void LLFloaterMemLeak::onClickStop(void* userData)
160{
161 sStatus = STOP ;
162}
163
164void LLFloaterMemLeak::onClickRelease(void* userData)
165{
166 sStatus = RELEASE ;
167}
168
169void LLFloaterMemLeak::onClickClose(void* userData)
170{
171 if (sInstance)
172 {
173 sInstance->setVisible(FALSE);
174 }
175}
176
177//----------------------------------------------
178
179BOOL LLFloaterMemLeak::postBuild(void)
180{
181 childSetCommitCallback("leak_speed", onChangeLeakingSpeed, this);
182 childSetCommitCallback("max_leak", onChangeMaxMemLeaking, this);
183
184 childSetAction("start_btn", onClickStart, this);
185 childSetAction("stop_btn", onClickStop, this);
186 childSetAction("release_btn", onClickRelease, this);
187 childSetAction("close_btn", onClickClose, this);
188
189 return TRUE ;
190}
191
192void LLFloaterMemLeak::draw()
193{
194 //show total memory leaked
195 if(sTotalLeaked > 0)
196 {
197 std::string bytes_string;
198 LLResMgr::getInstance()->getIntegerString(bytes_string, sTotalLeaked >> 10 );
199 childSetTextArg("total_leaked_label", "[SIZE]", bytes_string);
200 }
201 else
202 {
203 childSetTextArg("total_leaked_label", "[SIZE]", LLStringExplicit("0"));
204 }
205
206 if(sbAllocationFailed)
207 {
208 childSetTextArg("note_label_1", "[NOTE1]", LLStringExplicit("Memory leaking simulation stops. Reduce leaking speed or"));
209 childSetTextArg("note_label_2", "[NOTE2]", LLStringExplicit("increase max leaked memory, then press Start to continue."));
210 }
211 else
212 {
213 childSetTextArg("note_label_1", "[NOTE1]", LLStringExplicit(""));
214 childSetTextArg("note_label_2", "[NOTE2]", LLStringExplicit(""));
215 }
216
217 LLFloater::draw();
218}
219
220// static instance of it
221LLFloaterMemLeak* LLFloaterMemLeak::instance()
222{
223 if (!sInstance)
224 {
225 sInstance = new LLFloaterMemLeak();
226 LLUICtrlFactory::getInstance()->buildFloater(sInstance, "floater_mem_leaking.xml", NULL, FALSE);
227
228 if(sInstance)
229 {
230 F32 a, b ;
231 a = sInstance->childGetValue("leak_speed").asReal();
232 if(a > (F32)(0xFFFFFFFF))
233 {
234 sMemLeakingSpeed = 0xFFFFFFFF ;
235 }
236 else
237 {
238 sMemLeakingSpeed = (U32)a ;
239 }
240 b = sInstance->childGetValue("max_leak").asReal();
241 if(b > (F32)0xFFF)
242 {
243 sMaxLeakedMem = 0xFFFFFFFF ;
244 }
245 else
246 {
247 sMaxLeakedMem = ((U32)b) << 20 ;
248 }
249
250 sbAllocationFailed = FALSE ;
251 }
252 }
253 return sInstance ;
254}
255
256void LLFloaterMemLeak::show(void*)
257{
258 instance()->open();
259}
260
261LLFloaterMemLeak* LLFloaterMemLeak::getInstance()
262{
263 return sInstance ;
264}
265