aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/lua
diff options
context:
space:
mode:
authorGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-07-19 18:54:04 +0000
committerGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-07-19 18:54:04 +0000
commit6645cde43d7dbf0df76dbda2c089d8f58560e3e2 (patch)
tree1664f8f52c69f9a7ef75e4d94cfa716f67554c7a /tools/lua
parentfc70a4ae593aec6bbaeb1b6573627328b2ef2ad0 (diff)
Fix build problem with reverted issue 16948011
BUG= R=caryclark@google.com Author: sglez@google.com Review URL: https://chromiumcodereview.appspot.com/19541009 git-svn-id: http://skia.googlecode.com/svn/trunk@10201 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tools/lua')
-rw-r--r--tools/lua/bbh_filter.lua148
1 files changed, 148 insertions, 0 deletions
diff --git a/tools/lua/bbh_filter.lua b/tools/lua/bbh_filter.lua
new file mode 100644
index 0000000000..73b530c7c7
--- /dev/null
+++ b/tools/lua/bbh_filter.lua
@@ -0,0 +1,148 @@
+-- bbh_filter.lua
+--
+-- This script outputs info about 'interesting' skp files,
+-- where the definition of 'interesting' changes but is roughly:
+-- "Interesting for bounding box hierarchy benchmarks."
+--
+-- Currently, the approach is to output, in equal ammounts, the names of the files that
+-- have most commands, and the names of the files that use the least popular commands.
+
+function count_entries(table)
+ local count = 0
+ for _,_ in pairs(table) do
+ count = count + 1
+ end
+ return count
+end
+
+verbCounts = {}
+
+function reset_current()
+ -- Data about the skp in transit
+ currentInfo = {
+ fileName = '',
+ verbs = {},
+ numOps = 0
+ }
+end
+reset_current()
+
+numOutputFiles = 10 -- This is per measure.
+globalInfo = {} -- Saves currentInfo for each file to be used at the end.
+output = {} -- Stores {fileName, {verb, count}} tables.
+
+function tostr(t)
+ local str = ""
+ for k, v in next, t do
+ if #str > 0 then
+ str = str .. ", "
+ end
+ if type(k) == "number" then
+ str = str .. "[" .. k .. "] = "
+ else
+ str = str .. tostring(k) .. " = "
+ end
+ if type(v) == "table" then
+ str = str .. "{ " .. tostr(v) .. " }"
+ else
+ str = str .. tostring(v)
+ end
+ end
+ return str
+end
+
+function sk_scrape_startcanvas(c, fileName) end
+
+function sk_scrape_endcanvas(c, fileName)
+ globalInfo[fileName] = currentInfo
+ globalInfo[fileName].fileName = fileName
+ reset_current()
+end
+
+function sk_scrape_accumulate(t)
+ -- dump the params in t, specifically showing the verb first, which we
+ -- then nil out so it doesn't appear in tostr()
+ --
+ verbCounts[t.verb] = (verbCounts[t.verb] or 0) + 1
+ currentInfo.verbs[t.verb] = (currentInfo.verbs[t.verb] or 0) + 1
+ currentInfo.numOps = currentInfo.numOps + 1
+
+ t.verb = nil
+end
+
+function sk_scrape_summarize()
+ verbWeights = {} -- {verb, weight}, where 0 < weight <= 1
+
+ meta = {}
+ for k,v in pairs(verbCounts) do
+ table.insert(meta, {key=k, value=v})
+ end
+ table.sort(meta, function (a,b) return a.value > b.value; end)
+ maxValue = meta[1].value
+ io.write("-- ==================\n")
+ io.write("------------------------------------------------------------------ \n")
+ io.write("-- Command\t\t\tNumber of calls\t\tPopularity\n")
+ io.write("------------------------------------------------------------------ \n")
+ for k, v in pairs(meta) do
+ verbWeights[v.key] = v.value / maxValue
+
+ -- Poor man's formatting:
+ local padding = "\t\t\t"
+ if (#v.key + 3) < 8 then
+ padding = "\t\t\t\t"
+ end
+ if (#v.key + 3) >= 16 then
+ padding = "\t\t"
+ end
+
+ io.write ("-- ",v.key, padding, v.value, '\t\t\t', verbWeights[v.key], "\n")
+ end
+
+ meta = {}
+ function calculate_weight(verbs)
+ local weight = 0
+ for name, count in pairs(verbs) do
+ weight = weight + (1 / verbWeights[name]) * count
+ end
+ return weight
+ end
+ for n, info in pairs(globalInfo) do
+ table.insert(meta, info)
+ end
+
+ local visitedFiles = {}
+
+ -- Prints out information in lua readable format
+ function output_with_metric(metric_func, description, numOutputFiles)
+ table.sort(meta, metric_func)
+ print(description)
+ local iter = 0
+ for i, t in pairs(meta) do
+ if not visitedFiles[t.fileName] then
+ visitedFiles[t.fileName] = true
+ io.write ("{\nname = \"", t.fileName, "\", \nverbs = {\n")
+ for verb,count in pairs(globalInfo[t.fileName].verbs) do
+ io.write(' ', verb, " = ", count, ",\n")
+ end
+ io.write("}\n},\n")
+
+ iter = iter + 1
+ if iter >= numOutputFiles then
+ break
+ end
+ end
+ end
+ end
+
+ output_with_metric(
+ function(a, b) return calculate_weight(a.verbs) > calculate_weight(b.verbs); end,
+ "\n-- ================== skps with calling unpopular commands.", 10)
+ output_with_metric(
+ function(a, b) return a.numOps > b.numOps; end,
+ "\n-- ================== skps with the most calls.", 50)
+
+ local count = count_entries(visitedFiles)
+
+ print ("-- Spat", count, "files")
+end
+