| 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 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 777 start_address = int(match.group(1), 16) | 777 start_address = int(match.group(1), 16) |
| 778 end_address = start_address | 778 end_address = start_address |
| 779 name = match.group(2) | 779 name = match.group(2) |
| 780 if code: | 780 if code: |
| 781 code.end_address = start_address | 781 code.end_address = start_address |
| 782 code_map.Add(code, 16) | 782 code_map.Add(code, 16) |
| 783 code = Code(name, start_address, end_address, "kernel", 0) | 783 code = Code(name, start_address, end_address, "kernel", 0) |
| 784 return True | 784 return True |
| 785 | 785 |
| 786 | 786 |
| 787 def PrintReport(code_map, library_repo, arch, options): | 787 def PrintReport(code_map, library_repo, arch, ticks, options): |
| 788 print "Ticks per symbol:" | 788 print "Ticks per symbol:" |
| 789 used_code = [code for code in code_map.UsedCode()] | 789 used_code = [code for code in code_map.UsedCode()] |
| 790 used_code.sort(key=lambda x: x.self_ticks, reverse=True) | 790 used_code.sort(key=lambda x: x.self_ticks, reverse=True) |
| 791 for i, code in enumerate(used_code): | 791 for i, code in enumerate(used_code): |
| 792 print "%10d %s [%s]" % (code.self_ticks, code.FullName(), code.origin) | 792 code_ticks = code.self_ticks |
| 793 print "%10d %5.1f%% %s [%s]" % (code_ticks, 100. * code_ticks / ticks, |
| 794 code.FullName(), code.origin) |
| 793 if options.disasm_all or i < options.disasm_top: | 795 if options.disasm_all or i < options.disasm_top: |
| 794 code.PrintAnnotated(arch, options) | 796 code.PrintAnnotated(arch, options) |
| 795 print | 797 print |
| 796 print "Ticks per library:" | 798 print "Ticks per library:" |
| 797 mmap_infos = [m for m in library_repo.infos] | 799 mmap_infos = [m for m in library_repo.infos] |
| 798 mmap_infos.sort(key=lambda m: m.ticks, reverse=True) | 800 mmap_infos.sort(key=lambda m: m.ticks, reverse=True) |
| 799 for mmap_info in mmap_infos: | 801 for mmap_info in mmap_infos: |
| 800 print "%10d %s" % (mmap_info.ticks, mmap_info.unique_name) | 802 mmap_ticks = mmap_info.ticks |
| 803 print "%10d %5.1f%% %s" % (mmap_ticks, 100. * mmap_ticks / ticks, |
| 804 mmap_info.unique_name) |
| 801 | 805 |
| 802 | 806 |
| 803 def PrintDot(code_map, options): | 807 def PrintDot(code_map, options): |
| 804 print "digraph G {" | 808 print "digraph G {" |
| 805 for code in code_map.UsedCode(): | 809 for code in code_map.UsedCode(): |
| 806 if code.self_ticks < 10: | 810 if code.self_ticks < 10: |
| 807 continue | 811 continue |
| 808 print "n%d [shape=box,label=\"%s\"];" % (code.id, code.name) | 812 print "n%d [shape=box,label=\"%s\"];" % (code.id, code.name) |
| 809 if code.callee_ticks: | 813 if code.callee_ticks: |
| 810 for callee, ticks in code.callee_ticks.iteritems(): | 814 for callee, ticks in code.callee_ticks.iteritems(): |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 875 snapshot_name_map = snapshot_log_reader.ReadNameMap() | 879 snapshot_name_map = snapshot_log_reader.ReadNameMap() |
| 876 | 880 |
| 877 # Initialize the log reader. | 881 # Initialize the log reader. |
| 878 code_map = CodeMap() | 882 code_map = CodeMap() |
| 879 log_reader = LogReader(log_name=options.log + ".ll", | 883 log_reader = LogReader(log_name=options.log + ".ll", |
| 880 code_map=code_map, | 884 code_map=code_map, |
| 881 snapshot_pos_to_name=snapshot_name_map) | 885 snapshot_pos_to_name=snapshot_name_map) |
| 882 if not options.quiet: | 886 if not options.quiet: |
| 883 print "Generated code architecture: %s" % log_reader.arch | 887 print "Generated code architecture: %s" % log_reader.arch |
| 884 print | 888 print |
| 889 sys.stdout.flush() |
| 885 | 890 |
| 886 # Process the code and trace logs. | 891 # Process the code and trace logs. |
| 887 library_repo = LibraryRepo() | 892 library_repo = LibraryRepo() |
| 888 log_reader.ReadUpToGC() | 893 log_reader.ReadUpToGC() |
| 889 trace_reader = TraceReader(options.trace) | 894 trace_reader = TraceReader(options.trace) |
| 890 while True: | 895 while True: |
| 891 header, offset = trace_reader.ReadEventHeader() | 896 header, offset = trace_reader.ReadEventHeader() |
| 892 if not header: | 897 if not header: |
| 893 break | 898 break |
| 894 events += 1 | 899 events += 1 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 916 caller_code = code_map.Find(ip) | 921 caller_code = code_map.Find(ip) |
| 917 if caller_code: | 922 if caller_code: |
| 918 if code: | 923 if code: |
| 919 caller_code.CalleeTick(code) | 924 caller_code.CalleeTick(code) |
| 920 code = caller_code | 925 code = caller_code |
| 921 sample_time += time.time() - start | 926 sample_time += time.time() - start |
| 922 | 927 |
| 923 if options.dot: | 928 if options.dot: |
| 924 PrintDot(code_map, options) | 929 PrintDot(code_map, options) |
| 925 else: | 930 else: |
| 926 PrintReport(code_map, library_repo, log_reader.arch, options) | 931 PrintReport(code_map, library_repo, log_reader.arch, ticks, options) |
| 927 | 932 |
| 928 if not options.quiet: | 933 if not options.quiet: |
| 929 print | 934 print |
| 930 print "Stats:" | 935 print "Stats:" |
| 931 print "%10d total trace events" % events | 936 print "%10d total trace events" % events |
| 932 print "%10d total ticks" % ticks | 937 print "%10d total ticks" % ticks |
| 933 print "%10d ticks not in symbols" % missed_ticks | 938 print "%10d ticks not in symbols" % missed_ticks |
| 934 print "%10d unaccounted ticks" % really_missed_ticks | 939 print "%10d unaccounted ticks" % really_missed_ticks |
| 935 print "%10d total symbols" % len([c for c in code_map.AllCode()]) | 940 print "%10d total symbols" % len([c for c in code_map.AllCode()]) |
| 936 print "%10d used symbols" % len([c for c in code_map.UsedCode()]) | 941 print "%10d used symbols" % len([c for c in code_map.UsedCode()]) |
| 937 print "%9.2fs library processing time" % mmap_time | 942 print "%9.2fs library processing time" % mmap_time |
| 938 print "%9.2fs tick processing time" % sample_time | 943 print "%9.2fs tick processing time" % sample_time |
| 939 | 944 |
| 940 log_reader.Dispose() | 945 log_reader.Dispose() |
| 941 trace_reader.Dispose() | 946 trace_reader.Dispose() |
| OLD | NEW |