mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-10 00:08:07 +02:00
libexpr: Track and show GC time and cycle number
This commit is contained in:
parent
0ec5e3a1bc
commit
b16861d82e
3 changed files with 32 additions and 0 deletions
|
@ -155,6 +155,10 @@ static inline void initGCReal()
|
||||||
there. */
|
there. */
|
||||||
GC_set_no_dls(1);
|
GC_set_no_dls(1);
|
||||||
|
|
||||||
|
/* Enable perf measurements. This is just a setting; not much of a
|
||||||
|
start of something. */
|
||||||
|
GC_start_performance_measurement();
|
||||||
|
|
||||||
GC_INIT();
|
GC_INIT();
|
||||||
|
|
||||||
GC_set_oom_fn(oomHandler);
|
GC_set_oom_fn(oomHandler);
|
||||||
|
@ -205,6 +209,7 @@ static inline void initGCReal()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static bool gcInitialised = false;
|
static bool gcInitialised = false;
|
||||||
|
static GC_word gcCyclesAfterInit = 0;
|
||||||
|
|
||||||
void initGC()
|
void initGC()
|
||||||
{
|
{
|
||||||
|
@ -216,6 +221,7 @@ void initGC()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
gcInitialised = true;
|
gcInitialised = true;
|
||||||
|
gcCyclesAfterInit = GC_get_gc_no();
|
||||||
}
|
}
|
||||||
|
|
||||||
void assertGCInitialized()
|
void assertGCInitialized()
|
||||||
|
@ -223,4 +229,10 @@ void assertGCInitialized()
|
||||||
assert(gcInitialised);
|
assert(gcInitialised);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t getGCCycles()
|
||||||
|
{
|
||||||
|
assertGCInitialized();
|
||||||
|
return GC_get_gc_no() - gcCyclesAfterInit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace nix
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
///@file
|
///@file
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -13,4 +15,9 @@ void initGC();
|
||||||
*/
|
*/
|
||||||
void assertGCInitialized();
|
void assertGCInitialized();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The number of GC cycles since initGC().
|
||||||
|
*/
|
||||||
|
size_t getGCCycles();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2610,6 +2610,11 @@ void EvalState::printStatistics()
|
||||||
#if HAVE_BOEHMGC
|
#if HAVE_BOEHMGC
|
||||||
GC_word heapSize, totalBytes;
|
GC_word heapSize, totalBytes;
|
||||||
GC_get_heap_usage_safe(&heapSize, 0, 0, 0, &totalBytes);
|
GC_get_heap_usage_safe(&heapSize, 0, 0, 0, &totalBytes);
|
||||||
|
double gcFullOnlyTime = ({
|
||||||
|
auto ms = GC_get_full_gc_total_time();
|
||||||
|
ms * 0.001;
|
||||||
|
});
|
||||||
|
auto gcCycles = getGCCycles();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
auto outPath = getEnv("NIX_SHOW_STATS_PATH").value_or("-");
|
auto outPath = getEnv("NIX_SHOW_STATS_PATH").value_or("-");
|
||||||
|
@ -2620,6 +2625,13 @@ void EvalState::printStatistics()
|
||||||
#ifndef _WIN32 // TODO implement
|
#ifndef _WIN32 // TODO implement
|
||||||
topObj["cpuTime"] = cpuTime;
|
topObj["cpuTime"] = cpuTime;
|
||||||
#endif
|
#endif
|
||||||
|
topObj["time"] = {
|
||||||
|
{"cpu", cpuTime},
|
||||||
|
#ifdef HAVE_BOEHMGC
|
||||||
|
{GC_is_incremental_mode() ? "gcNonIncremental" : "gc", gcFullOnlyTime},
|
||||||
|
{GC_is_incremental_mode() ? "gcNonIncrementalFraction" : "gcFraction", gcFullOnlyTime / cpuTime},
|
||||||
|
#endif
|
||||||
|
};
|
||||||
topObj["envs"] = {
|
topObj["envs"] = {
|
||||||
{"number", nrEnvs},
|
{"number", nrEnvs},
|
||||||
{"elements", nrValuesInEnvs},
|
{"elements", nrValuesInEnvs},
|
||||||
|
@ -2661,6 +2673,7 @@ void EvalState::printStatistics()
|
||||||
topObj["gc"] = {
|
topObj["gc"] = {
|
||||||
{"heapSize", heapSize},
|
{"heapSize", heapSize},
|
||||||
{"totalBytes", totalBytes},
|
{"totalBytes", totalBytes},
|
||||||
|
{"cycles", gcCycles},
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue