示例#1
0
static void mergeInstrProfile(const cl::list<std::string> &Inputs,
                              StringRef OutputFilename) {
  if (OutputFilename.compare("-") == 0)
    exitWithError("Cannot write indexed profdata format to stdout.");

  std::error_code EC;
  raw_fd_ostream Output(OutputFilename.data(), EC, sys::fs::F_None);
  if (EC)
    exitWithError(EC.message(), OutputFilename);

  InstrProfWriter Writer;
  for (const auto &Filename : Inputs) {
    auto ReaderOrErr = InstrProfReader::create(Filename);
    if (std::error_code ec = ReaderOrErr.getError())
      exitWithError(ec.message(), Filename);

    auto Reader = std::move(ReaderOrErr.get());
    for (auto &I : *Reader)
      if (std::error_code EC = Writer.addRecord(std::move(I)))
        errs() << Filename << ": " << I.Name << ": " << EC.message() << "\n";
    if (Reader->hasError())
      exitWithError(Reader->getError().message(), Filename);
  }
  Writer.write(Output);
}
示例#2
0
int merge_main(int argc, const char *argv[]) {
  cl::list<std::string> Inputs(cl::Positional, cl::Required, cl::OneOrMore,
                               cl::desc("<filenames...>"));

  cl::opt<std::string> OutputFilename("output", cl::value_desc("output"),
                                      cl::init("-"), cl::Required,
                                      cl::desc("Output file"));
  cl::alias OutputFilenameA("o", cl::desc("Alias for --output"),
                            cl::aliasopt(OutputFilename));

  cl::ParseCommandLineOptions(argc, argv, "LLVM profile data merger\n");

  if (OutputFilename.compare("-") == 0)
    exitWithError("Cannot write indexed profdata format to stdout.");

  std::string ErrorInfo;
  raw_fd_ostream Output(OutputFilename.data(), ErrorInfo, sys::fs::F_None);
  if (!ErrorInfo.empty())
    exitWithError(ErrorInfo, OutputFilename);

  InstrProfWriter Writer;
  for (const auto &Filename : Inputs) {
    std::unique_ptr<InstrProfReader> Reader;
    if (std::error_code ec = InstrProfReader::create(Filename, Reader))
      exitWithError(ec.message(), Filename);

    for (const auto &I : *Reader)
      if (std::error_code EC =
              Writer.addFunctionCounts(I.Name, I.Hash, I.Counts))
        errs() << Filename << ": " << I.Name << ": " << EC.message() << "\n";
    if (Reader->hasError())
      exitWithError(Reader->getError().message(), Filename);
  }
  Writer.write(Output);

  return 0;
}