OpenWrt – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | #!/usr/bin/env perl |
2 | |||
3 | use strict; |
||
4 | use warnings; |
||
5 | use Config; |
||
6 | |||
7 | if (@ARGV < 2) { |
||
8 | die "Usage: $0 <prefix> <command...>\n"; |
||
9 | } |
||
10 | |||
11 | sub gettime { |
||
12 | my ($sec, $usec); |
||
13 | |||
14 | eval { |
||
15 | require Time::HiRes; |
||
16 | ($sec, $usec) = Time::HiRes::gettimeofday(); |
||
17 | }; |
||
18 | |||
19 | unless (defined($sec) && defined($usec)) { |
||
20 | my $tv_t = ($Config{'longsize'} == 8) ? 'qq' : 'll'; |
||
21 | my $tv = pack $tv_t, 0, 0; |
||
22 | |||
23 | eval { |
||
24 | require 'syscall.ph'; |
||
25 | syscall(SYS_gettimeofday(), $tv, 0); |
||
26 | }; |
||
27 | |||
28 | ($sec, $usec) = unpack $tv_t, $tv; |
||
29 | } |
||
30 | |||
31 | return ($sec, $usec); |
||
32 | } |
||
33 | |||
34 | my ($prefix, @cmd) = @ARGV; |
||
35 | my ($sec, $usec) = gettime(); |
||
36 | my $pid = fork(); |
||
37 | |||
38 | if (!defined($pid)) { |
||
39 | die "$0: Failure to fork(): $!\n"; |
||
40 | } |
||
41 | elsif ($pid == 0) { |
||
42 | exec(@cmd); |
||
43 | die "$0: Failure to exec(): $!\n"; |
||
44 | } |
||
45 | else { |
||
46 | $SIG{'INT'} = 'IGNORE'; |
||
47 | $SIG{'QUIT'} = 'IGNORE'; |
||
48 | |||
49 | if (waitpid($pid, 0) == -1) { |
||
50 | die "$0: Failure to waitpid(): $!\n"; |
||
51 | } |
||
52 | |||
53 | my $exitcode = $? >> 8; |
||
54 | my ($sec2, $usec2) = gettime(); |
||
55 | my (undef, undef, $cuser, $csystem) = times(); |
||
56 | |||
57 | printf STDERR "%s#%.2f#%.2f#%.2f\n", |
||
58 | $prefix, $cuser, $csystem, |
||
59 | ($sec2 - $sec) + ($usec2 - $usec) / 1000000; |
||
60 | |||
61 | $SIG{'INT'} = 'DEFAULT'; |
||
62 | $SIG{'QUIT'} = 'DEFAULT'; |
||
63 | |||
64 | exit $exitcode; |
||
65 | } |