This patch adds an EvalProfiler and MultiEvalProfiler that can be used to insert hooks into the evaluation for the purposes of function tracing (what function-trace currently does) or for flamegraph/tracy profilers. See the following commits for how this is supposed to be integrated into the evaluator and performance considerations.
49 lines
1.3 KiB
C++
49 lines
1.3 KiB
C++
#include "nix/expr/eval-profiler.hh"
|
|
#include "nix/expr/nixexpr.hh"
|
|
|
|
namespace nix {
|
|
|
|
void EvalProfiler::preFunctionCallHook(
|
|
const EvalState & state, const Value & v, std::span<Value *> args, const PosIdx pos)
|
|
{
|
|
}
|
|
|
|
void EvalProfiler::postFunctionCallHook(
|
|
const EvalState & state, const Value & v, std::span<Value *> args, const PosIdx pos)
|
|
{
|
|
}
|
|
|
|
void MultiEvalProfiler::preFunctionCallHook(
|
|
const EvalState & state, const Value & v, std::span<Value *> args, const PosIdx pos)
|
|
{
|
|
for (auto & profiler : profilers) {
|
|
if (profiler->getNeededHooks().test(Hook::preFunctionCall))
|
|
profiler->preFunctionCallHook(state, v, args, pos);
|
|
}
|
|
}
|
|
|
|
void MultiEvalProfiler::postFunctionCallHook(
|
|
const EvalState & state, const Value & v, std::span<Value *> args, const PosIdx pos)
|
|
{
|
|
for (auto & profiler : profilers) {
|
|
if (profiler->getNeededHooks().test(Hook::postFunctionCall))
|
|
profiler->postFunctionCallHook(state, v, args, pos);
|
|
}
|
|
}
|
|
|
|
EvalProfiler::Hooks MultiEvalProfiler::getNeededHooksImpl() const
|
|
{
|
|
Hooks hooks;
|
|
for (auto & p : profilers)
|
|
hooks |= p->getNeededHooks();
|
|
return hooks;
|
|
}
|
|
|
|
void MultiEvalProfiler::addProfiler(ref<EvalProfiler> profiler)
|
|
{
|
|
profilers.push_back(profiler);
|
|
invalidateNeededHooks();
|
|
}
|
|
|
|
}
|