Quantcast

Allow the library to do the resource calculations.

Scott Sibley [09-14-10 - 10:21]
Allow the library to do the resource calculations.
Filename
Modules/Histograms.lua
Modules/Text.lua
Modules/UnitTooltip.lua
diff --git a/Modules/Histograms.lua b/Modules/Histograms.lua
index 2dc8c89..2731592 100644
--- a/Modules/Histograms.lua
+++ b/Modules/Histograms.lua
@@ -87,19 +87,15 @@ return PowerColor("RAGE", unit)
 		name = "Mem",
 		type = "histogram",
 		expression = [[
-local mem, percent, memdiff, totalMem, totaldiff = GetMemUsage("StarTip")
-
+local mem, percent, memdiff, totalMem, totaldiff, memperc = GetMemUsage("StarTip")
 if mem then
-    if totaldiff == 0 then totaldiff = 1 end
-    return memdiff / totaldiff * 100
+    return memperc
 end
 ]],
 		color = [[
-local mem, percent, memdiff, totalMem, totaldiff = GetMemUsage("StarTip")
+local mem, percent, memdiff, totalMem, totaldiff, memperc = GetMemUsage("StarTip")
 if mem then
-    if totaldiff == 0 then totaldiff = 1 end
-    memperc = (memdiff / totaldiff * 100)
-    local num = floor(memperc + 0.5)
+    local num = floor(memperc)
     if num < 1 then num = 1 end
     if num > 100 then num = 100 end
     local r, g, b = gradient[num][1], gradient[num][2], gradient[num][3]
@@ -123,17 +119,12 @@ end
 		name = "CPU",
 		type = "histogram",
 		expression = [[
-local cpu, percent, cpudiff, totalCPU, totaldiff = GetCPUUsage("StarTip")
-if cpu then
-    if totaldiff == 0 then totaldiff = .001 end
-    return cpudiff / totaldiff * 100
-end
+local cpu, percent, cpudiff, totalCPU, totaldiff, cpuperc = GetCPUUsage("StarTip")
+return cpuperc
 ]],
 		color = [[
-local cpu, percent, cpudiff, totalCPU, totaldiff = GetCPUUsage("StarTip")
+local cpu, percent, cpudiff, totalCPU, totaldiff, cpuperc = GetCPUUsage("StarTip")
 if cpu then
-    if totaldiff == 0 then totaldiff = 1 end
-    cpuperc = (cpudiff / totaldiff * 100)
     local num = floor(cpuperc)
     if num < 1 then num = 1 end
     if num > 100 then num = 100 end
diff --git a/Modules/Text.lua b/Modules/Text.lua
index d584367..25ab8f6 100644
--- a/Modules/Text.lua
+++ b/Modules/Text.lua
@@ -116,11 +116,9 @@ return HPColor(mana, max)
 		name = "Memory Percent",
 		enabled = false,
 		value = [[
-local mem, percent, memdiff, totalMem, totaldiff = GetMemUsage("StarTip")
+local mem, percent, memdiff, totalMem, totaldiff, memperc = GetMemUsage("StarTip")
 if mem then
-    if totaldiff == 0 then totaldiff = 1 end
-    memperc = (memdiff / totaldiff * 100)
-    local num = floor(memperc + 0.5)
+    local num = floor(memperc)
     if num < 1 then num = 1 end
     if num > 100 then num = 100 end
     local r, g, b = gradient[num][1], gradient[num][2], gradient[num][3]
@@ -128,11 +126,9 @@ if mem then
 end
 ]],
 		color = [[
-local mem, percent, memdiff, totalMem, totaldiff = GetMemUsage("StarTip")
+local mem, percent, memdiff, totalMem, totaldiff, memperc = GetMemUsage("StarTip")
 if mem then
-    if totaldiff == 0 then totaldiff = 1 end
-    memperc = (memdiff / totaldiff * 100)
-    local num = floor(memperc + 0.5)
+    local num = floor(memperc)
     if num < 1 then num = 1 end
     if num > 100 then num = 100 end
     local r, g, b = gradient[num][1], gradient[num][2], gradient[num][3]
@@ -150,13 +146,8 @@ end
 		name = "Memory Total",
 		enabled = false,
 		value = [[
-local mem, percent, memdiff, totalMem, totaldiff = GetMemUsage("StarTip")
+local mem, percent, memdiff, totalMem, totaldiff, memperc = GetMemUsage("StarTip")
 if mem then
-    if totaldiff == 0 then totaldiff = 1 end
-    memperc = (mem / totalMem * 100)
-    local num = floor(memperc + 0.5)
-    if num < 1 then num = 1 end
-    if num > 100 then num = 100 end
     return format("%s (%.2f%%)", memshort(mem), memperc)
 end
 ]],
@@ -173,22 +164,14 @@ return 1, 1, 0
 		name = "CPU Percent",
 		enabled = false,
 		value = [[
-local cpu, percent, cpudiff, totalCPU, totaldiff = GetCPUUsage("StarTip")
+local cpu, percent, cpudiff, totalCPU, totaldiff, cpuperc = GetCPUUsage("StarTip")
 if cpu then
-    if totaldiff == 0 then totaldiff = 100 end
-    cpuperc = cpudiff / totaldiff * 100;
-    local num = floor(cpuperc + 0.5)
-    if num < 1 then num = 1 end
-    if num > 100 then num = 100 end
-    local r, g, b = gradient[num][1], gradient[num][2], gradient[num][3]
     return format("CPU: %.2f%%", cpuperc)
 end
 ]],
 		color = [[
-local cpu, percent, cpudiff, totalCPU, totaldiff = GetCPUUsage("StarTip")
+local cpu, percent, cpudiff, totalCPU, totaldiff, cpuperc = GetCPUUsage("StarTip")
 if cpu then
-    if totaldiff == 0 then totaldiff = 1 end
-    cpuperc = (cpudiff / totaldiff * 100)
     local num = floor(cpuperc)
     if num < 1 then num = 1 end
     if num > 100 then num = 100 end
@@ -209,7 +192,7 @@ end
 		value = [[
 local cpu, percent, cpudiff, totalCPU, totaldiff = GetCPUUsage("StarTip")
 if cpu then
-    if totalCPU == 0 then totalCPU = 100 end
+    if totalCPU == 0 then totalCPU = 100; cpu = 0 end
     cpuperc = cpu / totalCPU * 100;
     return format("%s (%.2f%%)", timeshort(cpu), cpuperc)
 end
diff --git a/Modules/UnitTooltip.lua b/Modules/UnitTooltip.lua
index 40fcc8d..21a72bc 100644
--- a/Modules/UnitTooltip.lua
+++ b/Modules/UnitTooltip.lua
@@ -294,13 +294,12 @@ return value
 		name = "Memory Usage",
 		left = "return 'Memory Usage:'",
 		right = [[
-local mem, percent, memdiff, totalMem, totaldiff = GetMemUsage("StarTip")
+local mem, percent, memdiff, totalMem, totaldiff, memperc = GetMemUsage("StarTip")
 if mem then
-    if totaldiff == 0 then totaldiff = 1 end
-    memperc = (memdiff / totaldiff * 100)
-    local num = floor(memperc + 0.5)
+    local num = floor(memperc)
     if num < 1 then num = 1 end
     if num > 100 then num = 100 end
+	assert(gradient[num], format("%d", num))
     local r, g, b = gradient[num][1], gradient[num][2], gradient[num][3]
     return GetColorCode(format("%s (%.2f%%)", memshort(mem), memperc), r, g, b)
 end
@@ -313,11 +312,9 @@ end
 		desc = "Note that you must turn on CPU profiling",
 		left = 'return "CPU Usage:"',
 		right = [[
-local cpu, percent, cpudiff, totalCPU, totaldiff = GetCPUUsage("StarTip")
+local cpu, percent, cpudiff, totalCPU, totaldiff, cpuperc = GetCPUUsage("StarTip")
 if cpu then
-    if totaldiff == 0 then totaldiff = 100 end
-    cpuperc = cpudiff / totaldiff * 100;
-    local num = floor(cpuperc + 0.5)
+    local num = floor(cpuperc)
     if num < 1 then num = 1 end
     if num > 100 then num = 100 end
     local r, g, b = gradient[num][1], gradient[num][2], gradient[num][3]
@@ -486,8 +483,10 @@ function mod:CreateLines()
     end
     lines = setmetatable(llines, {__call=function(self)
 		--@debug@
-		PluginResources.Update()
-		local mem, percent, memdiff, totalMem, totaldiff = PluginResources.GetMemUsage("StarTip")
+		if debugging then
+			PluginResources.Update()
+			local mem, percent, memdiff, totalMem, totaldiff = PluginResources.GetMemUsage("StarTip")
+		end
 		--@end-debug@
         local lineNum = 0
 		GameTooltip:ClearLines()
@@ -551,9 +550,11 @@ function mod:CreateLines()
         end
         mod.NUM_LINES = lineNum
 		--@debug@
-		PluginResources.Update()
-		local mem2, percent2, memdiff2, totalMem2, totaldiff2 = PluginResources.GetMemUsage("StarTip")
-		--StarTip:Print("Memory: ", plugin.memshort(mem2 - mem))
+		if debugging then
+			PluginResources.Update()
+			local mem2, percent2, memdiff2, totalMem2, totaldiff2 = PluginResources.GetMemUsage("StarTip")
+			StarTip:Print("Memory: ", plugin.memshort(mem2 - mem))
+		end
 		--@end-debug@
 		draw()
 		GameTooltip:Show()