vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 local L = AceLibrary("AceLocale-2.0"):new("FuBar_PerformanceFu")
2 local Tablet = AceLibrary("Tablet-2.0")
3 local Abacus = AceLibrary("Abacus-2.0")
4 local Crayon = AceLibrary("Crayon-2.0")
5  
6 PerformanceFu = AceLibrary("AceAddon-2.0"):new("FuBarPlugin-2.0", "AceConsole-2.0", "AceEvent-2.0", "AceDB-2.0")
7  
8 PerformanceFu.version = "2.0" .. string.sub("$Revision: 7559 $", 12, -3)
9 PerformanceFu.date = string.sub("$Date: 2006-08-09 22:43:29 -1000 (Wed, 09 Aug 2006) $", 8, 17)
10 PerformanceFu.hasIcon = true
11  
12 local string_format = string.format
13 local table_concat = table.concat
14 local table_insert = table.insert
15 local table_setn = table.setn
16  
17 PerformanceFu:RegisterDB("PerformanceFuDB")
18 PerformanceFu:RegisterDefaults("profile", {
19 showFramerate = true,
20 showLatency = true,
21 showMemory = true,
22 showRate = true,
23 warnGC = false,
24 })
25  
26 function PerformanceFu:IsShowingFramerate()
27 return self.db.profile.showFramerate
28 end
29  
30 function PerformanceFu:ToggleShowingFramerate()
31 self.db.profile.showFramerate = not self.db.profile.showFramerate
32 self:Update()
33 end
34  
35 function PerformanceFu:IsShowingLatency()
36 return self.db.profile.showLatency
37 end
38  
39 function PerformanceFu:ToggleShowingLatency()
40 self.db.profile.showLatency = not self.db.profile.showLatency
41 self:Update()
42 end
43  
44 function PerformanceFu:IsShowingRate()
45 return self.db.profile.showRate
46 end
47  
48 function PerformanceFu:ToggleShowingRate()
49 self.db.profile.showRate = not self.db.profile.showRate
50 self:Update()
51 end
52  
53 function PerformanceFu:IsShowingMemory()
54 return self.db.profile.showMemory
55 end
56  
57 function PerformanceFu:ToggleShowingMemory()
58 self.db.profile.showMemory = not self.db.profile.showMemory
59 self:Update()
60 end
61  
62 function PerformanceFu:IsWarningOnGC()
63 return self.db.profile.warnGC
64 end
65  
66 function PerformanceFu:ToggleWarningOnGC()
67 self.db.profile.warnGC = not self.db.profile.warnGC
68 end
69  
70 local beeps5 = 0
71 local beeps15 = 0
72 local beeps30 = 0
73 local beeps60 = 0
74 local beeps180 = 0
75 local beeps600 = 0
76  
77 local initialMemory, gcThreshold, currentMemory
78 local mem1, mem2, mem3, mem4, mem5, mem6, mem7, mem8, mem9, mem10
79 local timeSinceLastUpdate
80 local justEntered
81 local gcTime
82  
83 function PerformanceFu:OnEnable()
84 initialMemory, gcThreshold = gcinfo()
85 currentMemory = initialMemory
86 mem1 = currentMemory
87 mem2 = currentMemory
88 mem3 = currentMemory
89 mem4 = currentMemory
90 mem5 = currentMemory
91 mem6 = currentMemory
92 mem7 = currentMemory
93 mem8 = currentMemory
94 mem9 = currentMemory
95 mem10 = currentMemory
96 timeSinceLastUpdate = 0
97 gcTime = time()
98 justEntered = true
99 self:ScheduleRepeatingEvent(self.OnUpdate, 1, self)
100 end
101  
102 local options = {
103 type = 'group',
104 args = {
105 framerate = {
106 type = 'toggle',
107 name = L"Show framerate",
108 desc = L"Toggle whether to framerate",
109 get = "IsShowingFramerate",
110 set = "ToggleShowingFramerate",
111 },
112 latency = {
113 type = 'toggle',
114 name = L"Show latency",
115 desc = L"Toggle whether to latency (lag)",
116 get = "IsShowingLatency",
117 set = "ToggleShowingLatency",
118 },
119 memory = {
120 type = 'toggle',
121 name = L"Show memory usage",
122 desc = L"Toggle whether to show current memory usage",
123 get = "IsShowingMemory",
124 set = "ToggleShowingMemory",
125 },
126 rate = {
127 type = 'toggle',
128 name = L"Show rate of increasing memory usage",
129 desc = L"Toggle whether to show increasing rate of memory",
130 get = "IsShowingRate",
131 set = "ToggleShowingRate",
132 },
133 warn = {
134 type = 'toggle',
135 name = L"Warn on garbage collection",
136 desc = L"Toggle whether to warn on an upcoming garbage collection",
137 get = "IsWarningOnGC",
138 set = "ToggleWarningOnGC",
139 },
140 forcegc = {
141 type = 'execute',
142 name = L"Force garbage collection",
143 desc = L"Force a garbage collection to happen",
144 order = 101,
145 func = collectgarbage
146 }
147 }
148 }
149 PerformanceFu:RegisterChatCommand(L:GetTable("AceConsole-options"), options)
150 PerformanceFu.OnMenuRequest = options
151  
152 local gccheck = setmetatable({[{}]=true}, {__mode = "k"})
153  
154 function PerformanceFu:OnUpdate()
155 if justEntered then
156 if not timeSinceLastUpdate then
157 timeSinceLastUpdate = 0
158 end
159 timeSinceLastUpdate = timeSinceLastUpdate + 1
160 if timeSinceLastUpdate >= 10 then
161 initialMemory, gcThreshold = gcinfo()
162 currentMemory = initialMemory
163 mem1 = currentMemory
164 mem2 = currentMemory
165 mem3 = currentMemory
166 mem4 = currentMemory
167 mem5 = currentMemory
168 mem6 = currentMemory
169 mem7 = currentMemory
170 mem8 = currentMemory
171 mem9 = currentMemory
172 mem10 = currentMemory
173 timeSinceLastUpdate = nil
174 gcTime = time()
175 justEntered = false
176 end
177 else
178 local t = time()
179 timeSinceLastUpdate = 0
180 mem1, mem2, mem3, mem4, mem5, mem6, mem7, mem8, mem9, mem10 =
181 currentMemory, mem1, mem2, mem3, mem4, mem5, mem6, mem7, mem8, mem9
182 currentMemory, gcThreshold = gcinfo()
183 if not next(gccheck) then
184 gccheck[{}] = true
185 initialMemory = currentMemory
186 gcTime = t
187 mem10, mem9, mem9, mem8, mem7, mem6, mem5, mem4, mem3, mem2, mem1 =
188 currentMemory, currentMemory, currentMemory, currentMemory, currentMemory, currentMemory, currentMemory, currentMemory, currentMemory, currentMemory
189 beeps5 = 0
190 beeps5 = 0
191 beeps15 = 0
192 beeps30 = 0
193 beeps60 = 0
194 beeps180 = 0
195 beeps600 = 0
196 if self:IsWarningOnGC() then
197 self:Print(L"Garbage collection occurred")
198 end
199 end
200 local averageRate = (currentMemory - initialMemory) / (t - gcTime)
201 local totalSecs = (gcThreshold - currentMemory) / averageRate
202 if self:IsWarningOnGC() then
203 if totalSecs <= 5 and beeps5 < t - 15 then
204 self:Print(L"Garbage collection in %s", Abacus:FormatDurationShort(totalSecs, false, true))
205 beeps600 = t
206 beeps180 = t
207 beeps60 = t
208 beeps30 = t
209 beeps15 = t
210 beeps5 = t
211 elseif totalSecs <= 15 and beeps15 < t - 30 then
212 self:Print(L"Garbage collection in %s", Abacus:FormatDurationShort(totalSecs, false, true))
213 beeps600 = t
214 beeps180 = t
215 beeps60 = t
216 beeps30 = t
217 beeps15 = t
218 elseif totalSecs <= 30 and beeps30 < t - 45 then
219 self:Print(L"Garbage collection in %s", Abacus:FormatDurationShort(totalSecs, false, true))
220 beeps600 = t
221 beeps180 = t
222 beeps60 = t
223 beeps30 = t
224 elseif totalSecs <= 60 and beeps60 < t - 90 then
225 self:Print(L"Garbage collection in %s", Abacus:FormatDurationShort(totalSecs, false, true))
226 beeps600 = t
227 beeps180 = t
228 beeps60 = t
229 elseif totalSecs <= 180 and beeps180 < t - 270 then
230 self:Print(L"Garbage collection in %s", Abacus:FormatDurationShort(totalSecs, false, true))
231 beeps600 = t
232 beeps180 = t
233 elseif totalSecs <= 600 and beeps600 < t - 900 then
234 self:Print(L"Garbage collection in %s", Abacus:FormatDurationShort(totalSecs, false, true))
235 beeps600 = t
236 end
237 end
238 self:Update()
239 end
240 end
241  
242 local t = {}
243 function PerformanceFu:OnTextUpdate()
244 if not mem10 then
245 mem10 = currentMemory
246 end
247 local currentRate = (currentMemory - mem10) / 10
248  
249 if self:IsShowingFramerate() then
250 local framerate = floor(GetFramerate() + 0.5)
251 table_insert(t, format("|cff%s%d|r fps", Crayon:GetThresholdHexColor(framerate / 60), framerate))
252 end
253 if self:IsShowingLatency() then
254 local _,_,latency = GetNetStats()
255 table_insert(t, format("|cff%s%d|r ms", Crayon:GetThresholdHexColor(latency, 1000, 500, 250, 100, 0), latency))
256 end
257 if self:IsShowingMemory() then
258 table_insert(t, format("|cff%s%.1f|r MiB", Crayon:GetThresholdHexColor(currentMemory, 51200, 40960, 30520, 20480, 10240), currentMemory / 1024))
259 end
260 if self:IsShowingRate() then
261 table_insert(t, format("|cff%s%.1f|r KiB/s", Crayon:GetThresholdHexColor(currentRate, 30, 10, 3, 1, 0), currentRate))
262 end
263 self:SetText(table_concat(t, " "))
264 for k in pairs(t) do
265 t[k] = nil
266 k = nil
267 end
268 table_setn(t, 0)
269 end
270  
271 function PerformanceFu:OnTooltipUpdate()
272 local cat = Tablet:AddCategory(
273 'columns', 2,
274 'child_textR', 1,
275 'child_textG', 1,
276 'child_textB', 0
277 )
278 local framerate = GetFramerate()
279 local r, g, b = Crayon:GetThresholdColor(framerate / 60)
280 cat:AddLine(
281 'text', L"Framerate:",
282 'text2', string_format("%.1f fps", framerate),
283 'text2R', r,
284 'text2G', g,
285 'text2B', b
286 )
287  
288 cat = Tablet:AddCategory(
289 'text', L"Network status",
290 'columns', 2,
291 'child_textR', 1,
292 'child_textG', 1,
293 'child_textB', 0,
294 'child_text2R', 1,
295 'child_text2G', 1,
296 'child_text2B', 1
297 )
298 local bandwidthIn, bandwidthOut, latency = GetNetStats()
299 bandwidthIn, bandwidthOut = bandwidthIn * 1024, bandwidthOut * 1024
300 local r, g, b = Crayon:GetThresholdColor(latency, 3000, 1000, 250, 100, 0)
301 cat:AddLine(
302 'text', L"Latency:",
303 'text2', string_format("%d ms", latency),
304 'text2R', r,
305 'text2G', g,
306 'text2B', b
307 )
308  
309 cat:AddLine(
310 'text', L"Bandwidth in:",
311 'text2', string_format("%d B/s", bandwidthIn)
312 )
313  
314 cat:AddLine(
315 'text', L"Bandwidth out:",
316 'text2', string_format("%d B/s", bandwidthOut)
317 )
318  
319 local averageRate = (currentMemory - initialMemory) / (time() - gcTime)
320 cat = Tablet:AddCategory(
321 'text', L"Memory usage",
322 'columns', 2,
323 'child_textR', 1,
324 'child_textG', 1,
325 'child_textB', 0,
326 'child_text2R', 1,
327 'child_text2G', 1,
328 'child_text2B', 1
329 )
330 local currentRate = (currentMemory - mem10) / 10
331  
332 local r, g, b = Crayon:GetThresholdColor(currentMemory, 51200, 40960, 30520, 20480, 10240)
333 cat:AddLine(
334 'text', L"Current memory:",
335 'text2', string_format("%.1f MiB", currentMemory / 1024),
336 'text2R', r,
337 'text2G', g,
338 'text2B', b
339 )
340  
341 r, g, b = Crayon:GetThresholdColor(initialMemory, 51200, 40960, 30520, 20480, 10240)
342 cat:AddLine(
343 'text', L"Initial memory:",
344 'text2', string_format("%.1f MiB", initialMemory / 1024),
345 'text2R', r,
346 'text2G', g,
347 'text2B', b
348 )
349  
350 r, g, b = Crayon:GetThresholdColor(currentRate, 30, 10, 3, 1, 0)
351 cat:AddLine(
352 'text', L"Increasing rate:",
353 'text2', string_format("%.1f KiB/s", currentRate),
354 'text2R', r,
355 'text2G', g,
356 'text2B', b
357 )
358  
359 r, g, b = Crayon:GetThresholdColor(averageRate, 30, 10, 3, 1, 0)
360 cat:AddLine(
361 'text', L"Average increasing rate:",
362 'text2', format("%.1f KiB/s", averageRate),
363 'text2R', r,
364 'text2G', g,
365 'text2B', b
366 )
367  
368 cat = Tablet:AddCategory(
369 'text', L"Garbage collection",
370 'columns', 2,
371 'child_textR', 1,
372 'child_textG', 1,
373 'child_textB', 0,
374 'child_text2R', 1,
375 'child_text2G', 1,
376 'child_text2B', 1
377 )
378  
379 local totalSecs = (gcThreshold - currentMemory) / averageRate
380 local timeToNext = Abacus:FormatDurationFull(totalSecs)
381  
382 local r, g, b = Crayon:GetThresholdColor(gcThreshold, 51200, 40960, 30520, 20480, 10240)
383 cat:AddLine(
384 'text', L"Threshold:",
385 'text2', format("%.1f MiB", gcThreshold / 1024),
386 'text2R', r,
387 'text2G', g,
388 'text2B', b
389 )
390  
391 local r, g, b = Crayon:GetThresholdColor(totalSecs, 0, 900, 1800, 2700, 3600)
392 cat:AddLine(
393 'text', L"Time to next:",
394 'text2', timeToNext,
395 'text2R', r,
396 'text2G', g,
397 'text2B', b
398 )
399 end