Commit | Line | Data |
95667ae4 |
1 | #!perl |
583a019e |
2 | |
95667ae4 |
3 | BEGIN { |
4 | chdir( 't' ) if -d 't'; |
20822f61 |
5 | @INC = '../lib'; |
be3174d2 |
6 | require Config; import Config; |
7 | if ($Config{'extensions'} !~ /\bDevel\/DProf\b/){ |
8 | print "1..0 # Skip: Devel::DProf was not built\n"; |
9 | exit 0; |
10 | } |
95667ae4 |
11 | } |
583a019e |
12 | |
70b836b3 |
13 | END { |
ef060a86 |
14 | while(-e 'tmon.out' && unlink 'tmon.out') {} |
15 | while(-e 'err' && unlink 'err') {} |
70b836b3 |
16 | } |
17 | |
583a019e |
18 | use Benchmark qw( timediff timestr ); |
19 | use Getopt::Std 'getopts'; |
583a019e |
20 | getopts('vI:p:'); |
21 | |
22 | # -v Verbose |
23 | # -I Add to @INC |
24 | # -p Name of perl binary |
25 | |
ef060a86 |
26 | @tests = @ARGV ? @ARGV : sort (<lib/dprof/*_t>, <lib/dprof/*_v>); # glob-sort, for OS/2 |
583a019e |
27 | |
28 | $path_sep = $Config{path_sep} || ':'; |
583a019e |
29 | $perl5lib = $opt_I || join( $path_sep, @INC ); |
30 | $perl = $opt_p || $^X; |
31 | |
32 | if( $opt_v ){ |
33 | print "tests: @tests\n"; |
34 | print "perl: $perl\n"; |
35 | print "perl5lib: $perl5lib\n"; |
36 | } |
37 | if( $perl =~ m|^\./| ){ |
38 | # turn ./perl into ../perl, because of chdir(t) above. |
39 | $perl = ".$perl"; |
40 | } |
41 | if( ! -f $perl ){ die "Where's Perl?" } |
42 | |
43 | sub profile { |
44 | my $test = shift; |
45 | my @results; |
46 | local $ENV{PERL5LIB} = $perl5lib; |
47 | my $opt_d = '-d:DProf'; |
48 | |
49 | my $t_start = new Benchmark; |
ef060a86 |
50 | open( R, "$perl \"$opt_d\" $test |" ) || warn "$0: Can't run. $!\n"; |
583a019e |
51 | @results = <R>; |
52 | close R; |
53 | my $t_total = timediff( new Benchmark, $t_start ); |
54 | |
55 | if( $opt_v ){ |
56 | print "\n"; |
57 | print @results |
58 | } |
59 | |
ef060a86 |
60 | print '# ',timestr( $t_total, 'nop' ), "\n"; |
583a019e |
61 | } |
62 | |
63 | |
64 | sub verify { |
65 | my $test = shift; |
66 | |
d1ee8ea9 |
67 | my $command = $perl.' "-I../lib" "-I./lib/dprof" '.$test; |
68 | $command .= ' -v' if $opt_v; |
69 | $command .= ' -p '. $perl; |
70 | system $command; |
583a019e |
71 | } |
72 | |
73 | |
74 | $| = 1; |
95667ae4 |
75 | print "1..18\n"; |
583a019e |
76 | while( @tests ){ |
77 | $test = shift @tests; |
ef060a86 |
78 | $test =~ s/\.$// if $^O eq 'VMS'; |
95667ae4 |
79 | if( $test =~ /_t$/i ){ |
80 | print "# $test" . '.' x (20 - length $test); |
583a019e |
81 | profile $test; |
82 | } |
83 | else{ |
84 | verify $test; |
85 | } |
86 | } |
9394203c |
87 | |
88 | unlink("tmon.out"); |