Chris Lattner | 10c91cc | 2003-10-28 22:11:31 +0000 | [diff] [blame] | 1 | #!/usr/bin/perl -w |
| 2 | # |
| 3 | # Program: profile.pl |
| 4 | # |
| 5 | # Synopsis: Insert instrumentation code into a program, run it with the JIT, |
| 6 | # then print out a profile report. |
| 7 | # |
| 8 | # Syntax: profile.pl [OPTIONS] bytecodefile <arguments> |
| 9 | # |
| 10 | # OPTIONS may include one or more of the following: |
Chris Lattner | 2c14d253 | 2003-10-28 22:52:05 +0000 | [diff] [blame^] | 11 | # -block - Enable basic block level profiling |
Chris Lattner | 10c91cc | 2003-10-28 22:11:31 +0000 | [diff] [blame] | 12 | # |
Chris Lattner | 10c91cc | 2003-10-28 22:11:31 +0000 | [diff] [blame] | 13 | |
| 14 | my $ProfilePass = "-insert-function-profiling"; |
| 15 | |
| 16 | # Parse arguments... |
| 17 | while (scalar(@ARGV) and ($_ = $ARGV[0], /^[-+]/)) { |
| 18 | shift; |
| 19 | last if /^--$/; # Stop processing arguments on -- |
| 20 | |
| 21 | # List command line options here... |
Chris Lattner | 2c14d253 | 2003-10-28 22:52:05 +0000 | [diff] [blame^] | 22 | if (/^-block$/) { $ProfilePass = "-insert-block-profiling"; next; } |
Chris Lattner | 10c91cc | 2003-10-28 22:11:31 +0000 | [diff] [blame] | 23 | |
| 24 | print "Unknown option: $_ : ignoring!\n"; |
| 25 | } |
| 26 | |
| 27 | die "Must specify LLVM bytecode file as first argument!" if (@ARGV == 0); |
| 28 | |
| 29 | my $BytecodeFile = $ARGV[0]; |
| 30 | |
| 31 | shift @ARGV; |
| 32 | |
| 33 | my $LLIPath = `which lli`; |
| 34 | $LLIPath = `dirname $LLIPath`; |
| 35 | chomp $LLIPath; |
| 36 | |
| 37 | my $LibProfPath = $LLIPath . "/../../lib/Debug/libprofile_rt.so"; |
| 38 | |
Chris Lattner | 2c14d253 | 2003-10-28 22:52:05 +0000 | [diff] [blame^] | 39 | system "opt $ProfilePass < $BytecodeFile | lli -fake-argv0 '$BytecodeFile'" . |
| 40 | " -load $LibProfPath - " . (join ' ', @ARGV); |
Chris Lattner | 10c91cc | 2003-10-28 22:11:31 +0000 | [diff] [blame] | 41 | |
| 42 | system "llvm-prof $BytecodeFile"; |