Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add dynamic syntax log and monitor #7946

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions hphp/runtime/base/execution-context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2007,6 +2007,16 @@ typedef RankedCHM<StringData*, HPHP::Unit*,
StringDataHashCompare,
RankEvaledUnits> EvaledUnitsMap;
static EvaledUnitsMap s_evaledUnits;
static std::atomic<int64_t> s_createfuncs;

int64_t getEvaledUnits() {
return s_evaledUnits.size();
}

int64_t getCreateFuncs() {
return s_createfuncs.load(std::memory_order_acquire);
}

Unit* ExecutionContext::compileEvalString(
StringData* code,
const char* evalFilename /* = nullptr */) {
Expand All @@ -2015,6 +2025,11 @@ Unit* ExecutionContext::compileEvalString(
// across requests.
code = makeStaticString(code);
if (s_evaledUnits.insert(acc, code)) {
if (RuntimeOption::EnableDynamicFuncWarn) {
Logger::Warning("Don't recommended call eval(), "
"maybe effect performance "
"in %s on %d", getContainingFileName()->data(), getLine());
}
acc->second = compile_string(
code->data(),
code->size(),
Expand All @@ -2034,6 +2049,12 @@ StrNR ExecutionContext::createFunction(const String& args,
}

VMRegAnchor _;
s_createfuncs.fetch_add(1, std::memory_order_acq_rel);
if (RuntimeOption::EnableDynamicFuncWarn) {
Logger::Warning("Don't recommended call eval(), "
"maybe effect performance "
"in %s on %d", getContainingFileName()->data(), getLine());
}
auto const ar = GetCallerFrame();
// It doesn't matter if there's a user function named __lambda_func; we only
// use this name during parsing, and then change it to an impossible name
Expand Down
3 changes: 3 additions & 0 deletions hphp/runtime/base/execution-context.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ enum class InclOpFlags {
Relative = 16,
};

int64_t getEvaledUnits();
int64_t getCreateFuncs();

inline InclOpFlags operator|(const InclOpFlags& l, const InclOpFlags& r) {
return static_cast<InclOpFlags>(static_cast<int>(l) | static_cast<int>(r));
}
Expand Down
3 changes: 3 additions & 0 deletions hphp/runtime/base/runtime-option.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ bool RuntimeOption::CheckFlushOnUserClose = true;
bool RuntimeOption::EvalAuthoritativeMode = false;
bool RuntimeOption::IntsOverflowToInts = false;
bool RuntimeOption::AutoprimeGenerators = true;
bool RuntimeOption::EnableDynamicFuncWarn = false;

#ifdef FACEBOOK
bool RuntimeOption::UseThriftLogger = false;
Expand Down Expand Up @@ -1138,6 +1139,8 @@ void RuntimeOption::Load(
}
{
// Eval
Config::Bind(EnableDynamicFuncWarn, ini, config, "Eval.EnableDynamicFuncWarn",
EnableDynamicFuncWarn);
Config::Bind(EnableHipHopSyntax, ini, config, "Eval.EnableHipHopSyntax",
EnableHipHopSyntax);
Config::Bind(EnableHipHopExperimentalSyntax, ini,
Expand Down
1 change: 1 addition & 0 deletions hphp/runtime/base/runtime-option.h
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ struct RuntimeOption {
// is the following prefix followed by the pid of the hphp process.
static std::string LightProcessFilePrefix;
static int LightProcessCount;
static bool EnableDynamicFuncWarn;

// Eval options
static bool EnableHipHopSyntax;
Expand Down
2 changes: 2 additions & 0 deletions hphp/runtime/server/admin-request-handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,8 @@ bool AdminRequestHandler::handleCheckRequest(const std::string &cmd,
appendStat("fixups", jit::FixupMap::size());
appendStat("units", numLoadedUnits());
appendStat("funcs", Func::nextFuncId());
appendStat("EvaledUnits", getEvaledUnits());
appendStat("CreateFuncs", getCreateFuncs());
appendStat("named-entities", NamedEntity::tableSize());
for (auto& pair : NamedEntity::tableStats()) {
appendStat(folly::sformat("named-entities-{}", pair.first), pair.second);
Expand Down