r32998 - trunk/Expo/modules

0 views
Skip to first unread message

svnco...@wowace.com

unread,
Apr 18, 2007, 10:17:12 AM4/18/07
to wowace-gar...@googlegroups.com
Author: jjsheets
Date: Wed Apr 18 10:17:11 2007
New Revision: 32998

Log:
Expo - Added options to Profile Addons, Libraries, and Classes, each of which set up the profiler correctly, use these instead of the generic profiler as a general rule. Expo now sorts all 'profilers' together, and has a slightly cleaner display. AddOns with modules will properly have the modules profiled also when using the New Addon Profiler... Configuration option.

Modified:
trunk/Expo/modules/Profiler.lua

Modified: trunk/Expo/modules/Profiler.lua
==============================================================================
--- trunk/Expo/modules/Profiler.lua (original)
+++ trunk/Expo/modules/Profiler.lua Wed Apr 18 10:17:11 2007
@@ -7,7 +7,10 @@
L:RegisterTranslations("enUS", function() return {
["Profiler"] = true,
["Configure..."] = true,
- ['New Profiler...'] = true,
+ ['New Generic Profiler...'] = true,
+ ['New AddOn Profiler...'] = true,
+ ['New Library Profiler...'] = true,
+ ['New Class Profiler...'] = true,
['Delete Profiler...'] = true,
['Sort by time'] = true,
['Sort by time/call'] = true,
@@ -32,6 +35,8 @@
local times = {}
local timepers = {}
local calls = {}
+local headings = {}
+local shorts = {}
local sorts = {
time = function(alpha, bravo)
if times[alpha] ~= times[bravo] then
@@ -82,7 +87,7 @@
end,
}

-local function wrap(value, name)
+local function wrap(value, name, heading, short)
if type(value) == "function" then
local oldFunction = value
prefuncs[name] = value
@@ -90,6 +95,8 @@
times[name] = 0
timepers[name] = 0
calls[name] = 0
+ headings[name] = heading
+ shorts[name] = short or name
local function func(pos, t, mem, ...)
mem, t = collectgarbage('count') - mem, GetTime() - t
if pos > 0 then
@@ -117,7 +124,7 @@
elseif type(value) == "table" then
for k, v in pairs(value) do
if type(k) == "string" and type(v) == "function" and v ~= wrap then
- value[k] = wrap(v, name .. ':' .. k)
+ value[k] = wrap(v, name .. '.' .. k,heading,':'..k)
end
end
return value
@@ -132,13 +139,15 @@
times[name] = nil
timepers[name] = nil
calls[name] = nil
+ --DEFAULT_CHAT_FRAME:AddMessage("unwrapped "..name)
return ret
elseif type(value) == "table" then
for k, v in pairs(value) do
if type(k) == "string" and type(v) == "function" and v ~= wrap then
- value[k] = unwrap(name .. ':' .. k,v)
+ value[k] = unwrap(name .. '.' .. k,v)
end
end
+ --DEFAULT_CHAT_FRAME:AddMessage("unwrapped "..name)
return value
end
end
@@ -172,6 +181,8 @@
self.db = Expo:AcquireDBNamespace("Profiler")
db = self.db.account
db.wraps = db.wraps or {}
+ db.display = db.display or {}
+ db.virtual = db.virtual or {}
db.currentSort = db.currentSort or 'time'
-- Wrap the functions and tables.
for i,curWrap in ipairs(db.wraps) do
@@ -199,10 +210,12 @@
function mod:GetRevision() return self.revision end
function mod:GetDisplayName() return L["Profiler"] end

-function mod:TrackNewWrap(newWrap)
+function mod:TrackNewWrap(newWrap,displayName)
local value = getdeep(newWrap)
if type(value) == 'function' or type(value) == 'table' then
- wrap(value,newWrap,GetTime())
+ displayName = displayName or newWrap
+ wrap(value,newWrap,displayName)
+ db.display[newWrap] = displayName
db.wraps[#db.wraps + 1] = newWrap
end
end
@@ -213,6 +226,7 @@
tunwrap = unwrap
RunScript(name.." = tunwrap('"..name.."',"..name..")")
tunwrap = preunwrap
+ db.display[name] = nil
table_remove(db.wraps,wrapIndex)
end

@@ -220,10 +234,15 @@
function mod:GetData(cat)
-- add line to add and remove events
cat:AddLine(
- 'text', L["Configure..."],
- 'textR', 0.6,
- 'textG', 0.6,
- 'textB', 1,
+ 'text', " ",
+ 'text2', " ",
+ 'text3', " ",
+ 'text4', " ",
+ 'text5', " ",
+ 'text6', L["Configure..."],
+ 'text6R', 0.6,
+ 'text6G', 0.6,
+ 'text6B', 1,
'func',function() self:PopupConfigureMenu() end
)
cat:AddLine(
@@ -234,25 +253,33 @@
'text5', "Time/Call",
'text6', "Memory/Call"
)
- local t = self:new()
- for method in pairs(memories) do
- t[#t+1] = method
- end
- table.sort(t, sorts[db.currentSort])
- for _,method in ipairs(t) do
- if calls[method] > 0 then
- cat:AddLine(
- 'text', method,
- 'text2', ("%.3f s"):format(times[method]),
- 'text3', ("%.3f KiB"):format(memories[method]),
- 'text4', ("%dx"):format(calls[method]),
- 'text5', ("%.3f ms"):format(times[method] / calls[method] * 1000),
- 'text6', ("%.3f KiB"):format(memories[method] / calls[method]),
- 'func', function() end
- )
+ for k,v in pairs(db.display) do
+ cat:AddLine(
+ 'text', v
+ )
+ local t = self:new()
+ for method,hdng in pairs(headings) do
+ if hdng == v then
+ t[#t+1] = method
+ end
end
+ table.sort(t, sorts[db.currentSort])
+ for _,method in ipairs(t) do
+ if calls[method] > 0 then
+ cat:AddLine(
+ 'text', shorts[method],
+ 'text2', ("%.3f s"):format(times[method]),
+ 'text3', ("%.3f KiB"):format(memories[method]),
+ 'text4', ("%dx"):format(calls[method]),
+ 'text5', ("%.3f ms"):format(times[method] / calls[method] * 1000),
+ 'text6', ("%.3f KiB"):format(memories[method] / calls[method]),
+ 'func', function() end,
+ 'indentation',10
+ )
+ end
+ end
+ self:del(t)
end
- self:del(t)
end

function mod:PopupConfigureMenu()
@@ -260,13 +287,44 @@
dewdrop:Close()
dewdrop:Open("Expo_Profiler",'children',function(level,v,v_1,v_2,v_3,v_4)
if level == 1 then
- dewdrop:AddLine('text',L['New Profiler...'],
+ dewdrop:AddLine('text',L['New Generic Profiler...'],
'hasArrow',true,
'hasEditBox',true,
'editBoxFunc',function(newValue) self:TrackNewWrap(newValue) self.core:UpdateTooltip() end,
'tooltipTitle','Common Patterns:',
'tooltipText','AceLibrary("MyClass-1.0").prototype\nAceLibrary("MyAddon-1.0")'
)
+ dewdrop:AddLine('text',L['New AddOn Profiler...'],
+ 'hasArrow',true,
+ 'hasEditBox',true,
+ 'editBoxFunc',function(newValue)
+ self:TrackNewWrap(newValue,'AddOn: '..newValue)
+ local v = getdeep(newValue)
+ if v and type(v.IterateModules) == 'function' then
+ for name, module in v:IterateModules() do
+ self:TrackNewWrap(newValue..':GetModule("'..name..'")',newValue..' Module: '..name)
+ db.virtual[newValue..':GetModule("'..name..'")'] = newValue
+ end
+ end
+ self.core:UpdateTooltip()
+ end,
+ 'tooltipTitle','Common Patterns:',
+ 'tooltipText','AceLibrary("MyClass-1.0").prototype\nAceLibrary("MyAddon-1.0")'
+ )
+ dewdrop:AddLine('text',L['New Library Profiler...'],
+ 'hasArrow',true,
+ 'hasEditBox',true,
+ 'editBoxFunc',function(newValue) self:TrackNewWrap('AceLibrary("'..newValue..'")','Library: '..newValue) self.core:UpdateTooltip() end,
+ 'tooltipTitle','Common Patterns:',
+ 'tooltipText','AceLibrary("MyClass-1.0").prototype\nAceLibrary("MyAddon-1.0")'
+ )
+ dewdrop:AddLine('text',L['New Class Profiler...'],
+ 'hasArrow',true,
+ 'hasEditBox',true,
+ 'editBoxFunc',function(newValue) self:TrackNewWrap('AceLibrary("'..newValue..'").prototype','Class: '..newValue) self.core:UpdateTooltip() end,
+ 'tooltipTitle','Common Patterns:',
+ 'tooltipText','AceLibrary("MyClass-1.0").prototype\nAceLibrary("MyAddon-1.0")'
+ )
dewdrop:AddLine('text',L['Delete Profiler...'],
'hasArrow',true,'value','DeleteWraps')
dewdrop:AddLine('text','')
@@ -288,9 +346,26 @@
elseif level == 2 and v == 'DeleteWraps' then
local no = true
for i,wrap in ipairs(db.wraps) do
- dewdrop:AddLine('text',wrap,
- 'func',function() self:UntrackWrap(i) self.core:UpdateTooltip() end)
- no = nil
+ if not db.virtual[wrap] then
+ dewdrop:AddLine('text',db.display[wrap],
+ 'func',function()
+ local v = getdeep(wrap)
+ if v and type(v.IterateModules) == 'function' then
+ for name, module in v:IterateModules() do
+ unwrap(wrap..':GetModule("'..name..'")',module)
+ db.virtual[wrap..':GetModule("'..name..'")'] = nil
+ db.display[wrap..':GetModule("'..name..'")'] = nil
+ for i,v in ipairs(db.wraps) do if v == wrap..':GetModule("'..name..'")' then
+ table_remove(db.wraps,i)
+ break
+ end end
+ end
+ end
+ self:UntrackWrap(i)
+ self.core:UpdateTooltip()
+ end)
+ no = nil
+ end
end
if no then
dewdrop:AddLine('text',L['No Profilers Currently Tracked'])

Reply all
Reply to author
Forward
0 new messages