build: remove GNU time dependency
[openwrt/openwrt.git] / scripts / time.pl
1 #!/usr/bin/env perl
2
3 use strict;
4 use warnings;
5 use Time::HiRes qw(gettimeofday);
6
7 if (@ARGV < 2) {
8 die "Usage: $0 <prefix> <command...>\n";
9 }
10
11 my ($prefix, @cmd) = @ARGV;
12 my ($sec, $msec) = gettimeofday();
13 my $pid = fork();
14
15 if (!defined($pid)) {
16 die "$0: Failure to fork(): $!\n";
17 }
18 elsif ($pid == 0) {
19 exec(@cmd);
20 die "$0: Failure to exec(): $!\n";
21 }
22 else {
23 $SIG{'INT'} = 'IGNORE';
24 $SIG{'QUIT'} = 'IGNORE';
25
26 if (waitpid($pid, 0) == -1) {
27 die "$0: Failure to waitpid(): $!\n";
28 }
29
30 my $exitcode = $? >> 8;
31 my ($sec2, $msec2) = gettimeofday();
32 my (undef, undef, $cuser, $csystem) = times();
33
34 printf STDERR "%s#%.2f#%.2f#%.2f\n",
35 $prefix, $cuser, $csystem,
36 ($sec2 - $sec) + ($msec2 - $msec) / 1000000;
37
38 $SIG{'INT'} = 'DEFAULT';
39 $SIG{'QUIT'} = 'DEFAULT';
40
41 exit $exitcode;
42 }