mirror of
https://github.com/NixOS/nix.git
synced 2025-11-08 11:36:03 +01:00
Merge pull request #14380 from NixOS/backport-14364-to-2.30-maintenance
[Backport 2.30-maintenance] diff-closures: print sizes with dynamic unit
This commit is contained in:
commit
b479a25292
10 changed files with 24 additions and 30 deletions
|
|
@ -8,6 +8,7 @@
|
||||||
#include "nix/util/users.hh"
|
#include "nix/util/users.hh"
|
||||||
#include "nix/util/fs-sink.hh"
|
#include "nix/util/fs-sink.hh"
|
||||||
#include "nix/util/sync.hh"
|
#include "nix/util/sync.hh"
|
||||||
|
#include "nix/util/util.hh"
|
||||||
|
|
||||||
#include <git2/attr.h>
|
#include <git2/attr.h>
|
||||||
#include <git2/blob.h>
|
#include <git2/blob.h>
|
||||||
|
|
@ -517,12 +518,12 @@ struct GitRepoImpl : GitRepo, std::enable_shared_from_this<GitRepoImpl>
|
||||||
auto act = (Activity *) payload;
|
auto act = (Activity *) payload;
|
||||||
act->result(
|
act->result(
|
||||||
resFetchStatus,
|
resFetchStatus,
|
||||||
fmt("%d/%d objects received, %d/%d deltas indexed, %.1f MiB",
|
fmt("%d/%d objects received, %d/%d deltas indexed, %s",
|
||||||
stats->received_objects,
|
stats->received_objects,
|
||||||
stats->total_objects,
|
stats->total_objects,
|
||||||
stats->indexed_deltas,
|
stats->indexed_deltas,
|
||||||
stats->total_deltas,
|
stats->total_deltas,
|
||||||
stats->received_bytes / (1024.0 * 1024.0)));
|
renderSize(stats->received_bytes)));
|
||||||
return getInterrupted() ? -1 : 0;
|
return getInterrupted() ? -1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -89,8 +89,6 @@ extern volatile ::sig_atomic_t blockInt;
|
||||||
|
|
||||||
/* GC helpers. */
|
/* GC helpers. */
|
||||||
|
|
||||||
std::string showBytes(uint64_t bytes);
|
|
||||||
|
|
||||||
struct GCResults;
|
struct GCResults;
|
||||||
|
|
||||||
struct PrintFreed
|
struct PrintFreed
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
#include "nix/main/loggers.hh"
|
#include "nix/main/loggers.hh"
|
||||||
#include "nix/main/progress-bar.hh"
|
#include "nix/main/progress-bar.hh"
|
||||||
#include "nix/util/signals.hh"
|
#include "nix/util/signals.hh"
|
||||||
|
#include "nix/util/util.hh"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
|
@ -64,18 +65,19 @@ void printMissing(ref<Store> store, const MissingPaths & missing, Verbosity lvl)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!missing.willSubstitute.empty()) {
|
if (!missing.willSubstitute.empty()) {
|
||||||
const float downloadSizeMiB = missing.downloadSize / (1024.f * 1024.f);
|
|
||||||
const float narSizeMiB = missing.narSize / (1024.f * 1024.f);
|
|
||||||
if (missing.willSubstitute.size() == 1) {
|
if (missing.willSubstitute.size() == 1) {
|
||||||
printMsg(
|
printMsg(
|
||||||
lvl, "this path will be fetched (%.2f MiB download, %.2f MiB unpacked):", downloadSizeMiB, narSizeMiB);
|
lvl,
|
||||||
|
"this path will be fetched (%s download, %s unpacked):",
|
||||||
|
renderSize(missing.downloadSize),
|
||||||
|
renderSize(missing.narSize));
|
||||||
} else {
|
} else {
|
||||||
printMsg(
|
printMsg(
|
||||||
lvl,
|
lvl,
|
||||||
"these %d paths will be fetched (%.2f MiB download, %.2f MiB unpacked):",
|
"these %d paths will be fetched (%s download, %s unpacked):",
|
||||||
missing.willSubstitute.size(),
|
missing.willSubstitute.size(),
|
||||||
downloadSizeMiB,
|
renderSize(missing.downloadSize),
|
||||||
narSizeMiB);
|
renderSize(missing.narSize));
|
||||||
}
|
}
|
||||||
std::vector<const StorePath *> willSubstituteSorted = {};
|
std::vector<const StorePath *> willSubstituteSorted = {};
|
||||||
std::for_each(missing.willSubstitute.begin(), missing.willSubstitute.end(), [&](const StorePath & p) {
|
std::for_each(missing.willSubstitute.begin(), missing.willSubstitute.end(), [&](const StorePath & p) {
|
||||||
|
|
@ -411,7 +413,7 @@ RunPager::~RunPager()
|
||||||
PrintFreed::~PrintFreed()
|
PrintFreed::~PrintFreed()
|
||||||
{
|
{
|
||||||
if (show)
|
if (show)
|
||||||
std::cout << fmt("%d store paths deleted, %s freed\n", results.paths.size(), showBytes(results.bytesFreed));
|
std::cout << fmt("%d store paths deleted, %s freed\n", results.paths.size(), renderSize(results.bytesFreed));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace nix
|
} // namespace nix
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
#include "nix/util/finally.hh"
|
#include "nix/util/finally.hh"
|
||||||
#include "nix/util/unix-domain-socket.hh"
|
#include "nix/util/unix-domain-socket.hh"
|
||||||
#include "nix/util/signals.hh"
|
#include "nix/util/signals.hh"
|
||||||
|
#include "nix/util/util.hh"
|
||||||
#include "nix/store/posix-fs-canonicalise.hh"
|
#include "nix/store/posix-fs-canonicalise.hh"
|
||||||
|
|
||||||
#include "store-config-private.hh"
|
#include "store-config-private.hh"
|
||||||
|
|
@ -904,9 +905,7 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
|
||||||
#endif
|
#endif
|
||||||
;
|
;
|
||||||
|
|
||||||
printInfo(
|
printInfo("note: currently hard linking saves %s", renderSize(unsharedSize - actualSize - overhead));
|
||||||
"note: currently hard linking saves %.2f MiB",
|
|
||||||
((unsharedSize - actualSize - overhead) / (1024.0 * 1024.0)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* While we're at it, vacuum the database. */
|
/* While we're at it, vacuum the database. */
|
||||||
|
|
|
||||||
|
|
@ -312,7 +312,7 @@ void LocalStore::optimiseStore()
|
||||||
|
|
||||||
optimiseStore(stats);
|
optimiseStore(stats);
|
||||||
|
|
||||||
printInfo("%s freed by hard-linking %d files", showBytes(stats.bytesFreed), stats.filesLinked);
|
printInfo("%s freed by hard-linking %d files", renderSize(stats.bytesFreed), stats.filesLinked);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalStore::optimisePath(const Path & path, RepairFlag repair)
|
void LocalStore::optimisePath(const Path & path, RepairFlag repair)
|
||||||
|
|
|
||||||
|
|
@ -211,6 +211,7 @@ TEST(renderSize, misc)
|
||||||
ASSERT_EQ(renderSize(972, true), " 0.9 KiB");
|
ASSERT_EQ(renderSize(972, true), " 0.9 KiB");
|
||||||
ASSERT_EQ(renderSize(973, true), " 1.0 KiB"); // FIXME: should round down
|
ASSERT_EQ(renderSize(973, true), " 1.0 KiB"); // FIXME: should round down
|
||||||
ASSERT_EQ(renderSize(1024, true), " 1.0 KiB");
|
ASSERT_EQ(renderSize(1024, true), " 1.0 KiB");
|
||||||
|
ASSERT_EQ(renderSize(-1024, true), " -1.0 KiB");
|
||||||
ASSERT_EQ(renderSize(1024 * 1024, true), "1024.0 KiB");
|
ASSERT_EQ(renderSize(1024 * 1024, true), "1024.0 KiB");
|
||||||
ASSERT_EQ(renderSize(1100 * 1024, true), " 1.1 MiB");
|
ASSERT_EQ(renderSize(1100 * 1024, true), " 1.1 MiB");
|
||||||
ASSERT_EQ(renderSize(2ULL * 1024 * 1024 * 1024, true), " 2.0 GiB");
|
ASSERT_EQ(renderSize(2ULL * 1024 * 1024 * 1024, true), " 2.0 GiB");
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,7 @@ N string2IntWithUnitPrefix(std::string_view s)
|
||||||
* GiB`. If `align` is set, the number will be right-justified by
|
* GiB`. If `align` is set, the number will be right-justified by
|
||||||
* padding with spaces on the left.
|
* padding with spaces on the left.
|
||||||
*/
|
*/
|
||||||
std::string renderSize(uint64_t value, bool align = false);
|
std::string renderSize(int64_t value, bool align = false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse a string into a float.
|
* Parse a string into a float.
|
||||||
|
|
@ -362,8 +362,6 @@ struct overloaded : Ts...
|
||||||
template<class... Ts>
|
template<class... Ts>
|
||||||
overloaded(Ts...) -> overloaded<Ts...>;
|
overloaded(Ts...) -> overloaded<Ts...>;
|
||||||
|
|
||||||
std::string showBytes(uint64_t bytes);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provide an addition operator between strings and string_views
|
* Provide an addition operator between strings and string_views
|
||||||
* inexplicably omitted from the standard library.
|
* inexplicably omitted from the standard library.
|
||||||
|
|
|
||||||
|
|
@ -132,15 +132,16 @@ std::optional<N> string2Float(const std::string_view s)
|
||||||
template std::optional<double> string2Float<double>(const std::string_view s);
|
template std::optional<double> string2Float<double>(const std::string_view s);
|
||||||
template std::optional<float> string2Float<float>(const std::string_view s);
|
template std::optional<float> string2Float<float>(const std::string_view s);
|
||||||
|
|
||||||
std::string renderSize(uint64_t value, bool align)
|
std::string renderSize(int64_t value, bool align)
|
||||||
{
|
{
|
||||||
static const std::array<char, 9> prefixes{{'K', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'}};
|
static const std::array<char, 9> prefixes{{'K', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'}};
|
||||||
size_t power = 0;
|
size_t power = 0;
|
||||||
double res = value;
|
double abs_value = std::abs(value);
|
||||||
while (res > 1024 && power < prefixes.size()) {
|
while (abs_value > 1024 && power < prefixes.size()) {
|
||||||
++power;
|
++power;
|
||||||
res /= 1024;
|
abs_value /= 1024;
|
||||||
}
|
}
|
||||||
|
double res = (double) value / std::pow(1024.0, power);
|
||||||
return fmt(align ? "%6.1f %ciB" : "%.1f %ciB", power == 0 ? res / 1024 : res, prefixes.at(power));
|
return fmt(align ? "%6.1f %ciB" : "%.1f %ciB", power == 0 ? res / 1024 : res, prefixes.at(power));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -316,9 +317,4 @@ std::pair<std::string_view, std::string_view> getLine(std::string_view s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string showBytes(uint64_t bytes)
|
|
||||||
{
|
|
||||||
return fmt("%.2f MiB", bytes / (1024.0 * 1024.0));
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace nix
|
} // namespace nix
|
||||||
|
|
|
||||||
|
|
@ -103,8 +103,7 @@ void printClosureDiff(
|
||||||
if (!removed.empty() || !added.empty())
|
if (!removed.empty() || !added.empty())
|
||||||
items.push_back(fmt("%s → %s", showVersions(removed), showVersions(added)));
|
items.push_back(fmt("%s → %s", showVersions(removed), showVersions(added)));
|
||||||
if (showDelta)
|
if (showDelta)
|
||||||
items.push_back(
|
items.push_back(fmt("%s%s" ANSI_NORMAL, sizeDelta > 0 ? ANSI_RED : ANSI_GREEN, renderSize(sizeDelta)));
|
||||||
fmt("%s%+.1f KiB" ANSI_NORMAL, sizeDelta > 0 ? ANSI_RED : ANSI_GREEN, sizeDelta / 1024.0));
|
|
||||||
logger->cout("%s%s: %s", indent, name, concatStringsSep(", ", items));
|
logger->cout("%s%s: %s", indent, name, concatStringsSep(", ", items));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -141,7 +141,7 @@ struct CmdPathInfo : StorePathsCommand, MixJSON
|
||||||
void printSize(std::ostream & str, uint64_t value)
|
void printSize(std::ostream & str, uint64_t value)
|
||||||
{
|
{
|
||||||
if (humanReadable)
|
if (humanReadable)
|
||||||
str << fmt("\t%s", renderSize(value, true));
|
str << fmt("\t%s", renderSize((int64_t) value, true));
|
||||||
else
|
else
|
||||||
str << fmt("\t%11d", value);
|
str << fmt("\t%11d", value);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue