8 from xml
.dom
import minidom
16 A 'structure' representing the results of a test.
18 def __init__(self
, x_label
, y_label
, cntnr_list
, cntnr_descs
, res_sets
):
19 self
.x_label
= x_label
20 self
.y_label
= y_label
21 self
.cntnr_list
= cntnr_list
22 self
.cntnr_descs
= cntnr_descs
23 self
.res_sets
= res_sets
28 This class returns a res object for some test.
31 def __accum(self
, results
):
33 for result
in results
:
34 total
= total
+ result
[1]
37 def sort(self
, cntnr_list
, res_sets
):
38 cntnrs_and_totals
= []
39 for cntnr
in cntnr_list
:
40 results
= res_sets
[cntnr
]
41 total
= self
.__accum
(results
)
42 cntnrs_and_totals
.append((cntnr
, total
))
43 by_total
= lambda x
,y
: x
[1] > y
[1] and -1 or 1
44 cntnrs_and_totals
.sort(by_total
)
46 for cntnr_and_total
in cntnrs_and_totals
:
47 cntnr
= cntnr_and_total
[0]
51 def __init__(self
, test_infos_f_name
):
52 self
.__test
_to
_container
_res
_sets
= {}
53 self
.__test
_to
_f
_names
= {}
54 tests_dat
= minidom
.parse(test_infos_f_name
)
55 for test
in tests_dat
.getElementsByTagName('test'):
56 test_name
= test
.attributes
['name'].value
57 self
.__test
_to
_f
_names
[test_name
] = test
.getElementsByTagName('file')[0].attributes
['name'].value
59 for cntnr
in test
.getElementsByTagName('cntnr'):
60 cntnr_list
.append(cntnr
.attributes
['name'].value
)
61 self
.__test
_to
_container
_res
_sets
[test_name
] = cntnr_list
63 def __get_label(self
, tst_dat
, label_name
):
64 label
= tst_dat
.getElementsByTagName(label_name
)[0].firstChild
.data
65 label
= string
.strip(label
, '\n')
66 label
= string
.strip(label
)
69 def __parse_result_sets(self
, f_name
, cntnr_list
):
70 tst_dat
= minidom
.parse(f_name
)
71 x_label
= self
.__get
_label
(tst_dat
, 'x_name')
72 y_label
= self
.__get
_label
(tst_dat
, 'y_name')
73 parsed_container_list
= tst_dat
.getElementsByTagName('cntnr')
76 for cntnr
in parsed_container_list
:
77 cntnr_name
= cntnr
.attributes
["name"].value
78 res_sets
[cntnr_name
] = []
79 for cntnr
in parsed_container_list
:
80 cntnr_name
= cntnr
.attributes
["name"].value
81 cntnr_desc
= cntnr
.getElementsByTagName('desc')
82 if res_sets
.has_key(cntnr_name
):
84 result_list
= cntnr
.getElementsByTagName('result')
85 for result
in result_list
:
86 x
= string
.atol(result
.attributes
["x"].value
)
87 y
= string
.atof(result
.attributes
["y"].value
)
88 res_set
.append((x
, y
))
89 res_sets
[cntnr_name
] = res_set
90 cntnr_descs
[cntnr_name
] = cntnr_desc
[0]
91 return (x_label
, y_label
, cntnr_descs
, res_sets
)
93 def get(self
, res_dir
, test_name
):
94 cntnr_list
= self
.__test
_to
_container
_res
_sets
[test_name
]
95 f_name
= res_dir
+ '/' + self
.__test
_to
_f
_names
[test_name
]
96 parsed
= self
.__parse
_result
_sets
(f_name
, cntnr_list
)
99 cntnr_descs
= parsed
[2]
101 cntnr_list
= self
.__sorter
().sort(cntnr_list
, res_sets
)
102 return res(x_label
, y_label
, cntnr_list
, cntnr_descs
, res_sets
)
107 This class creates a svg file from a result set.
109 class __style_chooser
:
111 self
.native_re
= re
.compile(r
'n_(?:.*?)')
113 self
.native_tick_mark_0
= tick_mark
.blackdtri
114 self
.native_tick_mark_1
= tick_mark
.blackdia
115 self
.native_line_style_0
= line_style
.gray50_dash1
116 self
.native_line_style_1
= line_style
.gray50_dash2
118 self
.mask_re
= re
.compile(r
'mask(?:.*?)')
119 self
.mod_re
= re
.compile(r
'mod(?:.*?)')
121 self
.rb_tree_mmap_rb_tree_set_re
= re
.compile(r
'rb_tree_mmap_rb_tree_set(?:.*?)')
122 self
.rb_tree_mmap_lu_mtf_set_re
= re
.compile(r
'rb_tree_mmap_lu_mtf_set(?:.*?)')
124 self
.splay_re
= re
.compile(r
'splay(?:.*?)')
125 self
.rb_tree_re
= re
.compile(r
'rb_tree(?:.*?)')
126 self
.ov_tree_re
= re
.compile(r
'ov_tree(?:.*?)')
127 self
.splay_tree_re
= re
.compile(r
'splay_tree(?:.*?)')
129 self
.pat_trie_re
= re
.compile(r
'pat_trie(?:.*?)')
131 self
.lc_1div8_1div2_re
= re
.compile(r
'lc_1div8_1div2(?:.*?)')
132 self
.lc_1div8_1div1_re
= re
.compile(r
'lc_1div8_1div1(?:.*?)')
133 self
.mcolc_1div2_re
= re
.compile(r
'mcolc_1div2(?:.*?)')
135 def choose(self
, cntnr
):
136 if self
.native_re
.search(cntnr
):
137 if cntnr
== 'n_pq_vector':
138 return (self
.native_tick_mark_1
, self
.native_line_style_1
)
140 return (self
.native_tick_mark_0
, self
.native_line_style_0
)
142 # tick_mark predefined
143 # square, circle3, dia, tri, dtri, star, plus5, x5, gray70dia, blackdtri, blackdia
144 if self
.mask_re
.search(cntnr
):
146 elif self
.mod_re
.search(cntnr
):
148 elif self
.rb_tree_mmap_rb_tree_set_re
.search(cntnr
):
149 clr
= color
.mediumblue
150 tm
= tick_mark
.square
151 elif self
.rb_tree_mmap_lu_mtf_set_re
.search(cntnr
) or cntnr
== 'rc_binomial_heap':
154 elif self
.splay_tree_re
.search(cntnr
) or cntnr
== 'binomial_heap':
157 elif self
.rb_tree_re
.search(cntnr
) or cntnr
== 'binary_heap':
160 elif self
.ov_tree_re
.search(cntnr
) or cntnr
== 'thin_heap':
161 clr
= color
.orangered1
163 elif self
.pat_trie_re
.search(cntnr
) or cntnr
== 'pairing_heap':
164 clr
= color
.blueviolet
167 sys
.stderr
.write(cntnr
+ '\n')
171 if cntnr
.find('lc_1div8_1div') <> -1:
172 if cntnr
.find('mask') <> -1:
174 if self
.lc_1div8_1div2_re
.search(cntnr
):
175 if cntnr
.find('nsth') <> -1:
178 tm
= tick_mark
.gray70dia
179 if self
.lc_1div8_1div1_re
.search(cntnr
):
180 if cntnr
.find('nsth') <> -1:
183 tm
= tick_mark
.circle3
186 if self
.lc_1div8_1div2_re
.search(cntnr
):
187 if cntnr
.find('nsth') <> -1:
190 tm
= tick_mark
.square
191 if self
.lc_1div8_1div1_re
.search(cntnr
):
192 if cntnr
.find('nsth') <> -1:
197 if self
.mcolc_1div2_re
.search(cntnr
):
198 tm
= tick_mark
.circle3
200 return (tm
, line_style
.T(color
= clr
, width
= 2))
204 self
.__sc
= self
.__style
_chooser
()
205 self
.__mmap
_re
= re
.compile('mmap_')
207 def __container_label_name(self
, cntnr
):
208 return self
.__mmap
_re
.sub('\nmmap_\n', cntnr
)
210 def make(self
, res
, of_name
):
214 theme
.debug_level
= 3
215 theme
.output_format
= 'svg'
216 theme
.scale_factor
= 2
217 theme
.default_line_width
= 0.5
218 theme
.default_font_size
= 8
223 f
= file(of_name
, "w")
224 can
= canvas
.init(f
, "svg")
227 y_tick_interval
= self
.__get
_y
_tics
(res
)
228 xaxis
= axis
.X(format
= "/6/i/a-90{}%d",
230 label
= res
.x_label
, label_offset
= (0, -20))
231 yaxis
= axis
.Y(format
= "/6/i/a0{}%.2e",
232 tic_interval
= y_tick_interval
, tic_label_offset
= (-25, 0),
233 label
= res
.y_label
, label_offset
= (-15, 0))
236 legend_lines
= len(res
.cntnr_list
)
237 legend_vloc
= 80 + (legend_lines
* 10)
239 lg
= legend
.T(loc
=(legend_hloc
,-legend_vloc
),
240 frame_line_style
= None, inter_row_sep
= 2)
243 ar
= area
.T(x_axis
= xaxis
, y_axis
= yaxis
, legend
= lg
, size
= (240,110), x_range
= (0, 2200))
245 for cntnr
in res
.cntnr_list
:
246 style
= self
.__sc
.choose(cntnr
)
247 pl
= line_plot
.T(label
= self
.__container
_label
_name
(cntnr
),
248 data
= res
.res_sets
[cntnr
],
249 tick_mark
= style
[0],
250 line_style
= style
[1])
253 for plot
in plot_list
:
261 def __get_y_max_min(self
, res
):
264 for cntnr
in res
.cntnr_list
:
265 m
= max(d
[1] for d
in res
.res_sets
[cntnr
])
267 n
= min(d
[1] for d
in res
.res_sets
[cntnr
])
271 def __get_x_max_min(self
, res
):
274 for cntnr
in res
.cntnr_list
:
275 m
= max(d
[0] for d
in res
.res_sets
[cntnr
])
277 n
= min(d
[0] for d
in res
.res_sets
[cntnr
])
281 def __get_y_tics(self
, res
):
283 for cntnr
in res
.cntnr_list
:
284 m
= max(d
[1] for d
in res
.res_sets
[cntnr
])
289 def main(test_infos_f_name
, res_dir
, doc_dir
):
290 xmls_dat
= minidom
.parse(test_infos_f_name
)
291 for test
in xmls_dat
.getElementsByTagName('test'):
294 test_name
= test
.attributes
['name'].value
295 res_gtr
= res_getter(test_infos_f_name
)
296 res
= res_gtr
.get(res_dir
, test_name
)
299 image_mkr
= image_maker()
300 svg_of_name
= doc_dir
+ '/pbds_' + test_name
+ '.svg'
301 image_mkr
.make(res
, svg_of_name
)
303 if __name__
== "__main__":
305 This module takes 3 parameters from the command line:
306 Tests info XML file name
307 Test results directory
308 Image output directory
310 usg
= "make_graph.py <test_info_file> <res_dir> <image_dir>\n"
311 if len(sys
.argv
) != 4:
312 sys
.stderr
.write(usg
)
314 main(sys
.argv
[1], sys
.argv
[2], sys
.argv
[3])