代码拉取完成,页面将自动刷新
#include "profile_reader.h"
#include <cstdint>
#include "base/commandlineflags.h"
#include "base/logging.h"
#include "addr2line.h"
#include "gcov.h"
#include "symbol_map.h"
#include "third_party/abseil/absl/flags/flag.h"
namespace devtools_crosstool_autofdo {
void AutoFDOProfileReader::ReadModuleGroup() {
CHECK_EQ(gcov_read_unsigned(), GCOV_TAG_MODULE_GROUPING);
// Length of the section. Always 0.
gcov_read_unsigned();
// Number of modules. Always 0.
gcov_read_unsigned();
}
void AutoFDOProfileReader::ReadFunctionProfile() {
CHECK_EQ(gcov_read_unsigned(), GCOV_TAG_AFDO_FUNCTION);
gcov_read_unsigned();
uint32_t num_functions = gcov_read_unsigned();
SourceStack stack;
for (uint32_t i = 0; i < num_functions; i++) {
ReadSymbolProfile(stack, true);
}
}
void AutoFDOProfileReader::ReadSymbolProfile(const SourceStack &stack,
bool update) {
uint64_t head_count;
if (stack.size() == 0) {
head_count = gcov_read_counter();
} else {
head_count = 0;
}
const char *name = names_.at(gcov_read_unsigned()).c_str();
uint32_t num_pos_counts = gcov_read_unsigned();
uint32_t num_callsites = gcov_read_unsigned();
if (stack.size() == 0) {
symbol_map_->AddSymbol(name);
if (!force_update_ && symbol_map_->GetSymbolByName(name)->total_count > 0) {
update = false;
}
if (force_update_ || update) {
symbol_map_->AddSymbolEntryCount(name, head_count);
}
}
for (int i = 0; i < num_pos_counts; i++) {
uint32_t offset = gcov_read_unsigned();
uint32_t num_targets = gcov_read_unsigned();
uint64_t count = gcov_read_counter();
SourceInfo info(name, "", "", 0, offset >> 16, offset & 0xffff);
SourceStack new_stack;
new_stack.push_back(info);
new_stack.insert(new_stack.end(), stack.begin(), stack.end());
if (force_update_ || update) {
symbol_map_->AddSourceCount(new_stack[new_stack.size() - 1].func_name,
new_stack, count, 1);
}
for (int j = 0; j < num_targets; j++) {
// Only indirect call target histogram is supported now.
CHECK_EQ(gcov_read_unsigned(), HIST_TYPE_INDIR_CALL_TOPN);
const std::string &target_name = names_.at(gcov_read_counter());
uint64_t target_count = gcov_read_counter();
if (force_update_ || update) {
symbol_map_->AddIndirectCallTarget(
new_stack[new_stack.size() - 1].func_name,
new_stack, target_name, target_count);
}
}
}
for (int i = 0; i < num_callsites; i++) {
// offset is encoded as:
// higher 16 bits: line offset to the start of the function.
// lower 16 bits: discriminator.
uint32_t offset = gcov_read_unsigned();
SourceInfo info(name, "", "", 0, offset >> 16, offset & 0xffff);
SourceStack new_stack;
new_stack.push_back(info);
new_stack.insert(new_stack.end(), stack.begin(), stack.end());
ReadSymbolProfile(new_stack, update);
}
}
void AutoFDOProfileReader::ReadNameTable() {
CHECK_EQ(gcov_read_unsigned(), GCOV_TAG_AFDO_FILE_NAMES);
gcov_read_unsigned();
uint32_t name_vector_size = gcov_read_unsigned();
for (uint32_t i = 0; i < name_vector_size; i++) {
names_.push_back(gcov_read_string());
}
}
void AutoFDOProfileReader::ReadWorkingSet() {
CHECK_EQ(gcov_read_unsigned(), GCOV_TAG_AFDO_WORKING_SET);
gcov_read_unsigned();
for (uint32_t i = 0; i < NUM_GCOV_WORKING_SETS; i++) {
uint32_t num_counters = gcov_read_unsigned();
uint64_t min_counter = gcov_read_counter();
symbol_map_->UpdateWorkingSet(
i, num_counters * WORKING_SET_INSN_PER_BB, min_counter);
}
}
bool AutoFDOProfileReader::ReadFromFile(const std::string &output_file) {
CHECK_NE(gcov_open(output_file.c_str(), 1), -1);
// Read tags
CHECK_EQ(gcov_read_unsigned(), GCOV_DATA_MAGIC) << output_file;
absl::SetFlag(&FLAGS_gcov_version, gcov_read_unsigned());
gcov_read_unsigned();
ReadNameTable();
ReadFunctionProfile();
ReadModuleGroup();
ReadWorkingSet();
CHECK(!gcov_close());
return true;
}
} // namespace devtools_crosstool_autofdo
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。