mirror of
https://github.com/NixOS/nix
synced 2024-10-18 00:16:11 -04:00
Merge 794007cab7
into 806a91f7bf
This commit is contained in:
commit
18ded48f43
|
@ -332,6 +332,36 @@ EvalState::EvalState(
|
||||||
|
|
||||||
EvalState::~EvalState()
|
EvalState::~EvalState()
|
||||||
{
|
{
|
||||||
|
auto profileFile = getEnv("NIX_PROFILE_FILE");
|
||||||
|
|
||||||
|
std::map<PosIdx, std::string> cachedPositions;
|
||||||
|
|
||||||
|
if (!profileFile.has_value()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
std::ofstream profileStream(profileFile.value());
|
||||||
|
if (!profileStream) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (auto & [stack, count] : callCount) {
|
||||||
|
auto first = true;
|
||||||
|
for (auto & pos : stack) {
|
||||||
|
if (first) {
|
||||||
|
first = false;
|
||||||
|
} else {
|
||||||
|
profileStream << ";";
|
||||||
|
}
|
||||||
|
if (auto it = cachedPositions.find(pos); it != cachedPositions.end()) {
|
||||||
|
profileStream << it->second;
|
||||||
|
} else {
|
||||||
|
std::stringstream posStr;
|
||||||
|
posStr << positions[pos];
|
||||||
|
cachedPositions[pos] = posStr.str();
|
||||||
|
profileStream << posStr.str();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
profileStream << " " << count << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1448,15 +1478,36 @@ void ExprOpHasAttr::eval(EvalState & state, Env & env, Value & v)
|
||||||
v.mkBool(true);
|
v.mkBool(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ExprLambda::eval(EvalState & state, Env & env, Value & v)
|
void ExprLambda::eval(EvalState & state, Env & env, Value & v)
|
||||||
{
|
{
|
||||||
v.mkLambda(&env, this);
|
v.mkLambda(&env, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const std::chrono::duration SAMPLE_INTERVAL = std::chrono::microseconds(10);
|
||||||
|
namespace {
|
||||||
|
class SampleStack {
|
||||||
|
EvalState & state;
|
||||||
|
public:
|
||||||
|
SampleStack(EvalState & state, const PosIdx pos) : state(state) {
|
||||||
|
state.stack.push_back(pos);
|
||||||
|
}
|
||||||
|
~SampleStack() {
|
||||||
|
auto now = std::chrono::high_resolution_clock::now();
|
||||||
|
if (now - state.lastStackSample > SAMPLE_INTERVAL) {
|
||||||
|
state.callCount[state.stack] += 1;
|
||||||
|
state.lastStackSample = now;
|
||||||
|
}
|
||||||
|
if (state.stack.size() > 0) {
|
||||||
|
state.stack.pop_back();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
void EvalState::callFunction(Value & fun, size_t nrArgs, Value * * args, Value & vRes, const PosIdx pos)
|
void EvalState::callFunction(Value & fun, size_t nrArgs, Value * * args, Value & vRes, const PosIdx pos)
|
||||||
{
|
{
|
||||||
auto _level = addCallDepth(pos);
|
auto _level = addCallDepth(pos);
|
||||||
|
SampleStack _sample(*this, pos);
|
||||||
|
|
||||||
auto trace = settings.traceFunctionCalls
|
auto trace = settings.traceFunctionCalls
|
||||||
? std::make_unique<FunctionCallTrace>(positions[pos])
|
? std::make_unique<FunctionCallTrace>(positions[pos])
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include "search-path.hh"
|
#include "search-path.hh"
|
||||||
#include "repl-exit-status.hh"
|
#include "repl-exit-status.hh"
|
||||||
#include "ref.hh"
|
#include "ref.hh"
|
||||||
|
#include "pos-idx.hh"
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
@ -363,6 +364,10 @@ private:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
std::vector<PosIdx> stack = {};
|
||||||
|
std::map<std::vector<PosIdx>, int> callCount = {};
|
||||||
|
std::chrono::time_point<std::chrono::high_resolution_clock> lastStackSample = std::chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
EvalState(
|
EvalState(
|
||||||
const LookupPath & _lookupPath,
|
const LookupPath & _lookupPath,
|
||||||
ref<Store> store,
|
ref<Store> store,
|
||||||
|
@ -838,6 +843,7 @@ private:
|
||||||
|
|
||||||
bool countCalls;
|
bool countCalls;
|
||||||
|
|
||||||
|
|
||||||
typedef std::map<std::string, size_t> PrimOpCalls;
|
typedef std::map<std::string, size_t> PrimOpCalls;
|
||||||
PrimOpCalls primOpCalls;
|
PrimOpCalls primOpCalls;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue