Skip to content

Commit

Permalink
Put violation metric from D63795748 into Redex BSB stats
Browse files Browse the repository at this point in the history
Summary: If a hot method has a cold entry block, it is a violation. Adds this violation into bsb redex stats. Adds both a counter per violating interaction and per violating source block.

Reviewed By: jimmycFB

Differential Revision: D64256522

fbshipit-source-id: dc01e3999c16c8c1d6a7e82e1a8b68948d1b499f
  • Loading branch information
Koby Chan authored and facebook-github-bot committed Oct 14, 2024
1 parent 3f98c3d commit e793b39
Showing 1 changed file with 46 additions and 13 deletions.
59 changes: 46 additions & 13 deletions libredex/SourceBlocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,23 @@ size_t chain_hot_violations_tmpl(Block* block, const Fn& fn) {
return sum;
}

template <typename Fn>
size_t hot_method_cold_entry_violations_tmpl(Block* block, const Fn& fn) {
size_t sum{0};
if (block->preds().empty()) {
auto* sb = get_first_source_block(block);
if (sb != nullptr) {
sb->foreach_val([&sum](const auto& val) {
if (val->appear100 != 0 && val->val == 0) {
sum++;
}
});
}
}
sum = fn(sum);
return sum;
}

size_t chain_hot_violations(
Block* block,
const dominators::SimpleFastDominators<cfg::GraphInterface>&) {
Expand All @@ -688,6 +705,20 @@ size_t chain_hot_one_violations(
[](auto val) { return val > 0 ? 1 : 0; });
}

size_t hot_method_cold_entry_violations(
Block* block,
const dominators::SimpleFastDominators<cfg::GraphInterface>&) {
return hot_method_cold_entry_violations_tmpl(block,
[](auto val) { return val; });
}

size_t hot_method_cold_entry_block_violations(
Block* block,
const dominators::SimpleFastDominators<cfg::GraphInterface>&) {
return hot_method_cold_entry_violations_tmpl(
block, [](auto val) { return val > 0 ? 1 : 0; });
}

struct ChainAndDomState {
const SourceBlock* last{nullptr};
cfg::Block* dom_block{nullptr};
Expand Down Expand Up @@ -793,19 +824,21 @@ size_t chain_and_dom_violations_coldstart(
using CounterFnPtr = size_t (*)(
Block*, const dominators::SimpleFastDominators<cfg::GraphInterface>&);

constexpr std::array<std::pair<std::string_view, CounterFnPtr>, 8> gCounters = {
{
{"~blocks~count", &count_blocks},
{"~blocks~with~source~blocks", &count_block_has_sbs},
{"~blocks~with~incomplete-source~blocks",
&count_block_has_incomplete_sbs},
{"~assessment~source~blocks~total", &count_all_sbs},
{"~flow~violation~in~chain", &chain_hot_violations},
{"~flow~violation~in~chain~one", &chain_hot_one_violations},
{"~flow~violation~chain~and~dom", &chain_and_dom_violations},
{"~flow~violation~chain~and~dom.cold_start",
&chain_and_dom_violations_coldstart},
}};
constexpr std::array<std::pair<std::string_view, CounterFnPtr>, 10> gCounters =
{{{"~blocks~count", &count_blocks},
{"~blocks~with~source~blocks", &count_block_has_sbs},
{"~blocks~with~incomplete-source~blocks",
&count_block_has_incomplete_sbs},
{"~assessment~source~blocks~total", &count_all_sbs},
{"~flow~violation~in~chain", &chain_hot_violations},
{"~flow~violation~in~chain~one", &chain_hot_one_violations},
{"~flow~violation~chain~and~dom", &chain_and_dom_violations},
{"~flow~violation~chain~and~dom.cold_start",
&chain_and_dom_violations_coldstart},
{"~flow~violation~hot~method~cold~entry",
&hot_method_cold_entry_violations},
{"~flow~violation~hot~method~cold~entry~blocks",
&hot_method_cold_entry_block_violations}}};

constexpr std::array<std::pair<std::string_view, CounterFnPtr>, 3>
gCountersNonEntry = {{
Expand Down

0 comments on commit e793b39

Please sign in to comment.