203
212
"--no-pageids", dest="pageids",
204
213
action="store_false", default=True,
205
214
help="Do not produce pageids report")
216
"--directory", dest="directory",
217
default=os.getcwd(), metavar="DIR",
218
help="Output reports in DIR directory")
206
220
options, args = parser.parse_args()
222
if not os.path.isdir(options.directory):
223
parser.error("Directory %s does not exist" % options.directory)
207
225
if len(args) == 0:
208
226
parser.error("At least one zserver tracelog file must be provided")
243
261
parse(args, categories, pageid_times, options)
245
print_html_report(options, categories, pageid_times)
263
# Category only report.
264
if options.categories:
265
report_filename = os.path.join(options.directory,'categories.html')
266
log.info("Generating %s", report_filename)
267
html_report(open(report_filename, 'w'), categories, None)
269
# Pageid only report.
271
report_filename = os.path.join(options.directory,'pageids.html')
272
log.info("Generating %s", report_filename)
273
html_report(open(report_filename, 'w'), None, pageid_times)
276
if options.categories and options.pageids:
277
report_filename = os.path.join(options.directory,'combined.html')
278
html_report(open(report_filename, 'w'), categories, pageid_times)
398
431
"Unknown extension prefix %s" % prefix)
401
def print_html_report(options, categories, pageid_times):
434
def html_report(outf, categories, pageid_times):
436
print >> outf, dedent('''\
404
437
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
405
438
"http://www.w3.org/TR/html4/loose.dtd">
488
521
def handle_times(html_title, times):
489
522
stats = times.stats()
490
523
histograms.append(stats.histogram)
524
print >> outf, dedent("""\
493
526
<th class="category-title">%s</th>
494
527
<td class="numeric total_hits">%d</td>
517
550
stats.total_hits, stats.total_time,
518
551
stats.mean, stats.std, stats.var, stats.median,
520
553
stats.total_sqltime, stats.mean_sqltime,
521
554
stats.std_sqltime, stats.var_sqltime, stats.median_sqltime,
522
555
stats.total_sqlstatements, stats.mean_sqlstatements,
524
557
stats.median_sqlstatements))
526
559
# Table of contents
528
if options.categories:
529
print '<li><a href="#catrep">Category Report</a></li>'
531
print '<li><a href="#pageidrep">Pageid Report</a></li>'
560
if categories and pageid_times:
561
print >> outf, dedent('''\
563
<li><a href="#catrep">Category Report</a></li>
564
<li><a href="#pageidrep">Pageid Report</a></li>
534
if options.categories:
535
print '<h2 id="catrep">Category Report</h2>'
569
print >> outf, '<h2 id="catrep">Category Report</h2>'
570
print >> outf, table_header
537
571
for category in categories:
538
572
html_title = '%s<br/><span class="regexp">%s</span>' % (
539
573
html_quote(category.title), html_quote(category.regexp))
540
574
handle_times(html_title, category.times)
575
print >> outf, table_footer
544
print '<h2 id="pageidrep">Pageid Report</h2>'
578
print >> outf, '<h2 id="pageidrep">Pageid Report</h2>'
579
print >> outf, table_header
546
580
for pageid, times in sorted(pageid_times.items()):
547
581
handle_times(html_quote(pageid), times)
582
print >> outf, table_footer
550
584
# Ourput the javascript to render our histograms nicely, replacing
551
585
# the placeholder <div> tags output earlier.
586
print >> outf, dedent("""\
553
587
<script language="javascript" type="text/javascript">