OLD | NEW |
---|---|
(Empty) | |
1 -- bbh_filter.lua | |
2 -- | |
3 -- This script outputs info about 'interesting' skp files, | |
4 -- where the definition of 'interesting' changes but is roughly: | |
5 -- "Interesting for bounding box hierarchy benchmarks." | |
6 -- | |
7 -- Currently, the approach is to output, in equal ammounts, the names of the fil es that | |
8 -- have most commands, and the names of the files that use the least popular com mands. | |
reed1
2013/07/12 13:24:29
Since you seem to be tracking glyphs (why?) should
sglez
2013/07/13 03:57:15
Vestige of something that I thought was needed. Re
| |
9 | |
10 | |
11 verbCounts = {} | |
12 | |
13 function reset_current() | |
14 -- Data about the skp in transit | |
15 currentInfo = { | |
16 fileName = '', | |
17 verbs = {}, | |
18 glyphs = {}, | |
19 numOps = 0 | |
20 } | |
21 end | |
22 reset_current() | |
23 | |
24 numOutputFiles = 10 -- This is per measure. | |
25 globalInfo = {} -- Saves currentInfo for each file to be used at the end. | |
26 output = {} -- Stores {fileName, {verb, count}} tables. | |
27 | |
28 function tostr(t) | |
29 local str = "" | |
30 for k, v in next, t do | |
31 if #str > 0 then | |
32 str = str .. ", " | |
33 end | |
34 if type(k) == "number" then | |
35 str = str .. "[" .. k .. "] = " | |
36 else | |
37 str = str .. tostring(k) .. " = " | |
38 end | |
39 if type(v) == "table" then | |
40 str = str .. "{ " .. tostr(v) .. " }" | |
41 else | |
42 str = str .. tostring(v) | |
43 end | |
44 end | |
45 return str | |
46 end | |
47 | |
48 function sk_scrape_startcanvas(c, fileName) end | |
49 | |
50 function sk_scrape_endcanvas(c, fileName) | |
51 globalInfo[fileName] = currentInfo | |
52 globalInfo[fileName].fileName = fileName | |
53 reset_current() | |
54 end | |
55 | |
56 function sk_scrape_accumulate(t) | |
57 -- dump the params in t, specifically showing the verb first, which we | |
58 -- then nil out so it doesn't appear in tostr() | |
59 -- | |
60 verbCounts[t.verb] = (verbCounts[t.verb] or 0) + 1 | |
61 currentInfo.verbs[t.verb] = (currentInfo.verbs[t.verb] or 0) + 1 | |
62 if t.verb == "drawPosTextH" then | |
63 for k, glyph in pairs(t.glyphs) do | |
64 currentInfo.glyphs[glyph] = (currentInfo[glyph] or 0) + 1 | |
65 end | |
66 --io.write("--INFO\n") | |
67 end | |
68 currentInfo.numOps = currentInfo.numOps + 1 | |
69 | |
70 t.verb = nil | |
71 end | |
72 | |
73 function sk_scrape_summarize() | |
74 verbWeights = {} -- {verb, weight}, where 0 < weight <= 1 | |
75 | |
76 meta = {} | |
77 for k,v in pairs(verbCounts) do | |
78 table.insert(meta, {key=k, value=v}) | |
79 end | |
80 table.sort(meta, function (a,b) return a.value > b.value; end) | |
81 maxValue = meta[1].value | |
82 io.write("-- ==================\n") | |
83 io.write("------------------------------------------------------------------ \n") | |
84 io.write("-- Command\t\t\tNumber of calls\t\tPopularity\n") | |
85 io.write("------------------------------------------------------------------ \n") | |
86 for k, v in pairs(meta) do | |
87 verbWeights[v.key] = v.value / maxValue | |
88 | |
89 -- Poor man's formatting: | |
90 local padding = "\t\t\t" | |
91 if (#v.key + 3) < 8 then | |
92 padding = "\t\t\t\t" | |
93 end | |
94 if (#v.key + 3) >= 16 then | |
95 padding = "\t\t" | |
96 end | |
97 | |
98 io.write ("-- ",v.key, padding, v.value, '\t\t\t', verbWeights[v.key], " \n") | |
99 end | |
100 | |
101 meta = {} | |
102 function calculate_weight(verbs) | |
103 local weight = 0 | |
104 for name, count in pairs(verbs) do | |
105 weight = weight + (1 / verbWeights[name]) * count | |
106 end | |
107 return weight | |
108 end | |
109 for n, info in pairs(globalInfo) do | |
110 table.insert(meta, info) | |
111 end | |
112 | |
113 local visitedFiles = {} | |
114 | |
115 -- Prints out information in lua readable format | |
116 function output_with_metric(metric_func, description) | |
117 maxNumGlyphs = -1 | |
118 table.sort(meta, metric_func) | |
119 print(description) | |
120 local iter = 0 | |
121 for i, t in pairs(meta) do | |
122 if not visitedFiles[t.fileName] then | |
123 visitedFiles[t.fileName] = true | |
124 io.write ("{\nname = \"", t.fileName, "\", \nverbs = {\n") | |
125 for verb,count in pairs(globalInfo[t.fileName].verbs) do | |
126 io.write(' ', verb, " = ", count, ",\n") | |
127 end | |
128 | |
129 glyphCount = 0 | |
130 for _,g in pairs(globalInfo[t.fileName].glyphs) do glyphCount = glyphCount + 1 end | |
reed1
2013/07/12 13:24:29
perhaps we write a global helper function called c
sglez
2013/07/13 03:57:15
Deleted this along with the rest of the glyph code
| |
131 if glyphCount > maxNumGlyphs then | |
132 maxNumGlyphs = glyphCount | |
133 end | |
134 --io.write("glyphs={") | |
135 for glyph, count in pairs(globalInfo[t.fileName].glyphs) do | |
136 --io.write(glyph, ', ') | |
137 end | |
138 --io.write("}\n") | |
139 io.write("\t},\n") | |
reed1
2013/07/12 13:24:29
Can these multiple io.write calls be smashed into
| |
140 io.write("numGlyphs = ", glyphCount, ",\n") | |
141 io.write("},\n") | |
142 iter = iter + 1 | |
143 if iter >= numOutputFiles then | |
144 break | |
145 end | |
146 end | |
147 end | |
148 io.write("-- max: ", maxNumGlyphs, "\n") | |
149 end | |
150 | |
151 output_with_metric( | |
152 function(a, b) return calculate_weight(a.verbs) > calculate_weight(b.ver bs); end, | |
153 "\n-- ================== skps with calling unpopular commands.") | |
154 output_with_metric( | |
155 function(a, b) return a.numOps > b.numOps; end, | |
156 "\n-- ================== skps with the most calls.") | |
157 | |
158 local count = 0 | |
159 for _,_ in pairs(visitedFiles) do count = count + 1 end | |
160 print ("-- Spat", count, "files") | |
161 end | |
162 | |
OLD | NEW |