Index: bolt/tools/merge-fdata/merge-fdata.cpp =================================================================== --- bolt/tools/merge-fdata/merge-fdata.cpp +++ bolt/tools/merge-fdata/merge-fdata.cpp @@ -64,6 +64,12 @@ cl::Optional, cl::cat(MergeFdataCategory)); +static cl::opt +OutputFilePath("o", + cl::value_desc("file"), + cl::desc("Write output to "), + cl::cat(MergeFdataCategory)); + } // namespace opts namespace { @@ -81,6 +87,18 @@ exit(1); } +static raw_fd_ostream &output() { + if (opts::OutputFilePath.empty() || opts::OutputFilePath == "-") { + return outs(); + } else { + std::error_code EC; + static raw_fd_ostream output(opts::OutputFilePath, EC); + if (EC) + report_error(opts::OutputFilePath, EC); + return output; + } +} + void mergeProfileHeaders(BinaryProfileHeader &MergedHeader, const BinaryProfileHeader &Header) { if (MergedHeader.FileName.empty()) @@ -283,9 +301,9 @@ } if (BoltedCollection) - outs() << "boltedcollection\n"; + output() << "boltedcollection\n"; for (const auto &Entry : Entries) - outs() << Entry.getKey() << " " << Entry.getValue() << "\n"; + output() << Entry.getKey() << " " << Entry.getValue() << "\n"; errs() << "Profile from " << Filenames.size() << " files merged.\n"; } @@ -375,7 +393,7 @@ } if (!opts::SuppressMergedDataOutput) { - yaml::Output YamlOut(outs()); + yaml::Output YamlOut(output()); BinaryProfile MergedProfile; MergedProfile.Header = MergedHeader;