File: perl-profiler.pl

package info (click to toggle)
pkg-kde-tools 0.15.24
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 744 kB
  • ctags: 517
  • sloc: perl: 4,121; ansic: 628; sh: 481; python: 48; makefile: 3
file content (54 lines) | stat: -rwxr-xr-x 1,234 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/perl -w

# Based on /usr/share/doc/libdevel-nytprof-perl/examples/demo/demo-run.pl
# from the libdevel-nytprof-perl package.
# License: Artistic or GPL-1+

use strict;
use IO::Handle;

my $NYTPROF = ($ENV{NYTPROF}) ? "$ENV{NYTPROF}:" : "";

my %runs = (
    start_begin => {
        skip => 0,
        NYTPROF => 'start=begin:optimize=0',
    },
    start_check => {
        skip => 1,
        NYTPROF => 'start=init:optimize=0',
    },
    start_end => {
        skip => 1,
        NYTPROF => 'start=end:optimize=0',
    },
);

my $bin = shift @ARGV;
my $name = $bin;
$name =~ s,^.*/,,;

for my $run (keys %runs) {

    next if $runs{$run}{skip};
    $ENV{NYTPROF}      = $NYTPROF . $runs{$run}{NYTPROF} || '';
    $ENV{NYTPROF_HTML} = $runs{$run}{NYTPROF_HTML} || '';

    my $cmd = "perl -d:NYTProf $bin @ARGV";
    open my $fh, "| $cmd"
        or die "Error starting $cmd\n";
    $fh->autoflush;
    close $fh
        or die "Error closing pipe to $cmd: $!\n";

    my $outdir = "${name}-profiler/$run";
    system("rm -rf $outdir") == 0 or exit 0;
    system("mkdir -p $outdir") == 0 or exit 0;
    system("nytprofhtml --open --out=$outdir") == 0
        or exit 0;

    #system "ls -lrt $outdir/.";

    sleep 1;
}