Quantcast

Make resources global, updated by timer widget

Scott Sibley [09-03-10 - 05:35]
Make resources global, updated by timer widget
Filename
Display.lua
config.lua
diff --git a/Display.lua b/Display.lua
index fea50b7..d1b3ea6 100644
--- a/Display.lua
+++ b/Display.lua
@@ -13,6 +13,10 @@ local WidgetHistogram = LibStub("StarLibWidgetHistogram-1.0")
 local WidgetKey = LibStub("StarLibWidgetKey-1.0")
 local WidgetTimer = LibStub("StarLibWidgetTimer-1.0")
 local LayoutOptions = LibStub("StarLibLayoutOptions-1.0")
+local Resources = LibStub("StarLibPluginResourceTools-1.0")
+
+local resources = {}
+Resources:New(resources)

 local _G = _G
 local GameTooltip = _G.GameTooltip
@@ -52,32 +56,45 @@ local blankOptions = {
 		end,
 		order = 2
 	},
-	scriptProfile = {
-		name = "Turn on CPU profiling",
-		type = "execute",
-		func = function()
-
-		end
-	},
 	displays = {
 		name = "Displays",
 		type = "group",
 		args = {},
-		order = 3
+		order = 40
 	},
 	layouts = {
 		name = "Layouts",
 		type = "group",
 		args = {},
-		order = 4
+		order = 41
 	},
 	widgets = {
 		name = "Widgets",
 		type = "group",
 		args = {},
-		order = 5
+		order = 42
 	}
 }
+if resources.scriptProfile then
+	blankOptions.scriptProfile = {
+		name = "Turn off CPU profiling",
+		type = "execute",
+		func = function()
+			SetCVar("scriptProfile", 0)
+			ReloadUI()
+		end
+	}
+else
+	blankOptions.scriptProfile = {
+		name = "Turn on CPU profiling",
+		type = "execute",
+		func = function()
+			SetCVar("scriptProfile", 1)
+			ReloadUI()
+		end,
+		order = 3
+	}
+end

 function mod:RebuildOpts()
 	options = copy(blankOptions)
@@ -248,7 +265,7 @@ function mod:RebuildOpts()
 			end
 			if v.widgets then
 				for i, widget in ipairs(v.widgets) do
-					options.displays.args[k:gsub(" ", "_")].args.widgets[widget] = {
+					options.displays.args[k:gsub(" ", "_")].args.widgets.args[widget] = {
 						name = widget,
 						type = "input",
 						get = function() return widget end,
diff --git a/config.lua b/config.lua
index 7fdd6f7..4f5cb24 100644
--- a/config.lua
+++ b/config.lua
@@ -36,16 +36,23 @@ LCD4WoW.config = {
 		["timeout"] = 7000,
 		["transition_speed"] = 50,
 		["widgets"] = {"widget_key_up", "widget_key_down", "widget_resources_timer"},
-		["layouts"] = {"layout_lcd4wow", "layout_histogram_mem"},
+		["layouts"] = {"layout_histogram_mem", "layout_histogram_cpu"},
     },
 	["widget_resources_timer"] = {
         type = "timer",
-		update = 3000,
+		update = 1000,
 		repeating = true,
 		expression = [[
 if ResourceServer then self.timer:Stop() return end
 UpdateMem()
 UpdateCPU()
+if not StarLibs then
+    cpu, percent, cpudiff, totalCPU, totaldiff = GetCPUUsage("LCD4WoW")
+    mem, percent, memdiff, totalMem, totaldiff = GetMemUsage("LCD4WoW")
+else
+    mem, percent, memdiff, totalMem, totaldiff = GetMemUsage("StarLibs-1.0")
+    cpu, percent, cpudiff, totalCPU, totaldiff = GetCPUUsage("StarLibs-1.0")
+end
 ]]
 	},
 	["layout_tiny"] = {
@@ -176,11 +183,6 @@ UpdateCPU()
 		type = "text",
 		value = [[
 --do return random(100) .. "%" end
-if not StarLibs then
-    mem = GetMemUsage("LCD4WoW")
-else
-    mem = GetMemUsage("StarLibs-1.0")
-end
 if mem then
     return memshort(tonumber(format("%.2f", mem)))
 end
@@ -193,11 +195,6 @@ end
 		type = "text",
 		value = [[
 --do return random(100) .. "%" end
-if not StarLibs then
-    mem, percent, memdiff, totalMem, totaldiff = GetMemUsage("LCD4WoW")
-else
-    mem, percent, memdiff, totalMem, totaldiff = GetMemUsage("StarLibs-1.0")
-end
 if mem then
     if totaldiff == 0 then totaldiff = 1 end
     return '-==MEM:: ' .. format("%.2f", memdiff / totaldiff * 100) .. "%" .. "::MEM==-"
@@ -214,11 +211,6 @@ end
 		type = "bar",
 		expression = [[
 --do return random(100) end
-if not StarLibs then
-    mem, percent, memdiff, totalMem, totaldiff = GetMemUsage("LCD4WoW")
-else
-    mem, percent, memdiff, totalMem, totaldiff = GetMemUsage("StarLibs-1.0")
-end
 if mem then
     if totaldiff == 0 then return 0 end
     return memdiff / totaldiff * 100
@@ -232,11 +224,6 @@ end
 		type = "histogram",
 		expression = [[
 do return random(100) end
-if not StarLibs then
-    mem, percent, memdiff, totalMem, totaldiff = GetMemUsage("LCD4WoW")
-else
-    mem, percent, memdiff, totalMem, totaldiff = GetMemUsage("StarLibs-1.0")
-end
 if mem then
     if totaldiff == 0 then return 0 end
     return memdiff / totaldiff * 100
@@ -260,11 +247,6 @@ end
 		type = "text",
 		value = [[
 --do return timeshort(random(10000)) end
-if not StarLibs then
-    cpu = GetCPUUsaage("LCD4WoW")
-else
-    cpu = GetCPUUsage("StarLibs-1.0")
-end
 if cpu then
     return timeshort(cpu)
 end
@@ -277,11 +259,6 @@ end
 		type = "bar",
 		expression = [[
 --do return random(100) end
-if not StarLibs then
-    cpu, percent, cpudiff, totalCPU, totaldiff = GetCPUUsage("LCD4WoW")
-else
-    cpu, percent, cpudiff, totalCPU, totaldiff = GetCPUUsage("StarLibs-1.0")
-end
 if cpu then
     if totaldiff == 0 then return 0 end
     return cpudiff / totaldiff * 100
@@ -295,11 +272,6 @@ end
 		type = "histogram",
 		expression = [[
 if not scriptProfile then return random(100) end
-if not StarLibs then
-    cpu, percent, cpudiff, totalCPU, totaldiff = GetCPUUsage("LCD4WoW")
-else
-    cpu, percent, cpudiff, totalCPU, totaldiff = GetCPUUsage("StarLibs-1.0")
-end
 if cpu then
     if totaldiff == 0 then return 0 end
     return cpudiff / totaldiff * 100
@@ -314,11 +286,6 @@ end
 		type = "text",
 		value = [[
 --do return format("------%d%%-------", random(100)) end
-if not StarLibs then
-    cpu, percent, cpudiff, totalCPU, totaldiff = GetCPUUsage("LCD4WoW")
-else
-    cpu, percent, cpudiff, totalCPU, totaldiff = GetCPUUsage("StarLibs-1.0")
-end
 if cpu then
     if totaldiff == 0 then totaldiff = 1 end
     return '-==CPU::' .. format("%.2f", cpudiff / totaldiff * 100) .. "%" .. "::CPU==-"