Repository navigation
Expand file tree
/
Copy pathBench.lua
More file actions
317 lines (288 loc) · 10.6 KB
/
Copy pathBench.lua
File metadata and controls
317 lines (288 loc) · 10.6 KB
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
-- Copyright (C) 2026 BellaHealFr. Licence GPL-3.0-only avec conditions supplémentaires
-- (mention de l'auteur, nom « Strata » réservé) : voir LICENSE et NOTICE.md.
-- Strata - Carte du monde continue pour World of Warcraft 3.3.5
-- Mesure en jeu : le compteur à l'écran (/strata debug) et le parcours de mesure (/strata bench).
--
-- Le banc du dépôt compte le travail du code ; ici on mesure ce qu'il ne voit pas : images par
-- seconde réelles (rendu compris), millisecondes de Strata par image (debugprofilestop) et mémoire
-- Lua de l'addon. Rien ne tourne tant que ni le compteur ni le bench ne sont actifs.
local _, ns = ...
local L = ns.L
local stats = ns.stats
-- Objectifs de performance en jeu, comparés aux mesures de /strata bench.
local GOAL_FPS_DROP = 0.10 -- images par seconde carte ouverte : au plus 10 % de moins que fermée
local GOAL_PAN_AVG = 1 -- ms de Strata par image en déplacement, en moyenne
local GOAL_PAN_WORST = 5 -- ms, pire image
local GOAL_MEMORY = 2048 -- Ko de mémoire Lua après le parcours
-- Textures chargées au plus fort : la vraie mémoire de Strata, et mesurable sur tous les clients
-- (certains renvoient 0 pour la mémoire Lua d'un addon, #27).
local GOAL_TEXTURES = 600
-- Lecture des cartes à la première ouverture : tenir dans une image à 60 IPS (#8).
local GOAL_SCAN = 16
local overlay, overlayText, results, resultsBox
local bench
local function UpdateMeasuring()
ns.measuring = (overlay and overlay:IsShown()) or bench ~= nil
end
local function ResetWindow()
stats.frames, stats.ms, stats.worst = 0, 0, 0
end
local function Memory()
UpdateAddOnMemoryUsage()
return GetAddOnMemoryUsage("Strata")
end
--------------------------------------------------------------------------------
-- Compteur à l'écran
local function CreateOverlay(parent)
overlay = CreateFrame("Frame", nil, parent)
overlay:SetPoint("TOPLEFT", 16, -34)
overlay:SetWidth(250)
overlay:SetHeight(52)
overlay:SetFrameLevel(parent:GetFrameLevel() + 40)
overlay:SetBackdrop({ bgFile = "Interface\\Tooltips\\UI-Tooltip-Background" })
overlay:SetBackdropColor(0, 0, 0, 0.7)
overlayText = overlay:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
overlayText:SetPoint("TOPLEFT", 6, -6)
overlayText:SetJustifyH("LEFT")
overlay:Hide()
local wait, memWait, memory = 0, 0, 0
overlay:SetScript("OnUpdate", function(self, elapsed)
wait, memWait = wait - elapsed, memWait - elapsed
if wait > 0 then return end
wait = 0.5
if memWait <= 0 then
-- UpdateAddOnMemoryUsage parcourt tous les addons : pas plus d'une fois toutes les 2 s.
memory, memWait = Memory(), 2
end
local avg = stats.frames > 0 and stats.ms / stats.frames or 0
overlayText:SetFormattedText(L.DEBUG_TEXT, GetFramerate(), avg, stats.worst, stats.layersMs,
stats.textures, stats.zones, memory)
if not bench then ResetWindow() end
end)
overlay:SetScript("OnShow", UpdateMeasuring)
overlay:SetScript("OnHide", UpdateMeasuring)
end
function ns.ToggleDebug()
local frame = ns.view.Frame()
if not frame or not frame:IsShown() then ns.Open() end
frame = ns.view.Frame()
if not overlay then CreateOverlay(frame) end
if overlay:IsShown() then
overlay:Hide()
else
ResetWindow()
overlay:Show()
end
end
--------------------------------------------------------------------------------
-- Résultats
local function CreateResults()
results = CreateFrame("Frame", "StrataBenchFrame", UIParent)
results:SetWidth(520)
results:SetHeight(330)
results:SetPoint("CENTER")
results:SetFrameStrata("DIALOG")
results:SetToplevel(true)
results:EnableMouse(true)
results:SetMovable(true)
results:RegisterForDrag("LeftButton")
results:SetScript("OnDragStart", results.StartMoving)
results:SetScript("OnDragStop", results.StopMovingOrSizing)
results:SetBackdrop({
bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
tile = true, tileSize = 32, edgeSize = 24,
insets = { left = 6, right = 6, top = 6, bottom = 6 },
})
tinsert(UISpecialFrames, "StrataBenchFrame")
local title = results:CreateFontString(nil, "OVERLAY", "GameFontNormal")
title:SetPoint("TOPLEFT", 16, -14)
title:SetText(L.BENCH_TITLE)
local hint = results:CreateFontString(nil, "OVERLAY", "GameFontDisableSmall")
hint:SetPoint("BOTTOMLEFT", 16, 14)
hint:SetText(L.BENCH_COPY)
local close = CreateFrame("Button", nil, results, "UIPanelCloseButton")
close:SetPoint("TOPRIGHT", -4, -4)
resultsBox = CreateFrame("EditBox", nil, results)
resultsBox:SetPoint("TOPLEFT", 16, -36)
resultsBox:SetPoint("BOTTOMRIGHT", -16, 32)
resultsBox:SetMultiLine(true)
resultsBox:SetAutoFocus(false)
resultsBox:SetFontObject(GameFontHighlightSmall)
resultsBox:SetScript("OnEscapePressed", function(self) self:ClearFocus() end)
-- Le texte reste celui du bench même si l'on tape dedans : il ne sert qu'à être copié.
resultsBox:SetScript("OnTextChanged", function(self, user)
if user and results.text then self:SetText(results.text) end
end)
end
local function Verdict(ok)
return ok and L.OK or L.TO_CHECK
end
local function Report(r)
local lines = {
format("Strata %s - %s - %s", r.version, L.BENCH_TITLE, date("%Y-%m-%d %H:%M", r.time)),
"",
L.BENCH_HEADER,
}
for _, p in ipairs(r.phases) do
local ms = p.ms and format("%.2f / %.2f", p.ms, p.worst) or "-"
lines[#lines + 1] = format("%s %.0f %s %d", L.PHASES[p.key], p.fps, ms, p.peak)
end
lines[#lines + 1] = ""
-- Certains clients renvoient 0 pour la mémoire d'un addon (#27) : une mesure absente n'est
-- jamais présentée comme réussie.
local measured = r.memory and r.memory > 0
lines[#lines + 1] = measured and format(L.BENCH_MEMORY, r.memory) or L.BENCH_MEMORY_NONE
lines[#lines + 1] = format(L.BENCH_LUA_TOTAL, (r.luaTotal or 0) / 1024)
lines[#lines + 1] = ""
lines[#lines + 1] = L.BENCH_GOALS
local byKey = {}
for _, p in ipairs(r.phases) do byKey[p.key] = p end
local closed, still, pan = byKey.closed, byKey.still, byKey.pan
local drop = closed.fps > 0 and (closed.fps - still.fps) / closed.fps or 0
lines[#lines + 1] = format(L.GOAL_FPS, still.fps, closed.fps, -drop * 100, Verdict(drop <= GOAL_FPS_DROP))
lines[#lines + 1] = format(L.GOAL_PAN, pan.ms or 0, pan.worst or 0,
Verdict((pan.ms or 0) < GOAL_PAN_AVG and (pan.worst or 0) < GOAL_PAN_WORST))
local peak = 0
for _, p in ipairs(r.phases) do peak = math.max(peak, p.peak) end
lines[#lines + 1] = format(L.GOAL_TEXTURES, peak, Verdict(peak < GOAL_TEXTURES))
if r.scanMs then lines[#lines + 1] = format(L.BENCH_SCAN, r.scanMs, Verdict(r.scanMs < GOAL_SCAN)) end
if measured then
lines[#lines + 1] = format(L.GOAL_MEMORY, r.memory, Verdict(r.memory < GOAL_MEMORY))
else
lines[#lines + 1] = format(L.GOAL_MEMORY_NONE, L.TO_CHECK)
end
return table.concat(lines, "\n")
end
local function ShowResults(r)
if not results then CreateResults() end
results.text = Report(r)
resultsBox:SetText(results.text)
results:Show()
resultsBox:SetFocus()
resultsBox:HighlightText()
end
--------------------------------------------------------------------------------
-- Parcours
-- Le joueur en unités du canevas de sa vue, ou le milieu de la vue courante.
local function PlayerPoint()
local view, x, y = ns.UnitPos("player")
if view then
local k = 1000 / ns.VIEWS[view].size.w
return view, x * k, y * k
end
local name, _, _, _, w, h = ns.view.Get()
return name, w / 2, h / 2
end
local PHASES = {
{ key = "closed", time = 2, setup = function()
ns.view.Frame():Hide()
end },
-- 0,5 s d'attente : la réouverture de la carte n'est pas l'image immobile (#27).
{ key = "still", time = 3, warmup = 0.5, setup = function(b)
ns.Open()
local view, x, y = PlayerPoint()
ns.view.Show(view)
ns.view.Center(x, y, 6)
b.home = { view, x, y }
end },
-- Aller-retour, pour ne jamais buter sur un bord de la carte.
{ key = "pan", time = 4, step = function(b, dt, t)
local dir = (t % 2 < 1) and -1 or 1
ns.view.Pan(dir * 360 * dt, dir * 120 * dt)
end },
{ key = "zoom", time = 4, step = function(b, dt, t)
local z = 3 * (20 / 3) ^ ((1 - math.cos(t * math.pi / 2)) / 2)
ns.view.Center(b.home[2], b.home[3], z)
end },
{ key = "tour", time = 8, setup = function(b)
ns.view.Show("azeroth")
local _, _, _, _, w, h = ns.view.Get()
b.points = {}
for gy = 0.2, 0.8, 0.2 do
for gx = 0.1, 0.9, 0.2 do b.points[#b.points + 1] = { gx * w, gy * h } end
end
end, step = function(b, dt, t)
local p = b.points[math.min(#b.points, math.floor(t / 0.4) + 1)]
ns.view.Center(p[1], p[2], 6)
end },
{ key = "world", time = 2, setup = function()
local _, _, _, _, w, h = ns.view.Get()
ns.view.Center(w / 2, h / 2, ns.view.ZoomMin())
end },
}
local driver = CreateFrame("Frame")
driver:Hide()
local function Finish(b, cancelled)
driver:Hide()
bench, ns.benching = nil, nil
UpdateMeasuring()
local frame = ns.view.Frame()
if b.saved then
if not frame:IsShown() then ns.Open() end
ns.view.Show(b.saved[1])
ns.view.Center(b.saved[3], b.saved[4], b.saved[2])
end
if cancelled then
ns.Print(L.BENCH_STOPPED)
return
end
local r = { version = ns.version, time = time(), phases = b.results, memory = Memory(),
luaTotal = collectgarbage("count"), scanMs = ns.scanMs }
ns.db.lastBench = r
ns.Print(L.BENCH_DONE)
ShowResults(r)
end
local function StartPhase(b, i)
b.index, b.t, b.frames, b.warm = i, 0, 0, nil
b.peak = stats.files
ResetWindow()
local phase = PHASES[i]
if phase.setup then phase.setup(b) end
end
local function EndPhase(b)
local phase = PHASES[b.index]
b.results[#b.results + 1] = {
key = phase.key,
fps = b.t > 0 and b.frames / b.t or 0,
ms = stats.frames > 0 and stats.ms / stats.frames or nil,
worst = stats.frames > 0 and stats.worst or nil,
peak = b.peak,
warmup = phase.warmup,
}
end
driver:SetScript("OnUpdate", function(self, elapsed)
local b = bench
b.t, b.frames = b.t + elapsed, b.frames + 1
if stats.files > b.peak then b.peak = stats.files end
local phase = PHASES[b.index]
if phase.warmup and not b.warm then
if b.t < phase.warmup then return end
-- Fin de l'attente : la mesure de la phase commence ici.
b.warm, b.t, b.frames, b.peak = true, 0, 0, stats.files
ResetWindow()
return
end
if b.t >= phase.time then
EndPhase(b)
if b.index == #PHASES then return Finish(b) end
StartPhase(b, b.index + 1)
elseif phase.step then
ns.view.Stop()
phase.step(b, elapsed, b.t)
end
end)
function ns.Bench()
if bench then return Finish(bench, true) end
local frame = ns.view.Frame()
if not frame or not frame:IsShown() then ns.Open() end
if results then results:Hide() end
local name, z, cx, cy = ns.view.Get()
bench = { results = {}, saved = { name, z, cx, cy } }
ns.benching = true
UpdateMeasuring()
ns.view.Stop()
ns.Print(L.BENCH_RUNNING)
StartPhase(bench, 1)
driver:Show()
end