Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
eval-profiler.hh
Go to the documentation of this file.
1#pragma once
7
8#include "nix/util/ref.hh"
9
10#include <vector>
11#include <span>
12#include <bitset>
13#include <optional>
14#include <filesystem>
15
16namespace nix {
17
18class EvalState;
19class PosIdx;
20struct Value;
21
23{
24public:
25 enum Hook {
26 preFunctionCall,
27 postFunctionCall,
28 };
29
30 static constexpr std::size_t numHooks = Hook::postFunctionCall + 1;
31 using Hooks = std::bitset<numHooks>;
32
33private:
34 std::optional<Hooks> neededHooks;
35
36protected:
39 {
40 neededHooks = std::nullopt;
41 }
42
50 virtual Hooks getNeededHooksImpl() const
51 {
52 return Hooks{};
53 }
54
55public:
65 virtual void
66 preFunctionCallHook(EvalState & state, const Value & v, std::span<Value * const> args, const PosIdx pos);
67
77 virtual void
78 postFunctionCallHook(EvalState & state, const Value & v, std::span<Value * const> args, const PosIdx pos);
79
80 virtual ~EvalProfiler() = default;
81
86 {
87 if (neededHooks.has_value())
88 return *neededHooks;
89 return *(neededHooks = getNeededHooksImpl());
90 }
91};
92
96class MultiEvalProfiler : public EvalProfiler
97{
98 std::vector<ref<EvalProfiler>> profilers;
99
100 [[gnu::noinline]] Hooks getNeededHooksImpl() const override;
101
102public:
103 MultiEvalProfiler() = default;
104
106 void addProfiler(ref<EvalProfiler> profiler);
107
108 [[gnu::noinline]] void
109 preFunctionCallHook(EvalState & state, const Value & v, std::span<Value * const> args, const PosIdx pos) override;
110 [[gnu::noinline]] void
111 postFunctionCallHook(EvalState & state, const Value & v, std::span<Value * const> args, const PosIdx pos) override;
112};
113
114ref<EvalProfiler> makeSampleStackProfiler(EvalState & state, std::filesystem::path profileFile, uint64_t frequency);
115
116} // namespace nix
Definition eval-profiler.hh:23
virtual Hooks getNeededHooksImpl() const
Definition eval-profiler.hh:50
void invalidateNeededHooks()
Definition eval-profiler.hh:38
Hooks getNeededHooks()
Definition eval-profiler.hh:85
virtual void preFunctionCallHook(EvalState &state, const Value &v, std::span< Value *const > args, const PosIdx pos)
Definition eval-profiler.cc:9
virtual void postFunctionCallHook(EvalState &state, const Value &v, std::span< Value *const > args, const PosIdx pos)
Definition eval-profiler.cc:14
Definition eval.hh:420
void addProfiler(ref< EvalProfiler > profiler)
Definition eval-profiler.cc:45
void preFunctionCallHook(EvalState &state, const Value &v, std::span< Value *const > args, const PosIdx pos) override
Definition eval-profiler.cc:19
void postFunctionCallHook(EvalState &state, const Value &v, std::span< Value *const > args, const PosIdx pos) override
Definition eval-profiler.cc:28
Definition pos-idx.hh:10
Definition ref.hh:58
Definition value.hh:1166