Browse Source

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,
 089e627153
tags/devuan/2.0.1+devuan1
David Kalnischkies 7 months ago
parent
commit
ef50424be1
2 changed files with 14 additions and 24 deletions
  1. +1
    -1
      apt-pkg/contrib/progress.cc
  2. +13
    -23
      ftparchive/apt-ftparchive.cc

+ 1
- 1
apt-pkg/contrib/progress.cc View File

@@ -123,7 +123,7 @@ bool OpProgress::CheckChange(float Interval)

std::chrono::duration<decltype(Interval)> Delta =
std::chrono::seconds(NowTime.tv_sec - LastTime.tv_sec) +
std::chrono::microseconds(NowTime.tv_sec - LastTime.tv_usec);
std::chrono::microseconds(NowTime.tv_usec - LastTime.tv_usec);

if (Delta.count() < Interval)
return false;


+ 13
- 23
ftparchive/apt-ftparchive.cc View File

@@ -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;


Loading…
Cancel
Save