Assign weights to each function. General principles: any uncovered function gets weight 0. a function with lots of uncovered blocks gets bigger weight. a function with a less frequently executed code gets bigger weight.
| 87 | // * a function with lots of uncovered blocks gets bigger weight. |
| 88 | // * a function with a less frequently executed code gets bigger weight. |
| 89 | std::vector<double> BlockCoverage::FunctionWeights(size_t NumFunctions) const { |
| 90 | std::vector<double> Res(NumFunctions); |
| 91 | for (const auto &It : Functions) { |
| 92 | auto FunctionID = It.first; |
| 93 | auto Counters = It.second; |
| 94 | assert(FunctionID < NumFunctions); |
| 95 | auto &Weight = Res[FunctionID]; |
| 96 | // Give higher weight if the function has a DFT. |
| 97 | Weight = FunctionsWithDFT.count(FunctionID) ? 1000. : 1; |
| 98 | // Give higher weight to functions with less frequently seen basic blocks. |
| 99 | Weight /= SmallestNonZeroCounter(Counters); |
| 100 | // Give higher weight to functions with the most uncovered basic blocks. |
| 101 | Weight *= NumberOfUncoveredBlocks(Counters) + 1; |
| 102 | } |
| 103 | return Res; |
| 104 | } |
| 105 | |
| 106 | void DataFlowTrace::ReadCoverage(const std::string &DirPath) { |
| 107 | std::vector<SizedFile> Files; |