mirror of
https://github.com/RPCS3/llvm.git
synced 2025-04-13 03:21:07 +00:00

Summary: This change addresses two possible instances of user error / confusion when merging sampled profile data. Previously any input that didn't match the raw or processed instrumented format would automatically be interpreted as instrumented profile text format data. No error would be reported during the merge. Example: If foo-sampled.profdata and bar-sampled.profdata are binary sampled profiles: Old behavior: $ llvm-profdata merge foo-sampled.profdata bar-sampled.profdata -output foobar-sampled.profdata $ llvm-profdata show -sample foobar-sampled.profdata error: foobar-sampled.profdata:1: Expected 'mangled_name:NUM:NUM', found lprofi This change adds basic checks for valid input data when assuming text input. It also makes error messages related to file format validity more specific about the assumbed profile data type. New behavior: $ llvm-profdata merge foo-sampled.profdata bar-sampled.profdata -o foobar-sampled.profdata error: foo.profdata: Unrecognized instrumentation profile encoding format Perhaps you forgot to use the -sample option? Reviewers: bogner, davidxl, dnovillo Subscribers: davidxl, llvm-commits Differential Revision: http://reviews.llvm.org/D14558 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@252916 91177308-0d34-0410-b5e6-96231b3b80d8
90 lines
3.2 KiB
C++
90 lines
3.2 KiB
C++
//=-- SampleProf.cpp - Sample profiling format support --------------------===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file contains common definitions used in the reading and writing of
|
|
// sample profile data.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm/ProfileData/SampleProf.h"
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
#include "llvm/Support/ManagedStatic.h"
|
|
|
|
using namespace llvm::sampleprof;
|
|
using namespace llvm;
|
|
|
|
namespace {
|
|
class SampleProfErrorCategoryType : public std::error_category {
|
|
const char *name() const LLVM_NOEXCEPT override { return "llvm.sampleprof"; }
|
|
std::string message(int IE) const override {
|
|
sampleprof_error E = static_cast<sampleprof_error>(IE);
|
|
switch (E) {
|
|
case sampleprof_error::success:
|
|
return "Success";
|
|
case sampleprof_error::bad_magic:
|
|
return "Invalid sample profile data (bad magic)";
|
|
case sampleprof_error::unsupported_version:
|
|
return "Unsupported sample profile format version";
|
|
case sampleprof_error::too_large:
|
|
return "Too much profile data";
|
|
case sampleprof_error::truncated:
|
|
return "Truncated profile data";
|
|
case sampleprof_error::malformed:
|
|
return "Malformed sample profile data";
|
|
case sampleprof_error::unrecognized_format:
|
|
return "Unrecognized sample profile encoding format";
|
|
case sampleprof_error::unsupported_writing_format:
|
|
return "Profile encoding format unsupported for writing operations";
|
|
case sampleprof_error::truncated_name_table:
|
|
return "Truncated function name table";
|
|
case sampleprof_error::not_implemented:
|
|
return "Unimplemented feature";
|
|
}
|
|
llvm_unreachable("A value of sampleprof_error has no message.");
|
|
}
|
|
};
|
|
}
|
|
|
|
static ManagedStatic<SampleProfErrorCategoryType> ErrorCategory;
|
|
|
|
const std::error_category &llvm::sampleprof_category() {
|
|
return *ErrorCategory;
|
|
}
|
|
|
|
/// \brief Print the samples collected for a function on stream \p OS.
|
|
///
|
|
/// \param OS Stream to emit the output to.
|
|
void FunctionSamples::print(raw_ostream &OS, unsigned Indent) const {
|
|
OS << TotalSamples << ", " << TotalHeadSamples << ", " << BodySamples.size()
|
|
<< " sampled lines\n";
|
|
for (const auto &SI : BodySamples) {
|
|
LineLocation Loc = SI.first;
|
|
const SampleRecord &Sample = SI.second;
|
|
OS.indent(Indent);
|
|
OS << "line offset: " << Loc.LineOffset
|
|
<< ", discriminator: " << Loc.Discriminator
|
|
<< ", number of samples: " << Sample.getSamples();
|
|
if (Sample.hasCalls()) {
|
|
OS << ", calls:";
|
|
for (const auto &I : Sample.getCallTargets())
|
|
OS << " " << I.first() << ":" << I.second;
|
|
}
|
|
OS << "\n";
|
|
}
|
|
for (const auto &CS : CallsiteSamples) {
|
|
CallsiteLocation Loc = CS.first;
|
|
const FunctionSamples &CalleeSamples = CS.second;
|
|
OS.indent(Indent);
|
|
OS << "line offset: " << Loc.LineOffset
|
|
<< ", discriminator: " << Loc.Discriminator
|
|
<< ", inlined callee: " << Loc.CalleeName << ": ";
|
|
CalleeSamples.print(OS, Indent + 2);
|
|
}
|
|
}
|