| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright 2010 the V8 project authors. All rights reserved. | 3 # Copyright 2010 the V8 project authors. All rights reserved. |
| 4 # Redistribution and use in source and binary forms, with or without | 4 # Redistribution and use in source and binary forms, with or without |
| 5 # modification, are permitted provided that the following conditions are | 5 # modification, are permitted provided that the following conditions are |
| 6 # met: | 6 # met: |
| 7 # | 7 # |
| 8 # * Redistributions of source code must retain the above copyright | 8 # * Redistributions of source code must retain the above copyright |
| 9 # notice, this list of conditions and the following disclaimer. | 9 # notice, this list of conditions and the following disclaimer. |
| 10 # * Redistributions in binary form must reproduce the above | 10 # * Redistributions in binary form must reproduce the above |
| (...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 773 start_address = int(match.group(1), 16) | 773 start_address = int(match.group(1), 16) |
| 774 end_address = start_address | 774 end_address = start_address |
| 775 name = match.group(2) | 775 name = match.group(2) |
| 776 if code: | 776 if code: |
| 777 code.end_address = start_address | 777 code.end_address = start_address |
| 778 code_map.Add(code, 16) | 778 code_map.Add(code, 16) |
| 779 code = Code(name, start_address, end_address, "kernel", 0) | 779 code = Code(name, start_address, end_address, "kernel", 0) |
| 780 return True | 780 return True |
| 781 | 781 |
| 782 | 782 |
| 783 def PrintReport(code_map, library_repo, arch, options): | 783 def PrintReport(code_map, library_repo, arch, ticks, options): |
| 784 print "Ticks per symbol:" | 784 print "Ticks per symbol:" |
| 785 used_code = [code for code in code_map.UsedCode()] | 785 used_code = [code for code in code_map.UsedCode()] |
| 786 used_code.sort(key=lambda x: x.self_ticks, reverse=True) | 786 used_code.sort(key=lambda x: x.self_ticks, reverse=True) |
| 787 for i, code in enumerate(used_code): | 787 for i, code in enumerate(used_code): |
| 788 print "%10d %s [%s]" % (code.self_ticks, code.FullName(), code.origin) | 788 code_ticks = code.self_ticks |
| 789 print "%10d %5.1f%% %s [%s]" % (code_ticks, 100. * code_ticks / ticks, |
| 790 code.FullName(), code.origin) |
| 789 if options.disasm_all or i < options.disasm_top: | 791 if options.disasm_all or i < options.disasm_top: |
| 790 code.PrintAnnotated(arch, options) | 792 code.PrintAnnotated(arch, options) |
| 791 print | 793 print |
| 792 print "Ticks per library:" | 794 print "Ticks per library:" |
| 793 mmap_infos = [m for m in library_repo.infos] | 795 mmap_infos = [m for m in library_repo.infos] |
| 794 mmap_infos.sort(key=lambda m: m.ticks, reverse=True) | 796 mmap_infos.sort(key=lambda m: m.ticks, reverse=True) |
| 795 for mmap_info in mmap_infos: | 797 for mmap_info in mmap_infos: |
| 796 print "%10d %s" % (mmap_info.ticks, mmap_info.unique_name) | 798 mmap_ticks = mmap_info.ticks |
| 799 print "%10d %5.1f%% %s" % (mmap_ticks, 100. * mmap_ticks / ticks, |
| 800 mmap_info.unique_name) |
| 797 | 801 |
| 798 | 802 |
| 799 def PrintDot(code_map, options): | 803 def PrintDot(code_map, options): |
| 800 print "digraph G {" | 804 print "digraph G {" |
| 801 for code in code_map.UsedCode(): | 805 for code in code_map.UsedCode(): |
| 802 if code.self_ticks < 10: | 806 if code.self_ticks < 10: |
| 803 continue | 807 continue |
| 804 print "n%d [shape=box,label=\"%s\"];" % (code.id, code.name) | 808 print "n%d [shape=box,label=\"%s\"];" % (code.id, code.name) |
| 805 if code.callee_ticks: | 809 if code.callee_ticks: |
| 806 for callee, ticks in code.callee_ticks.iteritems(): | 810 for callee, ticks in code.callee_ticks.iteritems(): |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 871 snapshot_name_map = snapshot_log_reader.ReadNameMap() | 875 snapshot_name_map = snapshot_log_reader.ReadNameMap() |
| 872 | 876 |
| 873 # Initialize the log reader. | 877 # Initialize the log reader. |
| 874 code_map = CodeMap() | 878 code_map = CodeMap() |
| 875 log_reader = LogReader(log_name=options.log + ".ll", | 879 log_reader = LogReader(log_name=options.log + ".ll", |
| 876 code_map=code_map, | 880 code_map=code_map, |
| 877 snapshot_pos_to_name=snapshot_name_map) | 881 snapshot_pos_to_name=snapshot_name_map) |
| 878 if not options.quiet: | 882 if not options.quiet: |
| 879 print "Generated code architecture: %s" % log_reader.arch | 883 print "Generated code architecture: %s" % log_reader.arch |
| 880 print | 884 print |
| 885 sys.stdout.flush() |
| 881 | 886 |
| 882 # Process the code and trace logs. | 887 # Process the code and trace logs. |
| 883 library_repo = LibraryRepo() | 888 library_repo = LibraryRepo() |
| 884 log_reader.ReadUpToGC() | 889 log_reader.ReadUpToGC() |
| 885 trace_reader = TraceReader(options.trace) | 890 trace_reader = TraceReader(options.trace) |
| 886 while True: | 891 while True: |
| 887 header, offset = trace_reader.ReadEventHeader() | 892 header, offset = trace_reader.ReadEventHeader() |
| 888 if not header: | 893 if not header: |
| 889 break | 894 break |
| 890 events += 1 | 895 events += 1 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 912 caller_code = code_map.Find(ip) | 917 caller_code = code_map.Find(ip) |
| 913 if caller_code: | 918 if caller_code: |
| 914 if code: | 919 if code: |
| 915 caller_code.CalleeTick(code) | 920 caller_code.CalleeTick(code) |
| 916 code = caller_code | 921 code = caller_code |
| 917 sample_time += time.time() - start | 922 sample_time += time.time() - start |
| 918 | 923 |
| 919 if options.dot: | 924 if options.dot: |
| 920 PrintDot(code_map, options) | 925 PrintDot(code_map, options) |
| 921 else: | 926 else: |
| 922 PrintReport(code_map, library_repo, log_reader.arch, options) | 927 PrintReport(code_map, library_repo, log_reader.arch, ticks, options) |
| 923 | 928 |
| 924 if not options.quiet: | 929 if not options.quiet: |
| 925 print | 930 print |
| 926 print "Stats:" | 931 print "Stats:" |
| 927 print "%10d total trace events" % events | 932 print "%10d total trace events" % events |
| 928 print "%10d total ticks" % ticks | 933 print "%10d total ticks" % ticks |
| 929 print "%10d ticks not in symbols" % missed_ticks | 934 print "%10d ticks not in symbols" % missed_ticks |
| 930 print "%10d unaccounted ticks" % really_missed_ticks | 935 print "%10d unaccounted ticks" % really_missed_ticks |
| 931 print "%10d total symbols" % len([c for c in code_map.AllCode()]) | 936 print "%10d total symbols" % len([c for c in code_map.AllCode()]) |
| 932 print "%10d used symbols" % len([c for c in code_map.UsedCode()]) | 937 print "%10d used symbols" % len([c for c in code_map.UsedCode()]) |
| 933 print "%9.2fs library processing time" % mmap_time | 938 print "%9.2fs library processing time" % mmap_time |
| 934 print "%9.2fs tick processing time" % sample_time | 939 print "%9.2fs tick processing time" % sample_time |
| 935 | 940 |
| 936 log_reader.Dispose() | 941 log_reader.Dispose() |
| 937 trace_reader.Dispose() | 942 trace_reader.Dispose() |
| OLD | NEW |