From 196b1cc3cee1fc90c4da43621af2068721722df7 Mon Sep 17 00:00:00 2001 From: Yorhel Date: Mon, 7 Apr 2025 16:41:29 +0200 Subject: [PATCH] FU: Use CLOCK_MONOTONIC for timing --- FU.pm | 8 ++++---- FU/DebugImpl.pm | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/FU.pm b/FU.pm index d59f821..c21bb7f 100644 --- a/FU.pm +++ b/FU.pm @@ -3,7 +3,7 @@ use v5.36; use Carp 'confess', 'croak'; use IO::Socket; use POSIX (); -use Time::HiRes 'time'; +use Time::HiRes 'clock_gettime', 'CLOCK_MONOTONIC'; use FU::Log 'log_write'; use FU::Util; use FU::Validate; @@ -320,7 +320,7 @@ sub _log_err($e) { } 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'; $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 { _read_req $c; - $REQ->{trace_start} = time; + $REQ->{trace_start} = clock_gettime(CLOCK_MONOTONIC); my $path = fu->path; 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}); if (debug && $REQ->{trace_id} && $debug_info->{history} && $debug_info->{storage}) { diff --git a/FU/DebugImpl.pm b/FU/DebugImpl.pm index 08252ad..eda2939 100644 --- a/FU/DebugImpl.pm +++ b/FU/DebugImpl.pm @@ -342,7 +342,7 @@ sub save { return; }; 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:''); utf8::encode($line); print $fh $line;