[InstrProf][Correlate] Improve error messages

Improve the error messages when using `llvm-profdata` to correlate profiles with debug info.

Reviewed By: kyulee, phosek

Differential Revision: https://reviews.llvm.org/D118166
This commit is contained in:
Ellis Hoag 2022-01-25 12:35:23 -08:00
parent b1d946cbf7
commit 6d5239113c
3 changed files with 13 additions and 10 deletions

View File

@ -293,7 +293,6 @@ enum class instrprof_error {
missing_debug_info_for_correlation, missing_debug_info_for_correlation,
unexpected_debug_info_for_correlation, unexpected_debug_info_for_correlation,
unable_to_correlate_profile, unable_to_correlate_profile,
unsupported_debug_format,
unknown_function, unknown_function,
invalid_prof, invalid_prof,
hash_mismatch, hash_mismatch,

View File

@ -119,9 +119,6 @@ static std::string getInstrProfErrString(instrprof_error Err,
case instrprof_error::unable_to_correlate_profile: case instrprof_error::unable_to_correlate_profile:
OS << "unable to correlate profile"; OS << "unable to correlate profile";
break; break;
case instrprof_error::unsupported_debug_format:
OS << "unsupported debug info format (only DWARF is supported)";
break;
case instrprof_error::invalid_prof: case instrprof_error::invalid_prof:
OS << "invalid profile created. Please file a bug " OS << "invalid profile created. Please file a bug "
"at: " BUG_REPORT_URL "at: " BUG_REPORT_URL

View File

@ -23,7 +23,8 @@ Expected<object::SectionRef> getCountersSection(const object::ObjectFile &Obj) {
if (SectionName.get() == INSTR_PROF_CNTS_SECT_NAME) if (SectionName.get() == INSTR_PROF_CNTS_SECT_NAME)
return Section; return Section;
return make_error<InstrProfError>( return make_error<InstrProfError>(
instrprof_error::unable_to_correlate_profile); instrprof_error::unable_to_correlate_profile,
"could not find counter section (" INSTR_PROF_CNTS_SECT_NAME ")");
} }
const char *InstrProfCorrelator::FunctionNameAttributeName = "Function Name"; const char *InstrProfCorrelator::FunctionNameAttributeName = "Function Name";
@ -54,9 +55,9 @@ InstrProfCorrelator::get(StringRef DebugInfoFilename) {
// TODO: Enable profile correlation when there are multiple objects in a // TODO: Enable profile correlation when there are multiple objects in a
// dSYM bundle. // dSYM bundle.
if (DsymObjectsOrErr->size() > 1) if (DsymObjectsOrErr->size() > 1)
return createStringError( return make_error<InstrProfError>(
std::error_code(), instrprof_error::unable_to_correlate_profile,
"Profile correlation using multiple objects is not yet supported"); "using multiple objects is not yet supported");
DebugInfoFilename = *DsymObjectsOrErr->begin(); DebugInfoFilename = *DsymObjectsOrErr->begin();
} }
auto BufferOrErr = auto BufferOrErr =
@ -84,7 +85,7 @@ InstrProfCorrelator::get(std::unique_ptr<MemoryBuffer> Buffer) {
return InstrProfCorrelatorImpl<uint32_t>::get(std::move(*CtxOrErr), *Obj); return InstrProfCorrelatorImpl<uint32_t>::get(std::move(*CtxOrErr), *Obj);
} }
return make_error<InstrProfError>( return make_error<InstrProfError>(
instrprof_error::unable_to_correlate_profile); instrprof_error::unable_to_correlate_profile, "not an object file");
} }
namespace llvm { namespace llvm {
@ -120,13 +121,19 @@ InstrProfCorrelatorImpl<IntPtrT>::get(
return std::make_unique<DwarfInstrProfCorrelator<IntPtrT>>(std::move(DICtx), return std::make_unique<DwarfInstrProfCorrelator<IntPtrT>>(std::move(DICtx),
std::move(Ctx)); std::move(Ctx));
} }
return make_error<InstrProfError>(instrprof_error::unsupported_debug_format); return make_error<InstrProfError>(
instrprof_error::unable_to_correlate_profile,
"unsupported debug info format (only DWARF is supported)");
} }
template <class IntPtrT> template <class IntPtrT>
Error InstrProfCorrelatorImpl<IntPtrT>::correlateProfileData() { Error InstrProfCorrelatorImpl<IntPtrT>::correlateProfileData() {
assert(Data.empty() && Names.empty() && NamesVec.empty()); assert(Data.empty() && Names.empty() && NamesVec.empty());
correlateProfileDataImpl(); correlateProfileDataImpl();
if (Data.empty() || NamesVec.empty())
return make_error<InstrProfError>(
instrprof_error::unable_to_correlate_profile,
"could not find any profile metadata in debug info");
auto Result = auto Result =
collectPGOFuncNameStrings(NamesVec, /*doCompression=*/false, Names); collectPGOFuncNameStrings(NamesVec, /*doCompression=*/false, Names);
CounterOffsets.clear(); CounterOffsets.clear();