diff --git a/lib/hobbes/eval/cc.C b/lib/hobbes/eval/cc.C index 5b296704..0d17a3a7 100644 --- a/lib/hobbes/eval/cc.C +++ b/lib/hobbes/eval/cc.C @@ -25,17 +25,25 @@ #include #include +#include #include #include #include #include +#include #include #include namespace hobbes { struct cc::PerfTracer { - PerfTracer() : ofs(std::getenv("HOBBES_PERF_TRACE_FILE")) { + PerfTracer() { + const char* name = std::getenv("HOBBES_PERF_TRACE_FILE"); + if (name == nullptr) { + return; + } + + ofs.open(name); if (!ofs) { ofs.close(); return; @@ -49,24 +57,20 @@ struct cc::PerfTracer { threshold = std::chrono::seconds(atoi(th)); } + template + [[nodiscard]] std::size_t nonHiddenSz(const T& t, F f) { + const auto& ms = t.members(); + return std::accumulate(ms.cbegin(), ms.cend(), 0UL, [f](auto a, const auto& m) { + return a + (f(m).substr(0, 2) != ".p" ? 1UL : 0UL); + }); + } + template void log(const std::string& name, const ExprPtr& e, const Definitions& defs, TT delta) { if (!isEnabled() || delta <= threshold || name.empty() || name.substr(0, 5) == ".rfn.") { return; } - const auto normal = [](const std::string& n) { return (n.substr(0, 2) != ".p") ? 1 : 0; }; - const auto nonHiddenVar = [normal](const Variant& c) { - const auto& ms = c.members(); - return std::accumulate(ms.cbegin(), ms.cend(), 0, - [normal](int a, const auto& m) { return a + normal(m.selector); }); - }; - const auto nonHiddenRec = [normal](const Record& c) { - const auto& ms = c.members(); - return std::accumulate(ms.cbegin(), ms.cend(), 0, - [normal](int a, const auto& m) { return a + normal(m.field); }); - }; - constexpr const char* MARK = "HOBBES_PERF"; ofs << MARK << ':' << name << ":BEGIN:" << std::chrono::duration_cast(delta).count() << ":"; @@ -87,14 +91,14 @@ struct cc::PerfTracer { if (cs->name() == VariantDeconstructor::constraintName()) { const auto& var = cs->arguments()[1]; var->show(oss); - const auto sz = nonHiddenVar(*is(var)); - i -= sz - 1U; + const int sz = nonHiddenSz(*is(var), [](const auto& m) { return m.selector; }); + i -= static_cast(sz - 1); ofs << MARK << ':' << name << ':' << sz << ':' << std::move(oss).str() << '\n'; } else if (cs->name() == RecordDeconstructor::constraintName()) { const auto& rec = cs->arguments()[2]; rec->show(oss); - const auto sz = nonHiddenRec(*is(rec)); - i -= sz - 1U; + const int sz = nonHiddenSz(*is(rec), [](const auto& m) { return m.field; }); + i -= static_cast(sz - 1); ofs << MARK << ':' << name << ':' << sz << ':' << std::move(oss).str() << '\n'; } } diff --git a/lib/hobbes/eval/jitcc.C b/lib/hobbes/eval/jitcc.C index e9256754..f18bb195 100644 --- a/lib/hobbes/eval/jitcc.C +++ b/lib/hobbes/eval/jitcc.C @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include @@ -561,7 +561,7 @@ struct jitcc::IrTracer { if (name == nullptr) { return; } - out = std::make_unique(name, ec); + out = std::make_unique(name, ec, llvm::sys::fs::F_None); if (ec != std::errc()) { out = nullptr; return;