FU: Use CLOCK_MONOTONIC for timing

This commit is contained in:
Yorhel 2025-04-07 16:41:29 +02:00
parent e7a9f165de
commit 196b1cc3ce
2 changed files with 5 additions and 5 deletions

8
FU.pm
View file

@ -3,7 +3,7 @@ use v5.36;
use Carp 'confess', 'croak'; use Carp 'confess', 'croak';
use IO::Socket; use IO::Socket;
use POSIX (); use POSIX ();
use Time::HiRes 'time'; use Time::HiRes 'clock_gettime', 'CLOCK_MONOTONIC';
use FU::Log 'log_write'; use FU::Log 'log_write';
use FU::Util; use FU::Util;
use FU::Validate; use FU::Validate;
@ -320,7 +320,7 @@ sub _log_err($e) {
} }
sub _do_req($c) { sub _do_req($c) {
local $REQ = { hdr => {}, trace_start => time, trace_id => sprintf('%010x%08x%04x', int time, $$, int rand 1<<16) }; local $REQ = { hdr => {}, trace_start => clock_gettime(CLOCK_MONOTONIC), trace_id => sprintf('%010x%08x%04x', int time, $$, int rand 1<<16) };
local $fu = bless {}, 'FU::obj'; local $fu = bless {}, 'FU::obj';
$REQ->{ip} = $c->{client_sock} isa 'IO::Socket::INET' ? $c->{client_sock}->peerhost : '127.0.0.1'; $REQ->{ip} = $c->{client_sock} isa 'IO::Socket::INET' ? $c->{client_sock}->peerhost : '127.0.0.1';
@ -328,7 +328,7 @@ sub _do_req($c) {
my $ok = eval { my $ok = eval {
_read_req $c; _read_req $c;
$REQ->{trace_start} = time; $REQ->{trace_start} = clock_gettime(CLOCK_MONOTONIC);
my $path = fu->path; my $path = fu->path;
my $method = fu->method eq 'HEAD' ? 'GET' : fu->method; my $method = fu->method eq 'HEAD' ? 'GET' : fu->method;
@ -387,7 +387,7 @@ sub _do_req($c) {
} }
} }
$REQ->{trace_end} = time; $REQ->{trace_end} = clock_gettime(CLOCK_MONOTONIC);
fu->_flush($c->{fcgi_obj} || $c->{client_sock}); fu->_flush($c->{fcgi_obj} || $c->{client_sock});
if (debug && $REQ->{trace_id} && $debug_info->{history} && $debug_info->{storage}) { if (debug && $REQ->{trace_id} && $debug_info->{history} && $debug_info->{storage}) {

View file

@ -342,7 +342,7 @@ sub save {
return; return;
}; };
my $line = sprintf "%d %f %s %s %s\n", my $line = sprintf "%d %f %s %s %s\n",
time, time - $FU::REQ->{trace_start}, $FU::REQ->{status}, time, $FU::REQ->{trace_end} - $FU::REQ->{trace_start}, $FU::REQ->{status},
fu->method, fu->path.(fu->query?'?'.fu->query:''); fu->method, fu->path.(fu->query?'?'.fu->query:'');
utf8::encode($line); utf8::encode($line);
print $fh $line; print $fh $line;