diff options
author | David Kalnischkies <david@kalnischkies.de> | 2020-02-06 14:25:28 +0100 |
---|---|---|
committer | David Kalnischkies <david@kalnischkies.de> | 2020-02-06 14:25:28 +0100 |
commit | ef50424be1586b91a99d28bf5108f3999cc908fb (patch) | |
tree | 9a3a81b2d73eaa68577e1c3c7a4f8cd55e69807c /ftparchive | |
parent | cfbece15c4ba68b798ce3e8fffce19a89ffcd756 (diff) |
Fix remaining usec vs sec time-delta calculation typos
While moving to a more stable clock in 79b61ae I typoed the microsecond
calculation part and copied it all over the place… Julian fixed the
first two instances in 089e6271 and Trent reported the apt-ftparchive
instances leaving one instance in progress (invisible for user though).
A bit ironic that in an attempt to stop "confusing (and amusing) users"
I managed to hide a typo for close to two years doing just that…
Sadly we can't really test this as while "apt-ftparchive generate /dev/null"
is a great interactive test, it is hard to teach our test framework that
the output is "reasonably below an hour" (usually 0s, but on busy test
systems it is perhaps longer…).
Thanks: Trent W. Buck for initial patch
Closes: #950776
References: 79b61ae7673eb6213493e2cb202f0d70c390932d,
089e627153781ae7c320a5a0724c6c70d684b689
Diffstat (limited to 'ftparchive')
-rw-r--r-- | ftparchive/apt-ftparchive.cc | 36 |
1 files changed, 13 insertions, 23 deletions
diff --git a/ftparchive/apt-ftparchive.cc b/ftparchive/apt-ftparchive.cc index 077701cc0..87ce9153c 100644 --- a/ftparchive/apt-ftparchive.cc +++ b/ftparchive/apt-ftparchive.cc @@ -56,6 +56,15 @@ static struct timeval GetTimevalFromSteadyClock() /*{{{*/ return { Time_sec.count(), Time_usec.count() }; } /*}}}*/ +static auto GetTimeDeltaSince(struct timeval StartTime) /*{{{*/ +{ + auto const NewTime = GetTimevalFromSteadyClock(); + std::chrono::duration<double> Delta = + std::chrono::seconds(NewTime.tv_sec - StartTime.tv_sec) + + std::chrono::microseconds(NewTime.tv_usec - StartTime.tv_usec); + return llround(Delta.count()); +} + /*}}}*/ // struct PackageMap - List of all package files in the config file /*{{{*/ // --------------------------------------------------------------------- @@ -241,16 +250,11 @@ bool PackageMap::GenPackages(Configuration &Setup,struct CacheDB::Stats &Stats) << SizeToStr(Size) << "B "; else c0out << ' '; - - struct timeval NewTime = GetTimevalFromSteadyClock(); - std::chrono::duration<double> Delta = - std::chrono::seconds(NewTime.tv_sec - StartTime.tv_sec) + - std::chrono::microseconds(NewTime.tv_sec - StartTime.tv_usec); c0out << Packages.Stats.Packages << " files " << /* SizeToStr(Packages.Stats.MD5Bytes) << "B/" << */ SizeToStr(Packages.Stats.Bytes) << "B " << - TimeToStr(llround(Delta.count())) << endl; + TimeToStr(GetTimeDeltaSince(StartTime)) << endl; if(_config->FindB("APT::FTPArchive::ShowCacheMisses", false) == true) c0out << " Misses in Cache: " << Packages.Stats.Misses<< endl; @@ -328,13 +332,8 @@ bool PackageMap::GenSources(Configuration &Setup,struct CacheDB::Stats &Stats) else c0out << ' '; - struct timeval NewTime = GetTimevalFromSteadyClock(); - std::chrono::duration<double> Delta = - std::chrono::seconds(NewTime.tv_sec - StartTime.tv_sec) + - std::chrono::microseconds(NewTime.tv_sec - StartTime.tv_usec); - c0out << Sources.Stats.Packages << " pkgs in " << - TimeToStr(llround(Delta.count())) << endl; + TimeToStr(GetTimeDeltaSince(StartTime)) << endl; if(_config->FindB("APT::FTPArchive::ShowCacheMisses", false) == true) c0out << " Misses in Cache: " << Sources.Stats.Misses << endl; @@ -444,17 +443,12 @@ bool PackageMap::GenContents(Configuration &Setup, else c0out << ' '; - struct timeval NewTime = GetTimevalFromSteadyClock(); - std::chrono::duration<double> Delta = - std::chrono::seconds(NewTime.tv_sec - StartTime.tv_sec) + - std::chrono::microseconds(NewTime.tv_sec - StartTime.tv_usec); - if(_config->FindB("APT::FTPArchive::ShowCacheMisses", false) == true) c0out << " Misses in Cache: " << Contents.Stats.Misses<< endl; c0out << Contents.Stats.Packages << " files " << SizeToStr(Contents.Stats.Bytes) << "B " << - TimeToStr(llround(Delta.count())) << endl; + TimeToStr(GetTimeDeltaSince(StartTime)) << endl; return true; } @@ -970,12 +964,8 @@ static bool Generate(CommandLine &CmdL) return false; } - struct timeval NewTime = GetTimevalFromSteadyClock(); - std::chrono::duration<double> Delta = - std::chrono::seconds(NewTime.tv_sec - StartTime.tv_sec) + - std::chrono::microseconds(NewTime.tv_sec - StartTime.tv_usec); c1out << "Done. " << SizeToStr(Stats.Bytes) << "B in " << Stats.Packages - << " archives. Took " << TimeToStr(llround(Delta.count())) << endl; + << " archives. Took " << TimeToStr(GetTimeDeltaSince(StartTime)) << endl; UnloadTree(TransList); return true; |