forked from OSchip/llvm-project
[BOLT] Fix merge-fdata and heatmap in BAT
Summary: merge-fdata for legacy format was simply appending all input strings to output, but the real format supports some header strings that can't be simply concatanated to output. Check for the header string used by BAT before merging fdata to avoid creating an output file with invalid lines (header in the middle of the fdata file). For heatmap, avoid reading BAT tables, since they won't be used. (cherry picked from FBD17943131)
This commit is contained in:
parent
d87f95065a
commit
698a4684ac
|
@ -1849,10 +1849,13 @@ void RewriteInstance::readSpecialSections() {
|
||||||
|
|
||||||
if (auto BATSec =
|
if (auto BATSec =
|
||||||
BC->getUniqueSectionByName(BoltAddressTranslation::SECTION_NAME)) {
|
BC->getUniqueSectionByName(BoltAddressTranslation::SECTION_NAME)) {
|
||||||
if (std::error_code EC = BAT->parse(BATSec->getContents())) {
|
// Do not read BAT when plotting a heatmap
|
||||||
errs() << "BOLT-ERROR: failed to parse BOLT address translation "
|
if (!opts::HeatmapMode) {
|
||||||
"table.\n";
|
if (std::error_code EC = BAT->parse(BATSec->getContents())) {
|
||||||
exit(1);
|
errs() << "BOLT-ERROR: failed to parse BOLT address translation "
|
||||||
|
"table.\n";
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -245,6 +245,8 @@ bool isYAML(const StringRef Filename) {
|
||||||
|
|
||||||
void mergeLegacyProfiles(const cl::list<std::string> &Filenames) {
|
void mergeLegacyProfiles(const cl::list<std::string> &Filenames) {
|
||||||
errs() << "Using legacy profile format.\n";
|
errs() << "Using legacy profile format.\n";
|
||||||
|
bool BoltedCollection{false};
|
||||||
|
bool First{true};
|
||||||
for (auto &Filename : Filenames) {
|
for (auto &Filename : Filenames) {
|
||||||
if (isYAML(Filename))
|
if (isYAML(Filename))
|
||||||
report_error(Filename, "cannot mix YAML and legacy formats");
|
report_error(Filename, "cannot mix YAML and legacy formats");
|
||||||
|
@ -252,7 +254,28 @@ void mergeLegacyProfiles(const cl::list<std::string> &Filenames) {
|
||||||
if (std::error_code EC = MB.getError())
|
if (std::error_code EC = MB.getError())
|
||||||
report_error(Filename, EC);
|
report_error(Filename, EC);
|
||||||
errs() << "Merging data from " << Filename << "...\n";
|
errs() << "Merging data from " << Filename << "...\n";
|
||||||
outs() << MB.get()->getBuffer();
|
|
||||||
|
auto Buf = MB.get()->getBuffer();
|
||||||
|
// Check if the string "boltedcollection" is in the first line
|
||||||
|
if (Buf.startswith("boltedcollection\n")) {
|
||||||
|
if (!First && !BoltedCollection) {
|
||||||
|
report_error(
|
||||||
|
Filename,
|
||||||
|
"cannot mix profile collected in BOLT and non-BOLT deployments");
|
||||||
|
}
|
||||||
|
BoltedCollection = true;
|
||||||
|
if (!First)
|
||||||
|
Buf = Buf.drop_front(17);
|
||||||
|
} else {
|
||||||
|
if (BoltedCollection) {
|
||||||
|
report_error(
|
||||||
|
Filename,
|
||||||
|
"cannot mix profile collected in BOLT and non-BOLT deployments");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
outs() << Buf;
|
||||||
|
First = false;
|
||||||
}
|
}
|
||||||
errs() << "Profile from " << Filenames.size() << " files merged.\n";
|
errs() << "Profile from " << Filenames.size() << " files merged.\n";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue