aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2018-08-05 12:24:01 +0200
committerJo-Philipp Wich <jo@mein.io>2018-12-18 11:01:55 +0100
commit2890abbcc0329460ebc7384e994272d1ee3b372d (patch)
treedddf7131e8c01872743c8325b7dc533df7606e3d /scripts
parentb4454ca4fae13f85e06d01df8a2a94ddd78d3368 (diff)
downloadupstream-2890abbcc0329460ebc7384e994272d1ee3b372d.tar.gz
upstream-2890abbcc0329460ebc7384e994272d1ee3b372d.tar.bz2
upstream-2890abbcc0329460ebc7384e994272d1ee3b372d.zip
scripts: time.pl: avoid hard Time::HiRes dependency
Use Time::HiRes when available and fallback to raw syscall interface when not. If that fails too, simply report 0, 0 as real time. Signed-off-by: Jo-Philipp Wich <jo@mein.io> (backported from a692e4e3de60e1a10906511fb8ef2d14937d4a19)
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/time.pl31
1 files changed, 27 insertions, 4 deletions
diff --git a/scripts/time.pl b/scripts/time.pl
index cdc5824c83..a23b57c89e 100755
--- a/scripts/time.pl
+++ b/scripts/time.pl
@@ -2,14 +2,37 @@
use strict;
use warnings;
-use Time::HiRes qw(gettimeofday);
+use Config;
if (@ARGV < 2) {
die "Usage: $0 <prefix> <command...>\n";
}
+sub gettime {
+ my ($sec, $usec);
+
+ eval {
+ require Time::HiRes;
+ ($sec, $usec) = Time::HiRes::gettimeofday();
+ };
+
+ unless (defined($sec) && defined($usec)) {
+ my $tv_t = ($Config{'longsize'} == 8) ? 'qq' : 'll';
+ my $tv = pack $tv_t, 0, 0;
+
+ eval {
+ require 'syscall.ph';
+ syscall(SYS_gettimeofday(), $tv, 0);
+ };
+
+ ($sec, $usec) = unpack $tv_t, $tv;
+ }
+
+ return ($sec, $usec);
+}
+
my ($prefix, @cmd) = @ARGV;
-my ($sec, $msec) = gettimeofday();
+my ($sec, $usec) = gettime();
my $pid = fork();
if (!defined($pid)) {
@@ -28,12 +51,12 @@ else {
}
my $exitcode = $? >> 8;
- my ($sec2, $msec2) = gettimeofday();
+ my ($sec2, $usec2) = gettime();
my (undef, undef, $cuser, $csystem) = times();
printf STDERR "%s#%.2f#%.2f#%.2f\n",
$prefix, $cuser, $csystem,
- ($sec2 - $sec) + ($msec2 - $msec) / 1000000;
+ ($sec2 - $sec) + ($usec2 - $usec) / 1000000;
$SIG{'INT'} = 'DEFAULT';
$SIG{'QUIT'} = 'DEFAULT';