(S, args)
| 439 | |
| 440 | |
| 441 | def print_stats(S, args): |
| 442 | # Sort by ascending/descending time average, then by ascending/descending |
| 443 | # count average, then by ascending name. |
| 444 | def sort_asc_func(item): |
| 445 | return (item[1]['time_stat']['average'], |
| 446 | item[1]['count_stat']['average'], |
| 447 | item[0]) |
| 448 | def sort_desc_func(item): |
| 449 | return (-item[1]['time_stat']['average'], |
| 450 | -item[1]['count_stat']['average'], |
| 451 | item[0]) |
| 452 | # Sorting order is in the commend-line arguments. |
| 453 | sort_func = sort_asc_func if args.sort == "asc" else sort_desc_func |
| 454 | # Possibly limit how many elements to print. |
| 455 | L = [item for item in sorted(S.items(), key=sort_func) |
| 456 | if item[0] not in ["Total", "Sum"]] |
| 457 | N = len(L) |
| 458 | if args.limit == 0: |
| 459 | low, high = 0, N |
| 460 | elif args.sort == "desc": |
| 461 | low, high = 0, args.limit |
| 462 | else: |
| 463 | low, high = N-args.limit, N |
| 464 | # How to print entries. |
| 465 | def print_entry(key, value): |
| 466 | def stats(s, units=""): |
| 467 | conf = "{:0.1f}({:0.2f}%)".format(s['ci']['abs'], s['ci']['perc']) |
| 468 | return "{:8.1f}{} +/- {:15s}".format(s['average'], units, conf) |
| 469 | print("{:>50s} {} {}".format( |
| 470 | key, |
| 471 | stats(value['time_stat'], units="ms"), |
| 472 | stats(value['count_stat']) |
| 473 | )) |
| 474 | # Print and calculate partial sums, if necessary. |
| 475 | for i in range(low, high): |
| 476 | print_entry(*L[i]) |
| 477 | if args.totals and args.limit != 0 and not args.aggregate: |
| 478 | if i == low: |
| 479 | partial = { 'time_list': [0] * len(L[i][1]['time_list']), |
| 480 | 'count_list': [0] * len(L[i][1]['count_list']) } |
| 481 | assert len(partial['time_list']) == len(L[i][1]['time_list']) |
| 482 | assert len(partial['count_list']) == len(L[i][1]['count_list']) |
| 483 | for j, v in enumerate(L[i][1]['time_list']): |
| 484 | partial['time_list'][j] += v |
| 485 | for j, v in enumerate(L[i][1]['count_list']): |
| 486 | partial['count_list'][j] += v |
| 487 | # Print totals, if necessary. |
| 488 | if args.totals: |
| 489 | print('-' * 80) |
| 490 | if args.limit != 0 and not args.aggregate: |
| 491 | partial['time_stat'] = statistics(partial['time_list']) |
| 492 | partial['count_stat'] = statistics(partial['count_list']) |
| 493 | print_entry("Partial", partial) |
| 494 | print_entry("Sum", S["Sum"]) |
| 495 | print_entry("Total", S["Total"]) |
| 496 | |
| 497 | |
| 498 | def extract_domain(filename): |
no test coverage detected
searching dependent graphs…