Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Side by Side Diff: tools/code_coverage/croc_html.py

Issue 10681003: Added sorting functionality to HTML tables on coverage dashboard. (Closed) Base URL: https://src.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tools/code_coverage/third_party/README.chromium » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Crocodile HTML output.""" 5 """Crocodile HTML output."""
6 6
7 import os 7 import os
8 import shutil 8 import shutil
9 import time 9 import time
10 import xml.dom 10 import xml.dom
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 """Adds a section header to the coverage table. 187 """Adds a section header to the coverage table.
188 188
189 Args: 189 Args:
190 table: Table to add rows to. 190 table: Table to add rows to.
191 caption: Caption for section, if not None. 191 caption: Caption for section, if not None.
192 itemtype: Type of items in this section, if not None. 192 itemtype: Type of items in this section, if not None.
193 is_file: Are items in this section files? 193 is_file: Are items in this section files?
194 """ 194 """
195 195
196 if caption is not None: 196 if caption is not None:
197 table.E('tr').E('td', e_class='secdesc', colspan=8).Text(caption) 197 table.E('tr').E('th', e_class='secdesc', colspan=8).Text(caption)
198 198
199 sec_hdr = table.E('tr') 199 sec_hdr = table.E('tr')
200 200
201 if itemtype is not None: 201 if itemtype is not None:
202 sec_hdr.E('td', e_class='section').Text(itemtype) 202 sec_hdr.E('th', e_class='section').Text(itemtype)
203 203
204 sec_hdr.E('td', e_class='section').Text('Coverage') 204 sec_hdr.E('th', e_class='section').Text('Coverage')
205 sec_hdr.E('td', e_class='section', colspan=3).Text( 205 sec_hdr.E('th', e_class='section', colspan=3).Text(
206 'Lines executed / instrumented / missing') 206 'Lines executed / instrumented / missing')
207 207
208 graph = sec_hdr.E('td', e_class='section') 208 graph = sec_hdr.E('th', e_class='section')
209 graph.E('span', style='color:#00FF00').Text('exe') 209 graph.E('span', style='color:#00FF00').Text('exe')
210 graph.Text(' / ') 210 graph.Text(' / ')
211 graph.E('span', style='color:#FFFF00').Text('inst') 211 graph.E('span', style='color:#FFFF00').Text('inst')
212 graph.Text(' / ') 212 graph.Text(' / ')
213 graph.E('span', style='color:#FF0000').Text('miss') 213 graph.E('span', style='color:#FF0000').Text('miss')
214 214
215 if is_file: 215 if is_file:
216 sec_hdr.E('td', e_class='section').Text('Language') 216 sec_hdr.E('th', e_class='section').Text('Language')
217 sec_hdr.E('td', e_class='section').Text('Group') 217 sec_hdr.E('th', e_class='section').Text('Group')
218 else: 218 else:
219 sec_hdr.E('td', e_class='section', colspan=2) 219 sec_hdr.E('th', e_class='section', colspan=2)
220 220
221 def AddItem(self, table, itemname, stats, attrs, link=None): 221 def AddItem(self, table, itemname, stats, attrs, link=None):
222 """Adds a bar graph to the element. This is a series of <td> elements. 222 """Adds a bar graph to the element. This is a series of <td> elements.
223 223
224 Args: 224 Args:
225 table: Table to add item to. 225 table: Table to add item to.
226 itemname: Name of item. 226 itemname: Name of item.
227 stats: Stats object. 227 stats: Stats object.
228 attrs: Attributes dictionary; if None, no attributes will be printed. 228 attrs: Attributes dictionary; if None, no attributes will be printed.
229 link: Destination for itemname hyperlink, if not None. 229 link: Destination for itemname hyperlink, if not None.
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 351
352 if cov_dir.dirpath: 352 if cov_dir.dirpath:
353 title = 'Coverage for ' + cov_dir.dirpath + '/' 353 title = 'Coverage for ' + cov_dir.dirpath + '/'
354 f = self.CreateHtmlDoc(cov_dir.dirpath + '/index.html', title) 354 f = self.CreateHtmlDoc(cov_dir.dirpath + '/index.html', title)
355 else: 355 else:
356 title = 'Coverage summary' 356 title = 'Coverage summary'
357 f = self.CreateHtmlDoc('index.html', title) 357 f = self.CreateHtmlDoc('index.html', title)
358 358
359 body = f.body 359 body = f.body
360 360
361 dirs = [''] + cov_dir.dirpath.split('/')
362 num_dirs = len(dirs)
363 sort_jsfile = '../' * (num_dirs - 1) + 'sorttable.js'
364 script = body.E('script', src=sort_jsfile)
365 body.E('/script')
366
361 # Write header section 367 # Write header section
362 if cov_dir.dirpath: 368 if cov_dir.dirpath:
363 self.AddCaptionForSubdir(body, cov_dir.dirpath) 369 self.AddCaptionForSubdir(body, cov_dir.dirpath)
364 else: 370 else:
365 body.E('h2').Text(title) 371 body.E('h2').Text(title)
366 372
367 table = body.E('table') 373 table = body.E('table', e_class='sortable')
368 374 table.E('h3').Text('Coverage by Group')
369 # Coverage by group 375 # Coverage by group
370 self.AddSectionHeader(table, 'Coverage by Group', 'Group') 376 self.AddSectionHeader(table, None, 'Group')
371 377
372 for group in sorted(cov_dir.stats_by_group): 378 for group in sorted(cov_dir.stats_by_group):
373 self.AddItem(table, group, cov_dir.stats_by_group[group], None) 379 self.AddItem(table, group, cov_dir.stats_by_group[group], None)
374 380
381 table = body.E('table', e_class='sortable')
382 table.E('h3').Text('Subdirectories')
375 # List subdirs 383 # List subdirs
376 if cov_dir.subdirs: 384 if cov_dir.subdirs:
377 self.AddSectionHeader(table, 'Subdirectories', 'Subdirectory') 385 self.AddSectionHeader(table, None, 'Subdirectory')
378 386
379 for d in sorted(cov_dir.subdirs): 387 for d in sorted(cov_dir.subdirs):
380 self.AddItem(table, d + '/', cov_dir.subdirs[d].stats_by_group['all'], 388 self.AddItem(table, d + '/', cov_dir.subdirs[d].stats_by_group['all'],
381 None, link=d + '/index.html') 389 None, link=d + '/index.html')
382 390
391 table = body.E('table', e_class='sortable')
392 table.E('h3').Text('Files in This Directory')
383 # List files 393 # List files
384 if cov_dir.files: 394 if cov_dir.files:
385 self.AddSectionHeader(table, 'Files in This Directory', 'Filename', 395 self.AddSectionHeader(table, None, 'Filename',
386 is_file=True) 396 is_file=True)
387 397
388 for filename in sorted(cov_dir.files): 398 for filename in sorted(cov_dir.files):
389 cov_file = cov_dir.files[filename] 399 cov_file = cov_dir.files[filename]
390 self.AddItem(table, filename, cov_file.stats, cov_file.attrs, 400 self.AddItem(table, filename, cov_file.stats, cov_file.attrs,
391 link=filename + '.html') 401 link=filename + '.html')
392 402
393 body.E('p', e_class='time').Text(self.time_string) 403 body.E('p', e_class='time').Text(self.time_string)
394 f.Write() 404 f.Write()
395 405
396 def WriteRoot(self): 406 def WriteRoot(self):
397 """Writes the files in the output root.""" 407 """Writes the files in the output root."""
398 # Find ourselves 408 # Find ourselves
399 src_dir = os.path.split(self.WriteRoot.func_code.co_filename)[0] 409 src_dir = os.path.split(self.WriteRoot.func_code.co_filename)[0]
400 410
401 # Files to copy into output root 411 # Files to copy into output root
402 copy_files = [ 412 copy_files = [
John Grabowski 2012/07/10 17:37:14 since only one file each, can you copy_files = ['c
pshenoy 2012/07/10 18:02:22 I thought it is a good idea to maintain a separate
John Grabowski 2012/07/10 18:08:19 that's fine but still do this copy_files = ['croc
pshenoy 2012/07/10 18:22:23 Done.
403 'croc.css', 413 'croc.css',
404 ] 414 ]
415 # Third_party files to copy into output root
416 third_party_files = [
417 'sorttable.js',
418 ]
405 419
406 # Copy files from our directory into the output directory 420 # Copy files from our directory into the output directory
407 for copy_file in copy_files: 421 for copy_file in copy_files:
408 print ' Copying %s' % copy_file 422 print ' Copying %s' % copy_file
409 shutil.copyfile(os.path.join(src_dir, copy_file), 423 shutil.copyfile(os.path.join(src_dir, copy_file),
410 os.path.join(self.output_root, copy_file)) 424 os.path.join(self.output_root, copy_file))
425 # Copy third party files from third_party directory into
426 # the output directory
427 src_dir = os.path.join(src_dir, 'third_party')
428 for third_party_file in third_party_files:
429 print ' Copying %s' % third_party_file
430 shutil.copyfile(os.path.join(src_dir, third_party_file),
431 os.path.join(self.output_root, third_party_file))
411 432
412 def Write(self): 433 def Write(self):
413 """Writes HTML output.""" 434 """Writes HTML output."""
414 435
415 print 'Writing HTML to %s...' % self.output_root 436 print 'Writing HTML to %s...' % self.output_root
416 437
417 # Loop through the tree and write subdirs, breadth-first 438 # Loop through the tree and write subdirs, breadth-first
418 # TODO: switch to depth-first and sort values - makes nicer output? 439 # TODO: switch to depth-first and sort values - makes nicer output?
419 todo = [self.cov.tree] 440 todo = [self.cov.tree]
420 while todo: 441 while todo:
421 cov_dir = todo.pop(0) 442 cov_dir = todo.pop(0)
422 443
423 # Append subdirs to todo list 444 # Append subdirs to todo list
424 todo += cov_dir.subdirs.values() 445 todo += cov_dir.subdirs.values()
425 446
426 # Write this subdir 447 # Write this subdir
427 self.WriteSubdir(cov_dir) 448 self.WriteSubdir(cov_dir)
428 449
429 # Write files in this subdir 450 # Write files in this subdir
430 for cov_file in cov_dir.files.itervalues(): 451 for cov_file in cov_dir.files.itervalues():
431 self.WriteFile(cov_file) 452 self.WriteFile(cov_file)
432 453
433 # Write files in root directory 454 # Write files in root directory
434 self.WriteRoot() 455 self.WriteRoot()
OLDNEW
« no previous file with comments | « no previous file | tools/code_coverage/third_party/README.chromium » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698