Nix
2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Toggle main menu visibility
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
16
namespace
nix {
17
18
class
EvalState
;
19
class
PosIdx
;
20
struct
Value
;
21
22
class
EvalProfiler
23
{
24
public
:
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
33
private
:
34
std::optional<Hooks> neededHooks;
35
36
protected
:
38
void
invalidateNeededHooks
()
39
{
40
neededHooks = std::nullopt;
41
}
42
50
virtual
Hooks
getNeededHooksImpl
()
const
51
{
52
return
Hooks{};
53
}
54
55
public
:
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
85
Hooks
getNeededHooks
()
86
{
87
if
(neededHooks.has_value())
88
return
*neededHooks;
89
return
*(neededHooks =
getNeededHooksImpl
());
90
}
91
};
92
96
class
MultiEvalProfiler :
public
EvalProfiler
97
{
98
std::vector<ref<EvalProfiler>> profilers;
99
100
[[gnu::noinline]] Hooks getNeededHooksImpl()
const override
;
101
102
public
:
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
114
ref<EvalProfiler>
makeSampleStackProfiler(
EvalState
& state, std::filesystem::path profileFile, uint64_t frequency);
115
116
}
// namespace nix
nix::EvalProfiler
Definition
eval-profiler.hh:23
nix::EvalProfiler::getNeededHooksImpl
virtual Hooks getNeededHooksImpl() const
Definition
eval-profiler.hh:50
nix::EvalProfiler::invalidateNeededHooks
void invalidateNeededHooks()
Definition
eval-profiler.hh:38
nix::EvalProfiler::getNeededHooks
Hooks getNeededHooks()
Definition
eval-profiler.hh:85
nix::EvalProfiler::preFunctionCallHook
virtual void preFunctionCallHook(EvalState &state, const Value &v, std::span< Value *const > args, const PosIdx pos)
Definition
eval-profiler.cc:9
nix::EvalProfiler::postFunctionCallHook
virtual void postFunctionCallHook(EvalState &state, const Value &v, std::span< Value *const > args, const PosIdx pos)
Definition
eval-profiler.cc:14
nix::EvalState
Definition
eval.hh:420
nix::MultiEvalProfiler::addProfiler
void addProfiler(ref< EvalProfiler > profiler)
Definition
eval-profiler.cc:45
nix::MultiEvalProfiler::preFunctionCallHook
void preFunctionCallHook(EvalState &state, const Value &v, std::span< Value *const > args, const PosIdx pos) override
Definition
eval-profiler.cc:19
nix::MultiEvalProfiler::postFunctionCallHook
void postFunctionCallHook(EvalState &state, const Value &v, std::span< Value *const > args, const PosIdx pos) override
Definition
eval-profiler.cc:28
nix::PosIdx
Definition
pos-idx.hh:10
nix::ref
Definition
ref.hh:58
ref.hh
nix::Value
Definition
value.hh:1166
libexpr
include
nix
expr
eval-profiler.hh
Generated by
1.18.0