Duncan P. N. Exon Smith | 846a627 | 2014-02-17 23:22:49 +0000 | [diff] [blame] | 1 | //===- llvm-profdata.cpp - LLVM profile data tool -------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // llvm-profdata merges .profdata files. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Nathan Slingerland | c21a44d | 2015-11-18 17:10:24 +0000 | [diff] [blame] | 14 | #include "llvm/ADT/SmallSet.h" |
Nathan Slingerland | 7f5b47d | 2015-12-15 17:37:09 +0000 | [diff] [blame] | 15 | #include "llvm/ADT/SmallVector.h" |
Duncan P. N. Exon Smith | 846a627 | 2014-02-17 23:22:49 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/StringRef.h" |
Chandler Carruth | d990388 | 2015-01-14 11:23:27 +0000 | [diff] [blame] | 17 | #include "llvm/IR/LLVMContext.h" |
Justin Bogner | f8d7919 | 2014-03-21 17:24:48 +0000 | [diff] [blame] | 18 | #include "llvm/ProfileData/InstrProfReader.h" |
Justin Bogner | b9bd7f8 | 2014-03-21 17:46:22 +0000 | [diff] [blame] | 19 | #include "llvm/ProfileData/InstrProfWriter.h" |
Easwaran Raman | d68aae2 | 2016-02-04 23:34:31 +0000 | [diff] [blame] | 20 | #include "llvm/ProfileData/ProfileCommon.h" |
Diego Novillo | d5336ae | 2014-11-01 00:56:55 +0000 | [diff] [blame] | 21 | #include "llvm/ProfileData/SampleProfReader.h" |
| 22 | #include "llvm/ProfileData/SampleProfWriter.h" |
Duncan P. N. Exon Smith | 846a627 | 2014-02-17 23:22:49 +0000 | [diff] [blame] | 23 | #include "llvm/Support/CommandLine.h" |
Nathan Slingerland | 7f5b47d | 2015-12-15 17:37:09 +0000 | [diff] [blame] | 24 | #include "llvm/Support/Errc.h" |
Benjamin Kramer | d59664f | 2014-04-29 23:26:49 +0000 | [diff] [blame] | 25 | #include "llvm/Support/FileSystem.h" |
Justin Bogner | 423380f | 2014-03-23 20:43:50 +0000 | [diff] [blame] | 26 | #include "llvm/Support/Format.h" |
Rui Ueyama | 197194b | 2018-04-13 18:26:06 +0000 | [diff] [blame] | 27 | #include "llvm/Support/InitLLVM.h" |
Duncan P. N. Exon Smith | 846a627 | 2014-02-17 23:22:49 +0000 | [diff] [blame] | 28 | #include "llvm/Support/MemoryBuffer.h" |
Benjamin Kramer | 16132e6 | 2015-03-23 18:07:13 +0000 | [diff] [blame] | 29 | #include "llvm/Support/Path.h" |
Jonas Devlieghere | e46b756 | 2018-04-18 14:42:33 +0000 | [diff] [blame] | 30 | #include "llvm/Support/WithColor.h" |
Vedant Kumar | e3a0bf5 | 2016-07-19 01:17:20 +0000 | [diff] [blame] | 31 | #include "llvm/Support/ThreadPool.h" |
Duncan P. N. Exon Smith | 846a627 | 2014-02-17 23:22:49 +0000 | [diff] [blame] | 32 | #include "llvm/Support/raw_ostream.h" |
Nathan Slingerland | 7f5b47d | 2015-12-15 17:37:09 +0000 | [diff] [blame] | 33 | #include <algorithm> |
Duncan P. N. Exon Smith | 846a627 | 2014-02-17 23:22:49 +0000 | [diff] [blame] | 34 | |
| 35 | using namespace llvm; |
| 36 | |
Wei Mi | a0c0857 | 2018-06-11 22:40:43 +0000 | [diff] [blame] | 37 | enum ProfileFormat { |
| 38 | PF_None = 0, |
| 39 | PF_Text, |
| 40 | PF_Compact_Binary, |
| 41 | PF_GCC, |
| 42 | PF_Raw_Binary |
| 43 | }; |
Xinliang David Li | 6f7c19a | 2015-11-23 20:47:38 +0000 | [diff] [blame] | 44 | |
Jonas Devlieghere | e46b756 | 2018-04-18 14:42:33 +0000 | [diff] [blame] | 45 | static void warn(Twine Message, std::string Whence = "", |
Vedant Kumar | 188efda | 2017-11-17 21:18:32 +0000 | [diff] [blame] | 46 | std::string Hint = "") { |
Jonas Devlieghere | e46b756 | 2018-04-18 14:42:33 +0000 | [diff] [blame] | 47 | WithColor::warning(); |
Justin Bogner | f8d7919 | 2014-03-21 17:24:48 +0000 | [diff] [blame] | 48 | if (!Whence.empty()) |
| 49 | errs() << Whence << ": "; |
| 50 | errs() << Message << "\n"; |
Nathan Slingerland | 4f82366 | 2015-11-13 03:47:58 +0000 | [diff] [blame] | 51 | if (!Hint.empty()) |
Jonas Devlieghere | e46b756 | 2018-04-18 14:42:33 +0000 | [diff] [blame] | 52 | WithColor::note() << Hint << "\n"; |
Vedant Kumar | 188efda | 2017-11-17 21:18:32 +0000 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | static void exitWithError(Twine Message, std::string Whence = "", |
| 56 | std::string Hint = "") { |
Jonas Devlieghere | e46b756 | 2018-04-18 14:42:33 +0000 | [diff] [blame] | 57 | WithColor::error(); |
| 58 | if (!Whence.empty()) |
| 59 | errs() << Whence << ": "; |
| 60 | errs() << Message << "\n"; |
| 61 | if (!Hint.empty()) |
| 62 | WithColor::note() << Hint << "\n"; |
Duncan P. N. Exon Smith | 846a627 | 2014-02-17 23:22:49 +0000 | [diff] [blame] | 63 | ::exit(1); |
| 64 | } |
| 65 | |
Vedant Kumar | 9152fd1 | 2016-05-19 03:54:45 +0000 | [diff] [blame] | 66 | static void exitWithError(Error E, StringRef Whence = "") { |
| 67 | if (E.isA<InstrProfError>()) { |
| 68 | handleAllErrors(std::move(E), [&](const InstrProfError &IPE) { |
| 69 | instrprof_error instrError = IPE.get(); |
| 70 | StringRef Hint = ""; |
| 71 | if (instrError == instrprof_error::unrecognized_format) { |
| 72 | // Hint for common error of forgetting -sample for sample profiles. |
| 73 | Hint = "Perhaps you forgot to use the -sample option?"; |
| 74 | } |
| 75 | exitWithError(IPE.message(), Whence, Hint); |
| 76 | }); |
Nathan Slingerland | 4f82366 | 2015-11-13 03:47:58 +0000 | [diff] [blame] | 77 | } |
Vedant Kumar | 9152fd1 | 2016-05-19 03:54:45 +0000 | [diff] [blame] | 78 | |
| 79 | exitWithError(toString(std::move(E)), Whence); |
| 80 | } |
| 81 | |
| 82 | static void exitWithErrorCode(std::error_code EC, StringRef Whence = "") { |
| 83 | exitWithError(EC.message(), Whence); |
Nathan Slingerland | 4f82366 | 2015-11-13 03:47:58 +0000 | [diff] [blame] | 84 | } |
| 85 | |
Duncan P. N. Exon Smith | 02b6fa9 | 2015-06-16 00:43:04 +0000 | [diff] [blame] | 86 | namespace { |
Diego Novillo | d3babdb | 2015-12-14 20:37:15 +0000 | [diff] [blame] | 87 | enum ProfileKinds { instr, sample }; |
Duncan P. N. Exon Smith | 02b6fa9 | 2015-06-16 00:43:04 +0000 | [diff] [blame] | 88 | } |
Justin Bogner | 618bcea | 2014-03-19 02:20:46 +0000 | [diff] [blame] | 89 | |
Vedant Kumar | 9152fd1 | 2016-05-19 03:54:45 +0000 | [diff] [blame] | 90 | static void handleMergeWriterError(Error E, StringRef WhenceFile = "", |
Nathan Slingerland | e6e30d5 | 2015-11-17 22:08:53 +0000 | [diff] [blame] | 91 | StringRef WhenceFunction = "", |
Diego Novillo | d3babdb | 2015-12-14 20:37:15 +0000 | [diff] [blame] | 92 | bool ShowHint = true) { |
Nathan Slingerland | e6e30d5 | 2015-11-17 22:08:53 +0000 | [diff] [blame] | 93 | if (!WhenceFile.empty()) |
| 94 | errs() << WhenceFile << ": "; |
| 95 | if (!WhenceFunction.empty()) |
| 96 | errs() << WhenceFunction << ": "; |
Vedant Kumar | 9152fd1 | 2016-05-19 03:54:45 +0000 | [diff] [blame] | 97 | |
| 98 | auto IPE = instrprof_error::success; |
| 99 | E = handleErrors(std::move(E), |
| 100 | [&IPE](std::unique_ptr<InstrProfError> E) -> Error { |
| 101 | IPE = E->get(); |
| 102 | return Error(std::move(E)); |
| 103 | }); |
| 104 | errs() << toString(std::move(E)) << "\n"; |
Nathan Slingerland | e6e30d5 | 2015-11-17 22:08:53 +0000 | [diff] [blame] | 105 | |
| 106 | if (ShowHint) { |
| 107 | StringRef Hint = ""; |
Vedant Kumar | 9152fd1 | 2016-05-19 03:54:45 +0000 | [diff] [blame] | 108 | if (IPE != instrprof_error::success) { |
| 109 | switch (IPE) { |
Nathan Slingerland | 11c938d1 | 2015-11-17 23:37:09 +0000 | [diff] [blame] | 110 | case instrprof_error::hash_mismatch: |
| 111 | case instrprof_error::count_mismatch: |
| 112 | case instrprof_error::value_site_count_mismatch: |
Diego Novillo | d3babdb | 2015-12-14 20:37:15 +0000 | [diff] [blame] | 113 | Hint = "Make sure that all profile data to be merged is generated " |
Nathan Slingerland | e6e30d5 | 2015-11-17 22:08:53 +0000 | [diff] [blame] | 114 | "from the same binary."; |
Nathan Slingerland | 11c938d1 | 2015-11-17 23:37:09 +0000 | [diff] [blame] | 115 | break; |
Nathan Slingerland | b2d95f0 | 2015-11-18 00:52:45 +0000 | [diff] [blame] | 116 | default: |
| 117 | break; |
Nathan Slingerland | e6e30d5 | 2015-11-17 22:08:53 +0000 | [diff] [blame] | 118 | } |
| 119 | } |
| 120 | |
| 121 | if (!Hint.empty()) |
| 122 | errs() << Hint << "\n"; |
| 123 | } |
| 124 | } |
| 125 | |
Nathan Slingerland | 7f5b47d | 2015-12-15 17:37:09 +0000 | [diff] [blame] | 126 | struct WeightedFile { |
Xinliang David Li | 9a1bfcf | 2016-07-20 22:24:52 +0000 | [diff] [blame] | 127 | std::string Filename; |
Nathan Slingerland | 7f5b47d | 2015-12-15 17:37:09 +0000 | [diff] [blame] | 128 | uint64_t Weight; |
Nathan Slingerland | 7f5b47d | 2015-12-15 17:37:09 +0000 | [diff] [blame] | 129 | }; |
| 130 | typedef SmallVector<WeightedFile, 5> WeightedFileVector; |
| 131 | |
Vedant Kumar | e3a0bf5 | 2016-07-19 01:17:20 +0000 | [diff] [blame] | 132 | /// Keep track of merged data and reported errors. |
| 133 | struct WriterContext { |
| 134 | std::mutex Lock; |
| 135 | InstrProfWriter Writer; |
| 136 | Error Err; |
Vedant Kumar | faaa42a | 2017-11-17 02:58:23 +0000 | [diff] [blame] | 137 | std::string ErrWhence; |
Vedant Kumar | e3a0bf5 | 2016-07-19 01:17:20 +0000 | [diff] [blame] | 138 | std::mutex &ErrLock; |
| 139 | SmallSet<instrprof_error, 4> &WriterErrorCodes; |
| 140 | |
| 141 | WriterContext(bool IsSparse, std::mutex &ErrLock, |
| 142 | SmallSet<instrprof_error, 4> &WriterErrorCodes) |
| 143 | : Lock(), Writer(IsSparse), Err(Error::success()), ErrWhence(""), |
| 144 | ErrLock(ErrLock), WriterErrorCodes(WriterErrorCodes) {} |
| 145 | }; |
| 146 | |
Vedant Kumar | 188efda | 2017-11-17 21:18:32 +0000 | [diff] [blame] | 147 | /// Determine whether an error is fatal for profile merging. |
| 148 | static bool isFatalError(instrprof_error IPE) { |
| 149 | switch (IPE) { |
| 150 | default: |
| 151 | return true; |
| 152 | case instrprof_error::success: |
| 153 | case instrprof_error::eof: |
| 154 | case instrprof_error::unknown_function: |
| 155 | case instrprof_error::hash_mismatch: |
| 156 | case instrprof_error::count_mismatch: |
| 157 | case instrprof_error::counter_overflow: |
| 158 | case instrprof_error::value_site_count_mismatch: |
| 159 | return false; |
| 160 | } |
| 161 | } |
| 162 | |
Vedant Kumar | e3a0bf5 | 2016-07-19 01:17:20 +0000 | [diff] [blame] | 163 | /// Load an input into a writer context. |
| 164 | static void loadInput(const WeightedFile &Input, WriterContext *WC) { |
| 165 | std::unique_lock<std::mutex> CtxGuard{WC->Lock}; |
| 166 | |
| 167 | // If there's a pending hard error, don't do more work. |
| 168 | if (WC->Err) |
| 169 | return; |
| 170 | |
Vedant Kumar | faaa42a | 2017-11-17 02:58:23 +0000 | [diff] [blame] | 171 | // Copy the filename, because llvm::ThreadPool copied the input "const |
| 172 | // WeightedFile &" by value, making a reference to the filename within it |
| 173 | // invalid outside of this packaged task. |
Vedant Kumar | e3a0bf5 | 2016-07-19 01:17:20 +0000 | [diff] [blame] | 174 | WC->ErrWhence = Input.Filename; |
| 175 | |
| 176 | auto ReaderOrErr = InstrProfReader::create(Input.Filename); |
Rong Xu | 2c684cf | 2016-10-19 22:51:17 +0000 | [diff] [blame] | 177 | if (Error E = ReaderOrErr.takeError()) { |
| 178 | // Skip the empty profiles by returning sliently. |
| 179 | instrprof_error IPE = InstrProfError::take(std::move(E)); |
| 180 | if (IPE != instrprof_error::empty_raw_profile) |
| 181 | WC->Err = make_error<InstrProfError>(IPE); |
Vedant Kumar | e3a0bf5 | 2016-07-19 01:17:20 +0000 | [diff] [blame] | 182 | return; |
Rong Xu | 2c684cf | 2016-10-19 22:51:17 +0000 | [diff] [blame] | 183 | } |
Vedant Kumar | e3a0bf5 | 2016-07-19 01:17:20 +0000 | [diff] [blame] | 184 | |
| 185 | auto Reader = std::move(ReaderOrErr.get()); |
| 186 | bool IsIRProfile = Reader->isIRLevelProfile(); |
| 187 | if (WC->Writer.setIsIRLevelProfile(IsIRProfile)) { |
| 188 | WC->Err = make_error<StringError>( |
| 189 | "Merge IR generated profile with Clang generated profile.", |
| 190 | std::error_code()); |
| 191 | return; |
| 192 | } |
| 193 | |
| 194 | for (auto &I : *Reader) { |
Rong Xu | fe90d86 | 2016-10-19 23:31:59 +0000 | [diff] [blame] | 195 | const StringRef FuncName = I.Name; |
David Blaikie | 98cce00 | 2017-07-10 03:04:59 +0000 | [diff] [blame] | 196 | bool Reported = false; |
| 197 | WC->Writer.addRecord(std::move(I), Input.Weight, [&](Error E) { |
| 198 | if (Reported) { |
| 199 | consumeError(std::move(E)); |
| 200 | return; |
| 201 | } |
| 202 | Reported = true; |
Vedant Kumar | e3a0bf5 | 2016-07-19 01:17:20 +0000 | [diff] [blame] | 203 | // Only show hint the first time an error occurs. |
| 204 | instrprof_error IPE = InstrProfError::take(std::move(E)); |
| 205 | std::unique_lock<std::mutex> ErrGuard{WC->ErrLock}; |
| 206 | bool firstTime = WC->WriterErrorCodes.insert(IPE).second; |
| 207 | handleMergeWriterError(make_error<InstrProfError>(IPE), Input.Filename, |
Rong Xu | fe90d86 | 2016-10-19 23:31:59 +0000 | [diff] [blame] | 208 | FuncName, firstTime); |
David Blaikie | 98cce00 | 2017-07-10 03:04:59 +0000 | [diff] [blame] | 209 | }); |
Vedant Kumar | e3a0bf5 | 2016-07-19 01:17:20 +0000 | [diff] [blame] | 210 | } |
Vedant Kumar | 188efda | 2017-11-17 21:18:32 +0000 | [diff] [blame] | 211 | if (Reader->hasError()) { |
| 212 | if (Error E = Reader->getError()) { |
| 213 | instrprof_error IPE = InstrProfError::take(std::move(E)); |
| 214 | if (isFatalError(IPE)) |
| 215 | WC->Err = make_error<InstrProfError>(IPE); |
| 216 | } |
| 217 | } |
Vedant Kumar | e3a0bf5 | 2016-07-19 01:17:20 +0000 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | /// Merge the \p Src writer context into \p Dst. |
| 221 | static void mergeWriterContexts(WriterContext *Dst, WriterContext *Src) { |
Vedant Kumar | faaa42a | 2017-11-17 02:58:23 +0000 | [diff] [blame] | 222 | // If we've already seen a hard error, continuing with the merge would |
| 223 | // clobber it. |
| 224 | if (Dst->Err || Src->Err) |
| 225 | return; |
| 226 | |
David Blaikie | 98cce00 | 2017-07-10 03:04:59 +0000 | [diff] [blame] | 227 | bool Reported = false; |
| 228 | Dst->Writer.mergeRecordsFromWriter(std::move(Src->Writer), [&](Error E) { |
| 229 | if (Reported) { |
| 230 | consumeError(std::move(E)); |
| 231 | return; |
| 232 | } |
| 233 | Reported = true; |
Vedant Kumar | e3a0bf5 | 2016-07-19 01:17:20 +0000 | [diff] [blame] | 234 | Dst->Err = std::move(E); |
David Blaikie | 98cce00 | 2017-07-10 03:04:59 +0000 | [diff] [blame] | 235 | }); |
Vedant Kumar | e3a0bf5 | 2016-07-19 01:17:20 +0000 | [diff] [blame] | 236 | } |
| 237 | |
Nathan Slingerland | 7f5b47d | 2015-12-15 17:37:09 +0000 | [diff] [blame] | 238 | static void mergeInstrProfile(const WeightedFileVector &Inputs, |
Xinliang David Li | 6f7c19a | 2015-11-23 20:47:38 +0000 | [diff] [blame] | 239 | StringRef OutputFilename, |
Vedant Kumar | e3a0bf5 | 2016-07-19 01:17:20 +0000 | [diff] [blame] | 240 | ProfileFormat OutputFormat, bool OutputSparse, |
| 241 | unsigned NumThreads) { |
Justin Bogner | b7aa263 | 2014-04-18 21:48:40 +0000 | [diff] [blame] | 242 | if (OutputFilename.compare("-") == 0) |
| 243 | exitWithError("Cannot write indexed profdata format to stdout."); |
Justin Bogner | ec49f98 | 2014-03-12 22:00:57 +0000 | [diff] [blame] | 244 | |
Wei Mi | a0c0857 | 2018-06-11 22:40:43 +0000 | [diff] [blame] | 245 | if (OutputFormat != PF_Raw_Binary && OutputFormat != PF_Compact_Binary && |
| 246 | OutputFormat != PF_Text) |
Xinliang David Li | 6f7c19a | 2015-11-23 20:47:38 +0000 | [diff] [blame] | 247 | exitWithError("Unknown format is specified."); |
| 248 | |
Rafael Espindola | 3fd1e99 | 2014-08-25 18:16:47 +0000 | [diff] [blame] | 249 | std::error_code EC; |
| 250 | raw_fd_ostream Output(OutputFilename.data(), EC, sys::fs::F_None); |
| 251 | if (EC) |
Nathan Slingerland | 4f82366 | 2015-11-13 03:47:58 +0000 | [diff] [blame] | 252 | exitWithErrorCode(EC, OutputFilename); |
Justin Bogner | ec49f98 | 2014-03-12 22:00:57 +0000 | [diff] [blame] | 253 | |
Vedant Kumar | e3a0bf5 | 2016-07-19 01:17:20 +0000 | [diff] [blame] | 254 | std::mutex ErrorLock; |
Vedant Kumar | 9152fd1 | 2016-05-19 03:54:45 +0000 | [diff] [blame] | 255 | SmallSet<instrprof_error, 4> WriterErrorCodes; |
Justin Bogner | f8d7919 | 2014-03-21 17:24:48 +0000 | [diff] [blame] | 256 | |
Vedant Kumar | e3a0bf5 | 2016-07-19 01:17:20 +0000 | [diff] [blame] | 257 | // If NumThreads is not specified, auto-detect a good default. |
| 258 | if (NumThreads == 0) |
Rafael Espindola | 8c0ff95 | 2017-10-04 20:27:01 +0000 | [diff] [blame] | 259 | NumThreads = |
| 260 | std::min(hardware_concurrency(), unsigned((Inputs.size() + 1) / 2)); |
Rong Xu | 33c76c0 | 2016-02-10 17:18:30 +0000 | [diff] [blame] | 261 | |
Vedant Kumar | e3a0bf5 | 2016-07-19 01:17:20 +0000 | [diff] [blame] | 262 | // Initialize the writer contexts. |
| 263 | SmallVector<std::unique_ptr<WriterContext>, 4> Contexts; |
| 264 | for (unsigned I = 0; I < NumThreads; ++I) |
| 265 | Contexts.emplace_back(llvm::make_unique<WriterContext>( |
| 266 | OutputSparse, ErrorLock, WriterErrorCodes)); |
| 267 | |
| 268 | if (NumThreads == 1) { |
| 269 | for (const auto &Input : Inputs) |
| 270 | loadInput(Input, Contexts[0].get()); |
| 271 | } else { |
| 272 | ThreadPool Pool(NumThreads); |
| 273 | |
| 274 | // Load the inputs in parallel (N/NumThreads serial steps). |
| 275 | unsigned Ctx = 0; |
| 276 | for (const auto &Input : Inputs) { |
| 277 | Pool.async(loadInput, Input, Contexts[Ctx].get()); |
| 278 | Ctx = (Ctx + 1) % NumThreads; |
Nathan Slingerland | e6e30d5 | 2015-11-17 22:08:53 +0000 | [diff] [blame] | 279 | } |
Vedant Kumar | e3a0bf5 | 2016-07-19 01:17:20 +0000 | [diff] [blame] | 280 | Pool.wait(); |
| 281 | |
| 282 | // Merge the writer contexts together (~ lg(NumThreads) serial steps). |
| 283 | unsigned Mid = Contexts.size() / 2; |
| 284 | unsigned End = Contexts.size(); |
| 285 | assert(Mid > 0 && "Expected more than one context"); |
| 286 | do { |
| 287 | for (unsigned I = 0; I < Mid; ++I) |
| 288 | Pool.async(mergeWriterContexts, Contexts[I].get(), |
| 289 | Contexts[I + Mid].get()); |
| 290 | Pool.wait(); |
| 291 | if (End & 1) { |
| 292 | Pool.async(mergeWriterContexts, Contexts[0].get(), |
| 293 | Contexts[End - 1].get()); |
| 294 | Pool.wait(); |
| 295 | } |
| 296 | End = Mid; |
| 297 | Mid /= 2; |
| 298 | } while (Mid > 0); |
Justin Bogner | bfee8d4 | 2014-03-12 20:14:17 +0000 | [diff] [blame] | 299 | } |
Vedant Kumar | e3a0bf5 | 2016-07-19 01:17:20 +0000 | [diff] [blame] | 300 | |
| 301 | // Handle deferred hard errors encountered during merging. |
Vedant Kumar | 188efda | 2017-11-17 21:18:32 +0000 | [diff] [blame] | 302 | for (std::unique_ptr<WriterContext> &WC : Contexts) { |
| 303 | if (!WC->Err) |
| 304 | continue; |
| 305 | if (!WC->Err.isA<InstrProfError>()) |
Vedant Kumar | e3a0bf5 | 2016-07-19 01:17:20 +0000 | [diff] [blame] | 306 | exitWithError(std::move(WC->Err), WC->ErrWhence); |
| 307 | |
Vedant Kumar | 188efda | 2017-11-17 21:18:32 +0000 | [diff] [blame] | 308 | instrprof_error IPE = InstrProfError::take(std::move(WC->Err)); |
| 309 | if (isFatalError(IPE)) |
| 310 | exitWithError(make_error<InstrProfError>(IPE), WC->ErrWhence); |
| 311 | else |
Jonas Devlieghere | e46b756 | 2018-04-18 14:42:33 +0000 | [diff] [blame] | 312 | warn(toString(make_error<InstrProfError>(IPE)), |
Vedant Kumar | 188efda | 2017-11-17 21:18:32 +0000 | [diff] [blame] | 313 | WC->ErrWhence); |
| 314 | } |
| 315 | |
Vedant Kumar | e3a0bf5 | 2016-07-19 01:17:20 +0000 | [diff] [blame] | 316 | InstrProfWriter &Writer = Contexts[0]->Writer; |
Vedant Kumar | b5794ca | 2017-06-20 01:38:56 +0000 | [diff] [blame] | 317 | if (OutputFormat == PF_Text) { |
| 318 | if (Error E = Writer.writeText(Output)) |
| 319 | exitWithError(std::move(E)); |
| 320 | } else { |
Xinliang David Li | 6f7c19a | 2015-11-23 20:47:38 +0000 | [diff] [blame] | 321 | Writer.write(Output); |
Vedant Kumar | b5794ca | 2017-06-20 01:38:56 +0000 | [diff] [blame] | 322 | } |
Diego Novillo | d5336ae | 2014-11-01 00:56:55 +0000 | [diff] [blame] | 323 | } |
| 324 | |
Xinliang David Li | 6f7c19a | 2015-11-23 20:47:38 +0000 | [diff] [blame] | 325 | static sampleprof::SampleProfileFormat FormatMap[] = { |
Wei Mi | a0c0857 | 2018-06-11 22:40:43 +0000 | [diff] [blame] | 326 | sampleprof::SPF_None, sampleprof::SPF_Text, sampleprof::SPF_Compact_Binary, |
| 327 | sampleprof::SPF_GCC, sampleprof::SPF_Raw_Binary}; |
Xinliang David Li | 6f7c19a | 2015-11-23 20:47:38 +0000 | [diff] [blame] | 328 | |
Nathan Slingerland | 7f5b47d | 2015-12-15 17:37:09 +0000 | [diff] [blame] | 329 | static void mergeSampleProfile(const WeightedFileVector &Inputs, |
Benjamin Kramer | f044d3f | 2015-03-09 16:23:46 +0000 | [diff] [blame] | 330 | StringRef OutputFilename, |
Xinliang David Li | 6f7c19a | 2015-11-23 20:47:38 +0000 | [diff] [blame] | 331 | ProfileFormat OutputFormat) { |
Diego Novillo | d5336ae | 2014-11-01 00:56:55 +0000 | [diff] [blame] | 332 | using namespace sampleprof; |
Xinliang David Li | 6f7c19a | 2015-11-23 20:47:38 +0000 | [diff] [blame] | 333 | auto WriterOrErr = |
| 334 | SampleProfileWriter::create(OutputFilename, FormatMap[OutputFormat]); |
Diego Novillo | fcd5560 | 2014-11-03 00:51:45 +0000 | [diff] [blame] | 335 | if (std::error_code EC = WriterOrErr.getError()) |
Nathan Slingerland | 4f82366 | 2015-11-13 03:47:58 +0000 | [diff] [blame] | 336 | exitWithErrorCode(EC, OutputFilename); |
Diego Novillo | d5336ae | 2014-11-01 00:56:55 +0000 | [diff] [blame] | 337 | |
Diego Novillo | fcd5560 | 2014-11-03 00:51:45 +0000 | [diff] [blame] | 338 | auto Writer = std::move(WriterOrErr.get()); |
Diego Novillo | d5336ae | 2014-11-01 00:56:55 +0000 | [diff] [blame] | 339 | StringMap<FunctionSamples> ProfileMap; |
Diego Novillo | aae1ed8 | 2015-10-08 19:40:37 +0000 | [diff] [blame] | 340 | SmallVector<std::unique_ptr<sampleprof::SampleProfileReader>, 5> Readers; |
Mehdi Amini | 03b42e4 | 2016-04-14 21:59:01 +0000 | [diff] [blame] | 341 | LLVMContext Context; |
Nathan Slingerland | 7f5b47d | 2015-12-15 17:37:09 +0000 | [diff] [blame] | 342 | for (const auto &Input : Inputs) { |
Mehdi Amini | 03b42e4 | 2016-04-14 21:59:01 +0000 | [diff] [blame] | 343 | auto ReaderOrErr = SampleProfileReader::create(Input.Filename, Context); |
Diego Novillo | fcd5560 | 2014-11-03 00:51:45 +0000 | [diff] [blame] | 344 | if (std::error_code EC = ReaderOrErr.getError()) |
Nathan Slingerland | 7f5b47d | 2015-12-15 17:37:09 +0000 | [diff] [blame] | 345 | exitWithErrorCode(EC, Input.Filename); |
Diego Novillo | d5336ae | 2014-11-01 00:56:55 +0000 | [diff] [blame] | 346 | |
Diego Novillo | aae1ed8 | 2015-10-08 19:40:37 +0000 | [diff] [blame] | 347 | // We need to keep the readers around until after all the files are |
| 348 | // read so that we do not lose the function names stored in each |
| 349 | // reader's memory. The function names are needed to write out the |
| 350 | // merged profile map. |
| 351 | Readers.push_back(std::move(ReaderOrErr.get())); |
| 352 | const auto Reader = Readers.back().get(); |
Diego Novillo | d5336ae | 2014-11-01 00:56:55 +0000 | [diff] [blame] | 353 | if (std::error_code EC = Reader->read()) |
Nathan Slingerland | 7f5b47d | 2015-12-15 17:37:09 +0000 | [diff] [blame] | 354 | exitWithErrorCode(EC, Input.Filename); |
Diego Novillo | d5336ae | 2014-11-01 00:56:55 +0000 | [diff] [blame] | 355 | |
| 356 | StringMap<FunctionSamples> &Profiles = Reader->getProfiles(); |
| 357 | for (StringMap<FunctionSamples>::iterator I = Profiles.begin(), |
| 358 | E = Profiles.end(); |
| 359 | I != E; ++I) { |
| 360 | StringRef FName = I->first(); |
| 361 | FunctionSamples &Samples = I->second; |
Nathan Slingerland | 48dd080 | 2015-12-16 21:45:43 +0000 | [diff] [blame] | 362 | sampleprof_error Result = ProfileMap[FName].merge(Samples, Input.Weight); |
| 363 | if (Result != sampleprof_error::success) { |
| 364 | std::error_code EC = make_error_code(Result); |
Vedant Kumar | 9152fd1 | 2016-05-19 03:54:45 +0000 | [diff] [blame] | 365 | handleMergeWriterError(errorCodeToError(EC), Input.Filename, FName); |
Nathan Slingerland | 48dd080 | 2015-12-16 21:45:43 +0000 | [diff] [blame] | 366 | } |
Diego Novillo | d5336ae | 2014-11-01 00:56:55 +0000 | [diff] [blame] | 367 | } |
| 368 | } |
| 369 | Writer->write(ProfileMap); |
| 370 | } |
| 371 | |
Nathan Slingerland | 7f5b47d | 2015-12-15 17:37:09 +0000 | [diff] [blame] | 372 | static WeightedFile parseWeightedFile(const StringRef &WeightedFilename) { |
Vedant Kumar | 8d0e861 | 2016-06-06 23:43:56 +0000 | [diff] [blame] | 373 | StringRef WeightStr, FileName; |
| 374 | std::tie(WeightStr, FileName) = WeightedFilename.split(','); |
Diego Novillo | d5336ae | 2014-11-01 00:56:55 +0000 | [diff] [blame] | 375 | |
Nathan Slingerland | 7f5b47d | 2015-12-15 17:37:09 +0000 | [diff] [blame] | 376 | uint64_t Weight; |
| 377 | if (WeightStr.getAsInteger(10, Weight) || Weight < 1) |
| 378 | exitWithError("Input weight must be a positive integer."); |
| 379 | |
Benjamin Kramer | 929e7db | 2016-07-21 14:29:11 +0000 | [diff] [blame] | 380 | return {FileName, Weight}; |
Nathan Slingerland | 7f5b47d | 2015-12-15 17:37:09 +0000 | [diff] [blame] | 381 | } |
| 382 | |
Vedant Kumar | cef4360 | 2016-06-07 22:47:31 +0000 | [diff] [blame] | 383 | static std::unique_ptr<MemoryBuffer> |
| 384 | getInputFilenamesFileBuf(const StringRef &InputFilenamesFile) { |
| 385 | if (InputFilenamesFile == "") |
| 386 | return {}; |
| 387 | |
| 388 | auto BufOrError = MemoryBuffer::getFileOrSTDIN(InputFilenamesFile); |
| 389 | if (!BufOrError) |
| 390 | exitWithErrorCode(BufOrError.getError(), InputFilenamesFile); |
| 391 | |
| 392 | return std::move(*BufOrError); |
| 393 | } |
| 394 | |
Xinliang David Li | 9a1bfcf | 2016-07-20 22:24:52 +0000 | [diff] [blame] | 395 | static void addWeightedInput(WeightedFileVector &WNI, const WeightedFile &WF) { |
| 396 | StringRef Filename = WF.Filename; |
| 397 | uint64_t Weight = WF.Weight; |
Benjamin Kramer | a81f472 | 2016-07-22 12:39:55 +0000 | [diff] [blame] | 398 | |
| 399 | // If it's STDIN just pass it on. |
| 400 | if (Filename == "-") { |
| 401 | WNI.push_back({Filename, Weight}); |
| 402 | return; |
| 403 | } |
| 404 | |
Xinliang David Li | 9a1bfcf | 2016-07-20 22:24:52 +0000 | [diff] [blame] | 405 | llvm::sys::fs::file_status Status; |
| 406 | llvm::sys::fs::status(Filename, Status); |
| 407 | if (!llvm::sys::fs::exists(Status)) |
| 408 | exitWithErrorCode(make_error_code(errc::no_such_file_or_directory), |
| 409 | Filename); |
| 410 | // If it's a source file, collect it. |
| 411 | if (llvm::sys::fs::is_regular_file(Status)) { |
Benjamin Kramer | 929e7db | 2016-07-21 14:29:11 +0000 | [diff] [blame] | 412 | WNI.push_back({Filename, Weight}); |
Xinliang David Li | 9a1bfcf | 2016-07-20 22:24:52 +0000 | [diff] [blame] | 413 | return; |
| 414 | } |
| 415 | |
| 416 | if (llvm::sys::fs::is_directory(Status)) { |
| 417 | std::error_code EC; |
| 418 | for (llvm::sys::fs::recursive_directory_iterator F(Filename, EC), E; |
| 419 | F != E && !EC; F.increment(EC)) { |
| 420 | if (llvm::sys::fs::is_regular_file(F->path())) { |
| 421 | addWeightedInput(WNI, {F->path(), Weight}); |
| 422 | } |
| 423 | } |
| 424 | if (EC) |
| 425 | exitWithErrorCode(EC, Filename); |
| 426 | } |
| 427 | } |
| 428 | |
Vedant Kumar | cef4360 | 2016-06-07 22:47:31 +0000 | [diff] [blame] | 429 | static void parseInputFilenamesFile(MemoryBuffer *Buffer, |
| 430 | WeightedFileVector &WFV) { |
| 431 | if (!Buffer) |
| 432 | return; |
| 433 | |
| 434 | SmallVector<StringRef, 8> Entries; |
| 435 | StringRef Data = Buffer->getBuffer(); |
| 436 | Data.split(Entries, '\n', /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
| 437 | for (const StringRef &FileWeightEntry : Entries) { |
| 438 | StringRef SanitizedEntry = FileWeightEntry.trim(" \t\v\f\r"); |
| 439 | // Skip comments. |
| 440 | if (SanitizedEntry.startswith("#")) |
| 441 | continue; |
| 442 | // If there's no comma, it's an unweighted profile. |
| 443 | else if (SanitizedEntry.find(',') == StringRef::npos) |
Xinliang David Li | 9a1bfcf | 2016-07-20 22:24:52 +0000 | [diff] [blame] | 444 | addWeightedInput(WFV, {SanitizedEntry, 1}); |
Vedant Kumar | cef4360 | 2016-06-07 22:47:31 +0000 | [diff] [blame] | 445 | else |
Xinliang David Li | 9a1bfcf | 2016-07-20 22:24:52 +0000 | [diff] [blame] | 446 | addWeightedInput(WFV, parseWeightedFile(SanitizedEntry)); |
Vedant Kumar | cef4360 | 2016-06-07 22:47:31 +0000 | [diff] [blame] | 447 | } |
| 448 | } |
| 449 | |
Nathan Slingerland | 7f5b47d | 2015-12-15 17:37:09 +0000 | [diff] [blame] | 450 | static int merge_main(int argc, const char *argv[]) { |
| 451 | cl::list<std::string> InputFilenames(cl::Positional, |
| 452 | cl::desc("<filename...>")); |
| 453 | cl::list<std::string> WeightedInputFilenames("weighted-input", |
| 454 | cl::desc("<weight>,<filename>")); |
Vedant Kumar | cef4360 | 2016-06-07 22:47:31 +0000 | [diff] [blame] | 455 | cl::opt<std::string> InputFilenamesFile( |
| 456 | "input-files", cl::init(""), |
| 457 | cl::desc("Path to file containing newline-separated " |
| 458 | "[<weight>,]<filename> entries")); |
| 459 | cl::alias InputFilenamesFileA("f", cl::desc("Alias for --input-files"), |
| 460 | cl::aliasopt(InputFilenamesFile)); |
| 461 | cl::opt<bool> DumpInputFileList( |
| 462 | "dump-input-file-list", cl::init(false), cl::Hidden, |
| 463 | cl::desc("Dump the list of input files and their weights, then exit")); |
Diego Novillo | d5336ae | 2014-11-01 00:56:55 +0000 | [diff] [blame] | 464 | cl::opt<std::string> OutputFilename("output", cl::value_desc("output"), |
| 465 | cl::init("-"), cl::Required, |
| 466 | cl::desc("Output file")); |
| 467 | cl::alias OutputFilenameA("o", cl::desc("Alias for --output"), |
| 468 | cl::aliasopt(OutputFilename)); |
| 469 | cl::opt<ProfileKinds> ProfileKind( |
| 470 | cl::desc("Profile kind:"), cl::init(instr), |
| 471 | cl::values(clEnumVal(instr, "Instrumentation profile (default)"), |
Mehdi Amini | 732afdd | 2016-10-08 19:41:06 +0000 | [diff] [blame] | 472 | clEnumVal(sample, "Sample profile"))); |
Xinliang David Li | 6f7c19a | 2015-11-23 20:47:38 +0000 | [diff] [blame] | 473 | cl::opt<ProfileFormat> OutputFormat( |
Wei Mi | a0c0857 | 2018-06-11 22:40:43 +0000 | [diff] [blame] | 474 | cl::desc("Format of output profile"), cl::init(PF_Raw_Binary), |
| 475 | cl::values( |
| 476 | clEnumValN(PF_Raw_Binary, "binary", "Binary encoding (default)"), |
| 477 | clEnumValN(PF_Compact_Binary, "compbinary", |
Wei Mi | 432db3b | 2018-06-12 04:43:09 +0000 | [diff] [blame^] | 478 | "Compact binary encoding"), |
Wei Mi | a0c0857 | 2018-06-11 22:40:43 +0000 | [diff] [blame] | 479 | clEnumValN(PF_Text, "text", "Text encoding"), |
| 480 | clEnumValN(PF_GCC, "gcc", |
| 481 | "GCC encoding (only meaningful for -sample)"))); |
Vedant Kumar | 00dab22 | 2016-01-29 22:54:45 +0000 | [diff] [blame] | 482 | cl::opt<bool> OutputSparse("sparse", cl::init(false), |
| 483 | cl::desc("Generate a sparse profile (only meaningful for -instr)")); |
Vedant Kumar | e3a0bf5 | 2016-07-19 01:17:20 +0000 | [diff] [blame] | 484 | cl::opt<unsigned> NumThreads( |
| 485 | "num-threads", cl::init(0), |
| 486 | cl::desc("Number of merge threads to use (default: autodetect)")); |
| 487 | cl::alias NumThreadsA("j", cl::desc("Alias for --num-threads"), |
| 488 | cl::aliasopt(NumThreads)); |
Vedant Kumar | 00dab22 | 2016-01-29 22:54:45 +0000 | [diff] [blame] | 489 | |
Diego Novillo | d5336ae | 2014-11-01 00:56:55 +0000 | [diff] [blame] | 490 | cl::ParseCommandLineOptions(argc, argv, "LLVM profile data merger\n"); |
| 491 | |
Vedant Kumar | cef4360 | 2016-06-07 22:47:31 +0000 | [diff] [blame] | 492 | WeightedFileVector WeightedInputs; |
| 493 | for (StringRef Filename : InputFilenames) |
Xinliang David Li | 9a1bfcf | 2016-07-20 22:24:52 +0000 | [diff] [blame] | 494 | addWeightedInput(WeightedInputs, {Filename, 1}); |
Vedant Kumar | cef4360 | 2016-06-07 22:47:31 +0000 | [diff] [blame] | 495 | for (StringRef WeightedFilename : WeightedInputFilenames) |
Xinliang David Li | 9a1bfcf | 2016-07-20 22:24:52 +0000 | [diff] [blame] | 496 | addWeightedInput(WeightedInputs, parseWeightedFile(WeightedFilename)); |
Vedant Kumar | cef4360 | 2016-06-07 22:47:31 +0000 | [diff] [blame] | 497 | |
| 498 | // Make sure that the file buffer stays alive for the duration of the |
| 499 | // weighted input vector's lifetime. |
| 500 | auto Buffer = getInputFilenamesFileBuf(InputFilenamesFile); |
| 501 | parseInputFilenamesFile(Buffer.get(), WeightedInputs); |
| 502 | |
| 503 | if (WeightedInputs.empty()) |
Chandler Carruth | 0c30f89 | 2016-06-04 03:08:01 +0000 | [diff] [blame] | 504 | exitWithError("No input files specified. See " + |
| 505 | sys::path::filename(argv[0]) + " -help"); |
| 506 | |
Vedant Kumar | cef4360 | 2016-06-07 22:47:31 +0000 | [diff] [blame] | 507 | if (DumpInputFileList) { |
| 508 | for (auto &WF : WeightedInputs) |
| 509 | outs() << WF.Weight << "," << WF.Filename << "\n"; |
| 510 | return 0; |
| 511 | } |
Vedant Kumar | f771a05 | 2016-06-04 00:36:28 +0000 | [diff] [blame] | 512 | |
Diego Novillo | d5336ae | 2014-11-01 00:56:55 +0000 | [diff] [blame] | 513 | if (ProfileKind == instr) |
Vedant Kumar | 00dab22 | 2016-01-29 22:54:45 +0000 | [diff] [blame] | 514 | mergeInstrProfile(WeightedInputs, OutputFilename, OutputFormat, |
Vedant Kumar | e3a0bf5 | 2016-07-19 01:17:20 +0000 | [diff] [blame] | 515 | OutputSparse, NumThreads); |
Diego Novillo | d5336ae | 2014-11-01 00:56:55 +0000 | [diff] [blame] | 516 | else |
Nathan Slingerland | 7f5b47d | 2015-12-15 17:37:09 +0000 | [diff] [blame] | 517 | mergeSampleProfile(WeightedInputs, OutputFilename, OutputFormat); |
Justin Bogner | bfee8d4 | 2014-03-12 20:14:17 +0000 | [diff] [blame] | 518 | |
Justin Bogner | ec49f98 | 2014-03-12 22:00:57 +0000 | [diff] [blame] | 519 | return 0; |
Justin Bogner | bfee8d4 | 2014-03-12 20:14:17 +0000 | [diff] [blame] | 520 | } |
Justin Bogner | 618bcea | 2014-03-19 02:20:46 +0000 | [diff] [blame] | 521 | |
Rong Xu | 0cf1f56 | 2017-03-09 19:03:57 +0000 | [diff] [blame] | 522 | typedef struct ValueSitesStats { |
| 523 | ValueSitesStats() |
| 524 | : TotalNumValueSites(0), TotalNumValueSitesWithValueProfile(0), |
| 525 | TotalNumValues(0) {} |
| 526 | uint64_t TotalNumValueSites; |
| 527 | uint64_t TotalNumValueSitesWithValueProfile; |
| 528 | uint64_t TotalNumValues; |
| 529 | std::vector<unsigned> ValueSitesHistogram; |
| 530 | } ValueSitesStats; |
| 531 | |
| 532 | static void traverseAllValueSites(const InstrProfRecord &Func, uint32_t VK, |
| 533 | ValueSitesStats &Stats, raw_fd_ostream &OS, |
Rong Xu | 60faea1 | 2017-03-16 21:15:48 +0000 | [diff] [blame] | 534 | InstrProfSymtab *Symtab) { |
Rong Xu | 0cf1f56 | 2017-03-09 19:03:57 +0000 | [diff] [blame] | 535 | uint32_t NS = Func.getNumValueSites(VK); |
| 536 | Stats.TotalNumValueSites += NS; |
| 537 | for (size_t I = 0; I < NS; ++I) { |
| 538 | uint32_t NV = Func.getNumValueDataForSite(VK, I); |
| 539 | std::unique_ptr<InstrProfValueData[]> VD = Func.getValueForSite(VK, I); |
| 540 | Stats.TotalNumValues += NV; |
| 541 | if (NV) { |
| 542 | Stats.TotalNumValueSitesWithValueProfile++; |
| 543 | if (NV > Stats.ValueSitesHistogram.size()) |
| 544 | Stats.ValueSitesHistogram.resize(NV, 0); |
| 545 | Stats.ValueSitesHistogram[NV - 1]++; |
| 546 | } |
| 547 | for (uint32_t V = 0; V < NV; V++) { |
| 548 | OS << "\t[ " << I << ", "; |
Rong Xu | 60faea1 | 2017-03-16 21:15:48 +0000 | [diff] [blame] | 549 | if (Symtab == nullptr) |
| 550 | OS << VD[V].Value; |
| 551 | else |
| 552 | OS << Symtab->getFuncName(VD[V].Value); |
| 553 | OS << ", " << VD[V].Count << " ]\n"; |
Rong Xu | 0cf1f56 | 2017-03-09 19:03:57 +0000 | [diff] [blame] | 554 | } |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | static void showValueSitesStats(raw_fd_ostream &OS, uint32_t VK, |
| 559 | ValueSitesStats &Stats) { |
| 560 | OS << " Total number of sites: " << Stats.TotalNumValueSites << "\n"; |
| 561 | OS << " Total number of sites with values: " |
| 562 | << Stats.TotalNumValueSitesWithValueProfile << "\n"; |
| 563 | OS << " Total number of profiled values: " << Stats.TotalNumValues << "\n"; |
| 564 | |
| 565 | OS << " Value sites histogram:\n\tNumTargets, SiteCount\n"; |
| 566 | for (unsigned I = 0; I < Stats.ValueSitesHistogram.size(); I++) { |
| 567 | if (Stats.ValueSitesHistogram[I] > 0) |
| 568 | OS << "\t" << I + 1 << ", " << Stats.ValueSitesHistogram[I] << "\n"; |
| 569 | } |
| 570 | } |
| 571 | |
Benjamin Kramer | 1afc1de | 2016-06-17 20:41:14 +0000 | [diff] [blame] | 572 | static int showInstrProfile(const std::string &Filename, bool ShowCounts, |
Xinliang David Li | 801b531 | 2017-07-11 20:30:43 +0000 | [diff] [blame] | 573 | uint32_t TopN, bool ShowIndirectCallTargets, |
| 574 | bool ShowMemOPSizes, bool ShowDetailedSummary, |
Easwaran Raman | 183ebbe | 2016-01-13 21:44:36 +0000 | [diff] [blame] | 575 | std::vector<uint32_t> DetailedSummaryCutoffs, |
Benjamin Kramer | 1afc1de | 2016-06-17 20:41:14 +0000 | [diff] [blame] | 576 | bool ShowAllFunctions, |
| 577 | const std::string &ShowFunction, bool TextFormat, |
| 578 | raw_fd_ostream &OS) { |
Diego Novillo | fcd5560 | 2014-11-03 00:51:45 +0000 | [diff] [blame] | 579 | auto ReaderOrErr = InstrProfReader::create(Filename); |
Benjamin Kramer | 1afc1de | 2016-06-17 20:41:14 +0000 | [diff] [blame] | 580 | std::vector<uint32_t> Cutoffs = std::move(DetailedSummaryCutoffs); |
| 581 | if (ShowDetailedSummary && Cutoffs.empty()) { |
Easwaran Raman | 183ebbe | 2016-01-13 21:44:36 +0000 | [diff] [blame] | 582 | Cutoffs = {800000, 900000, 950000, 990000, 999000, 999900, 999990}; |
| 583 | } |
Benjamin Kramer | 1afc1de | 2016-06-17 20:41:14 +0000 | [diff] [blame] | 584 | InstrProfSummaryBuilder Builder(std::move(Cutoffs)); |
Vedant Kumar | 9152fd1 | 2016-05-19 03:54:45 +0000 | [diff] [blame] | 585 | if (Error E = ReaderOrErr.takeError()) |
| 586 | exitWithError(std::move(E), Filename); |
Justin Bogner | 9af28ef | 2014-03-21 17:29:44 +0000 | [diff] [blame] | 587 | |
Diego Novillo | fcd5560 | 2014-11-03 00:51:45 +0000 | [diff] [blame] | 588 | auto Reader = std::move(ReaderOrErr.get()); |
Rong Xu | 33c76c0 | 2016-02-10 17:18:30 +0000 | [diff] [blame] | 589 | bool IsIRInstr = Reader->isIRLevelProfile(); |
Easwaran Raman | 183ebbe | 2016-01-13 21:44:36 +0000 | [diff] [blame] | 590 | size_t ShownFunctions = 0; |
Rong Xu | 0cf1f56 | 2017-03-09 19:03:57 +0000 | [diff] [blame] | 591 | int NumVPKind = IPVK_Last - IPVK_First + 1; |
| 592 | std::vector<ValueSitesStats> VPStats(NumVPKind); |
Xinliang David Li | 801b531 | 2017-07-11 20:30:43 +0000 | [diff] [blame] | 593 | |
| 594 | auto MinCmp = [](const std::pair<std::string, uint64_t> &v1, |
| 595 | const std::pair<std::string, uint64_t> &v2) { |
| 596 | return v1.second > v2.second; |
| 597 | }; |
| 598 | |
| 599 | std::priority_queue<std::pair<std::string, uint64_t>, |
| 600 | std::vector<std::pair<std::string, uint64_t>>, |
| 601 | decltype(MinCmp)> |
| 602 | HottestFuncs(MinCmp); |
| 603 | |
Justin Bogner | 9af28ef | 2014-03-21 17:29:44 +0000 | [diff] [blame] | 604 | for (const auto &Func : *Reader) { |
Diego Novillo | d5336ae | 2014-11-01 00:56:55 +0000 | [diff] [blame] | 605 | bool Show = |
| 606 | ShowAllFunctions || (!ShowFunction.empty() && |
| 607 | Func.Name.find(ShowFunction) != Func.Name.npos); |
Justin Bogner | 9af28ef | 2014-03-21 17:29:44 +0000 | [diff] [blame] | 608 | |
Xinliang David Li | 6f7c19a | 2015-11-23 20:47:38 +0000 | [diff] [blame] | 609 | bool doTextFormatDump = (Show && ShowCounts && TextFormat); |
| 610 | |
| 611 | if (doTextFormatDump) { |
Xinliang David Li | a716cc5 | 2015-12-20 06:22:13 +0000 | [diff] [blame] | 612 | InstrProfSymtab &Symtab = Reader->getSymtab(); |
David Blaikie | cf9d52c | 2017-07-06 19:00:12 +0000 | [diff] [blame] | 613 | InstrProfWriter::writeRecordInText(Func.Name, Func.Hash, Func, Symtab, |
| 614 | OS); |
Xinliang David Li | 6f7c19a | 2015-11-23 20:47:38 +0000 | [diff] [blame] | 615 | continue; |
| 616 | } |
| 617 | |
Justin Bogner | b59d7c7 | 2014-04-25 02:45:33 +0000 | [diff] [blame] | 618 | assert(Func.Counts.size() > 0 && "function missing entry counter"); |
Easwaran Raman | e5a17e3 | 2016-05-19 21:07:12 +0000 | [diff] [blame] | 619 | Builder.addRecord(Func); |
Xinliang David Li | 6f7c19a | 2015-11-23 20:47:38 +0000 | [diff] [blame] | 620 | |
Xinliang David Li | 801b531 | 2017-07-11 20:30:43 +0000 | [diff] [blame] | 621 | if (TopN) { |
| 622 | uint64_t FuncMax = 0; |
| 623 | for (size_t I = 0, E = Func.Counts.size(); I < E; ++I) |
| 624 | FuncMax = std::max(FuncMax, Func.Counts[I]); |
| 625 | |
| 626 | if (HottestFuncs.size() == TopN) { |
| 627 | if (HottestFuncs.top().second < FuncMax) { |
| 628 | HottestFuncs.pop(); |
| 629 | HottestFuncs.emplace(std::make_pair(std::string(Func.Name), FuncMax)); |
| 630 | } |
| 631 | } else |
| 632 | HottestFuncs.emplace(std::make_pair(std::string(Func.Name), FuncMax)); |
| 633 | } |
| 634 | |
Justin Bogner | 9af28ef | 2014-03-21 17:29:44 +0000 | [diff] [blame] | 635 | if (Show) { |
Xinliang David Li | 6f7c19a | 2015-11-23 20:47:38 +0000 | [diff] [blame] | 636 | |
Justin Bogner | 9af28ef | 2014-03-21 17:29:44 +0000 | [diff] [blame] | 637 | if (!ShownFunctions) |
| 638 | OS << "Counters:\n"; |
Xinliang David Li | 6f7c19a | 2015-11-23 20:47:38 +0000 | [diff] [blame] | 639 | |
Justin Bogner | 9af28ef | 2014-03-21 17:29:44 +0000 | [diff] [blame] | 640 | ++ShownFunctions; |
| 641 | |
| 642 | OS << " " << Func.Name << ":\n" |
Justin Bogner | 423380f | 2014-03-23 20:43:50 +0000 | [diff] [blame] | 643 | << " Hash: " << format("0x%016" PRIx64, Func.Hash) << "\n" |
Rong Xu | 33c76c0 | 2016-02-10 17:18:30 +0000 | [diff] [blame] | 644 | << " Counters: " << Func.Counts.size() << "\n"; |
| 645 | if (!IsIRInstr) |
| 646 | OS << " Function count: " << Func.Counts[0] << "\n"; |
Xinliang David Li | 6f7c19a | 2015-11-23 20:47:38 +0000 | [diff] [blame] | 647 | |
Justin Bogner | 9e9a057 | 2015-09-29 22:13:58 +0000 | [diff] [blame] | 648 | if (ShowIndirectCallTargets) |
Xinliang David Li | 2004f00 | 2015-11-02 05:08:23 +0000 | [diff] [blame] | 649 | OS << " Indirect Call Site Count: " |
| 650 | << Func.getNumValueSites(IPVK_IndirectCallTarget) << "\n"; |
Justin Bogner | 9af28ef | 2014-03-21 17:29:44 +0000 | [diff] [blame] | 651 | |
Rong Xu | 60faea1 | 2017-03-16 21:15:48 +0000 | [diff] [blame] | 652 | uint32_t NumMemOPCalls = Func.getNumValueSites(IPVK_MemOPSize); |
| 653 | if (ShowMemOPSizes && NumMemOPCalls > 0) |
| 654 | OS << " Number of Memory Intrinsics Calls: " << NumMemOPCalls |
| 655 | << "\n"; |
| 656 | |
Xinliang David Li | 6f7c19a | 2015-11-23 20:47:38 +0000 | [diff] [blame] | 657 | if (ShowCounts) { |
| 658 | OS << " Block counts: ["; |
Rong Xu | 33c76c0 | 2016-02-10 17:18:30 +0000 | [diff] [blame] | 659 | size_t Start = (IsIRInstr ? 0 : 1); |
| 660 | for (size_t I = Start, E = Func.Counts.size(); I < E; ++I) { |
| 661 | OS << (I == Start ? "" : ", ") << Func.Counts[I]; |
Xinliang David Li | 6f7c19a | 2015-11-23 20:47:38 +0000 | [diff] [blame] | 662 | } |
| 663 | OS << "]\n"; |
| 664 | } |
Justin Bogner | 9e9a057 | 2015-09-29 22:13:58 +0000 | [diff] [blame] | 665 | |
Xinliang David Li | 6f7c19a | 2015-11-23 20:47:38 +0000 | [diff] [blame] | 666 | if (ShowIndirectCallTargets) { |
Rong Xu | 0cf1f56 | 2017-03-09 19:03:57 +0000 | [diff] [blame] | 667 | OS << " Indirect Target Results:\n"; |
| 668 | traverseAllValueSites(Func, IPVK_IndirectCallTarget, |
| 669 | VPStats[IPVK_IndirectCallTarget], OS, |
Rong Xu | 60faea1 | 2017-03-16 21:15:48 +0000 | [diff] [blame] | 670 | &(Reader->getSymtab())); |
| 671 | } |
| 672 | |
| 673 | if (ShowMemOPSizes && NumMemOPCalls > 0) { |
Teresa Johnson | cd2aa0d | 2017-05-24 17:55:25 +0000 | [diff] [blame] | 674 | OS << " Memory Intrinsic Size Results:\n"; |
Rong Xu | 60faea1 | 2017-03-16 21:15:48 +0000 | [diff] [blame] | 675 | traverseAllValueSites(Func, IPVK_MemOPSize, VPStats[IPVK_MemOPSize], OS, |
| 676 | nullptr); |
Justin Bogner | 9e9a057 | 2015-09-29 22:13:58 +0000 | [diff] [blame] | 677 | } |
| 678 | } |
Justin Bogner | 9af28ef | 2014-03-21 17:29:44 +0000 | [diff] [blame] | 679 | } |
Justin Bogner | db1225d | 2014-03-23 20:55:53 +0000 | [diff] [blame] | 680 | if (Reader->hasError()) |
Vedant Kumar | 9152fd1 | 2016-05-19 03:54:45 +0000 | [diff] [blame] | 681 | exitWithError(Reader->getError(), Filename); |
Justin Bogner | 9af28ef | 2014-03-21 17:29:44 +0000 | [diff] [blame] | 682 | |
Xinliang David Li | 6f7c19a | 2015-11-23 20:47:38 +0000 | [diff] [blame] | 683 | if (ShowCounts && TextFormat) |
| 684 | return 0; |
Easwaran Raman | 7cefdb8 | 2016-05-19 21:53:28 +0000 | [diff] [blame] | 685 | std::unique_ptr<ProfileSummary> PS(Builder.getSummary()); |
Adam Nemet | 1142b2d | 2017-11-14 16:59:18 +0000 | [diff] [blame] | 686 | OS << "Instrumentation level: " |
| 687 | << (Reader->isIRLevelProfile() ? "IR" : "Front-end") << "\n"; |
Justin Bogner | 9af28ef | 2014-03-21 17:29:44 +0000 | [diff] [blame] | 688 | if (ShowAllFunctions || !ShowFunction.empty()) |
| 689 | OS << "Functions shown: " << ShownFunctions << "\n"; |
Easwaran Raman | e5a17e3 | 2016-05-19 21:07:12 +0000 | [diff] [blame] | 690 | OS << "Total functions: " << PS->getNumFunctions() << "\n"; |
| 691 | OS << "Maximum function count: " << PS->getMaxFunctionCount() << "\n"; |
Easwaran Raman | 7cefdb8 | 2016-05-19 21:53:28 +0000 | [diff] [blame] | 692 | OS << "Maximum internal block count: " << PS->getMaxInternalCount() << "\n"; |
Rong Xu | 60faea1 | 2017-03-16 21:15:48 +0000 | [diff] [blame] | 693 | |
Xinliang David Li | 801b531 | 2017-07-11 20:30:43 +0000 | [diff] [blame] | 694 | if (TopN) { |
| 695 | std::vector<std::pair<std::string, uint64_t>> SortedHottestFuncs; |
| 696 | while (!HottestFuncs.empty()) { |
| 697 | SortedHottestFuncs.emplace_back(HottestFuncs.top()); |
| 698 | HottestFuncs.pop(); |
| 699 | } |
| 700 | OS << "Top " << TopN |
| 701 | << " functions with the largest internal block counts: \n"; |
| 702 | for (auto &hotfunc : llvm::reverse(SortedHottestFuncs)) |
| 703 | OS << " " << hotfunc.first << ", max count = " << hotfunc.second << "\n"; |
| 704 | } |
| 705 | |
Xinliang David Li | 872362c | 2016-05-23 16:36:11 +0000 | [diff] [blame] | 706 | if (ShownFunctions && ShowIndirectCallTargets) { |
Rong Xu | 0cf1f56 | 2017-03-09 19:03:57 +0000 | [diff] [blame] | 707 | OS << "Statistics for indirect call sites profile:\n"; |
| 708 | showValueSitesStats(OS, IPVK_IndirectCallTarget, |
| 709 | VPStats[IPVK_IndirectCallTarget]); |
Xinliang David Li | 872362c | 2016-05-23 16:36:11 +0000 | [diff] [blame] | 710 | } |
Easwaran Raman | 183ebbe | 2016-01-13 21:44:36 +0000 | [diff] [blame] | 711 | |
Rong Xu | 60faea1 | 2017-03-16 21:15:48 +0000 | [diff] [blame] | 712 | if (ShownFunctions && ShowMemOPSizes) { |
| 713 | OS << "Statistics for memory intrinsic calls sizes profile:\n"; |
| 714 | showValueSitesStats(OS, IPVK_MemOPSize, VPStats[IPVK_MemOPSize]); |
| 715 | } |
| 716 | |
Easwaran Raman | 183ebbe | 2016-01-13 21:44:36 +0000 | [diff] [blame] | 717 | if (ShowDetailedSummary) { |
| 718 | OS << "Detailed summary:\n"; |
Easwaran Raman | 7cefdb8 | 2016-05-19 21:53:28 +0000 | [diff] [blame] | 719 | OS << "Total number of blocks: " << PS->getNumCounts() << "\n"; |
Easwaran Raman | e5a17e3 | 2016-05-19 21:07:12 +0000 | [diff] [blame] | 720 | OS << "Total count: " << PS->getTotalCount() << "\n"; |
| 721 | for (auto Entry : PS->getDetailedSummary()) { |
Easwaran Raman | 4309570 | 2016-02-17 18:18:47 +0000 | [diff] [blame] | 722 | OS << Entry.NumCounts << " blocks with count >= " << Entry.MinCount |
Easwaran Raman | 183ebbe | 2016-01-13 21:44:36 +0000 | [diff] [blame] | 723 | << " account for " |
| 724 | << format("%0.6g", (float)Entry.Cutoff / ProfileSummary::Scale * 100) |
| 725 | << " percentage of the total counts.\n"; |
| 726 | } |
| 727 | } |
Justin Bogner | 9af28ef | 2014-03-21 17:29:44 +0000 | [diff] [blame] | 728 | return 0; |
| 729 | } |
| 730 | |
Benjamin Kramer | 1afc1de | 2016-06-17 20:41:14 +0000 | [diff] [blame] | 731 | static int showSampleProfile(const std::string &Filename, bool ShowCounts, |
| 732 | bool ShowAllFunctions, |
| 733 | const std::string &ShowFunction, |
Benjamin Kramer | f044d3f | 2015-03-09 16:23:46 +0000 | [diff] [blame] | 734 | raw_fd_ostream &OS) { |
Diego Novillo | d5336ae | 2014-11-01 00:56:55 +0000 | [diff] [blame] | 735 | using namespace sampleprof; |
Mehdi Amini | 03b42e4 | 2016-04-14 21:59:01 +0000 | [diff] [blame] | 736 | LLVMContext Context; |
| 737 | auto ReaderOrErr = SampleProfileReader::create(Filename, Context); |
Diego Novillo | fcd5560 | 2014-11-03 00:51:45 +0000 | [diff] [blame] | 738 | if (std::error_code EC = ReaderOrErr.getError()) |
Nathan Slingerland | 4f82366 | 2015-11-13 03:47:58 +0000 | [diff] [blame] | 739 | exitWithErrorCode(EC, Filename); |
Diego Novillo | d5336ae | 2014-11-01 00:56:55 +0000 | [diff] [blame] | 740 | |
Diego Novillo | fcd5560 | 2014-11-03 00:51:45 +0000 | [diff] [blame] | 741 | auto Reader = std::move(ReaderOrErr.get()); |
Diego Novillo | c6d032a | 2015-09-17 00:17:21 +0000 | [diff] [blame] | 742 | if (std::error_code EC = Reader->read()) |
Nathan Slingerland | 4f82366 | 2015-11-13 03:47:58 +0000 | [diff] [blame] | 743 | exitWithErrorCode(EC, Filename); |
Diego Novillo | c6d032a | 2015-09-17 00:17:21 +0000 | [diff] [blame] | 744 | |
Diego Novillo | d5336ae | 2014-11-01 00:56:55 +0000 | [diff] [blame] | 745 | if (ShowAllFunctions || ShowFunction.empty()) |
| 746 | Reader->dump(OS); |
| 747 | else |
| 748 | Reader->dumpFunctionProfile(ShowFunction, OS); |
| 749 | |
| 750 | return 0; |
| 751 | } |
| 752 | |
Benjamin Kramer | f044d3f | 2015-03-09 16:23:46 +0000 | [diff] [blame] | 753 | static int show_main(int argc, const char *argv[]) { |
Diego Novillo | d5336ae | 2014-11-01 00:56:55 +0000 | [diff] [blame] | 754 | cl::opt<std::string> Filename(cl::Positional, cl::Required, |
| 755 | cl::desc("<profdata-file>")); |
| 756 | |
| 757 | cl::opt<bool> ShowCounts("counts", cl::init(false), |
| 758 | cl::desc("Show counter values for shown functions")); |
Xinliang David Li | 6f7c19a | 2015-11-23 20:47:38 +0000 | [diff] [blame] | 759 | cl::opt<bool> TextFormat( |
| 760 | "text", cl::init(false), |
| 761 | cl::desc("Show instr profile data in text dump format")); |
Justin Bogner | 9e9a057 | 2015-09-29 22:13:58 +0000 | [diff] [blame] | 762 | cl::opt<bool> ShowIndirectCallTargets( |
| 763 | "ic-targets", cl::init(false), |
| 764 | cl::desc("Show indirect call site target values for shown functions")); |
Rong Xu | 60faea1 | 2017-03-16 21:15:48 +0000 | [diff] [blame] | 765 | cl::opt<bool> ShowMemOPSizes( |
| 766 | "memop-sizes", cl::init(false), |
| 767 | cl::desc("Show the profiled sizes of the memory intrinsic calls " |
| 768 | "for shown functions")); |
Easwaran Raman | 183ebbe | 2016-01-13 21:44:36 +0000 | [diff] [blame] | 769 | cl::opt<bool> ShowDetailedSummary("detailed-summary", cl::init(false), |
| 770 | cl::desc("Show detailed profile summary")); |
| 771 | cl::list<uint32_t> DetailedSummaryCutoffs( |
| 772 | cl::CommaSeparated, "detailed-summary-cutoffs", |
| 773 | cl::desc( |
| 774 | "Cutoff percentages (times 10000) for generating detailed summary"), |
| 775 | cl::value_desc("800000,901000,999999")); |
Diego Novillo | d5336ae | 2014-11-01 00:56:55 +0000 | [diff] [blame] | 776 | cl::opt<bool> ShowAllFunctions("all-functions", cl::init(false), |
| 777 | cl::desc("Details for every function")); |
| 778 | cl::opt<std::string> ShowFunction("function", |
| 779 | cl::desc("Details for matching functions")); |
| 780 | |
| 781 | cl::opt<std::string> OutputFilename("output", cl::value_desc("output"), |
| 782 | cl::init("-"), cl::desc("Output file")); |
| 783 | cl::alias OutputFilenameA("o", cl::desc("Alias for --output"), |
| 784 | cl::aliasopt(OutputFilename)); |
| 785 | cl::opt<ProfileKinds> ProfileKind( |
| 786 | cl::desc("Profile kind:"), cl::init(instr), |
| 787 | cl::values(clEnumVal(instr, "Instrumentation profile (default)"), |
Mehdi Amini | 732afdd | 2016-10-08 19:41:06 +0000 | [diff] [blame] | 788 | clEnumVal(sample, "Sample profile"))); |
Xinliang David Li | 801b531 | 2017-07-11 20:30:43 +0000 | [diff] [blame] | 789 | cl::opt<uint32_t> TopNFunctions( |
| 790 | "topn", cl::init(0), |
| 791 | cl::desc("Show the list of functions with the largest internal counts")); |
Diego Novillo | d5336ae | 2014-11-01 00:56:55 +0000 | [diff] [blame] | 792 | |
| 793 | cl::ParseCommandLineOptions(argc, argv, "LLVM profile data summary\n"); |
| 794 | |
| 795 | if (OutputFilename.empty()) |
| 796 | OutputFilename = "-"; |
| 797 | |
| 798 | std::error_code EC; |
| 799 | raw_fd_ostream OS(OutputFilename.data(), EC, sys::fs::F_Text); |
| 800 | if (EC) |
Xinliang David Li | 6f7c19a | 2015-11-23 20:47:38 +0000 | [diff] [blame] | 801 | exitWithErrorCode(EC, OutputFilename); |
Diego Novillo | d5336ae | 2014-11-01 00:56:55 +0000 | [diff] [blame] | 802 | |
| 803 | if (ShowAllFunctions && !ShowFunction.empty()) |
Jonas Devlieghere | e46b756 | 2018-04-18 14:42:33 +0000 | [diff] [blame] | 804 | WithColor::warning() << "-function argument ignored: showing all functions\n"; |
Diego Novillo | d5336ae | 2014-11-01 00:56:55 +0000 | [diff] [blame] | 805 | |
Easwaran Raman | 183ebbe | 2016-01-13 21:44:36 +0000 | [diff] [blame] | 806 | std::vector<uint32_t> Cutoffs(DetailedSummaryCutoffs.begin(), |
| 807 | DetailedSummaryCutoffs.end()); |
Diego Novillo | d5336ae | 2014-11-01 00:56:55 +0000 | [diff] [blame] | 808 | if (ProfileKind == instr) |
Xinliang David Li | 801b531 | 2017-07-11 20:30:43 +0000 | [diff] [blame] | 809 | return showInstrProfile(Filename, ShowCounts, TopNFunctions, |
| 810 | ShowIndirectCallTargets, ShowMemOPSizes, |
| 811 | ShowDetailedSummary, DetailedSummaryCutoffs, |
| 812 | ShowAllFunctions, ShowFunction, TextFormat, OS); |
Diego Novillo | d5336ae | 2014-11-01 00:56:55 +0000 | [diff] [blame] | 813 | else |
| 814 | return showSampleProfile(Filename, ShowCounts, ShowAllFunctions, |
| 815 | ShowFunction, OS); |
| 816 | } |
| 817 | |
Justin Bogner | 618bcea | 2014-03-19 02:20:46 +0000 | [diff] [blame] | 818 | int main(int argc, const char *argv[]) { |
Rui Ueyama | 197194b | 2018-04-13 18:26:06 +0000 | [diff] [blame] | 819 | InitLLVM X(argc, argv); |
Justin Bogner | 618bcea | 2014-03-19 02:20:46 +0000 | [diff] [blame] | 820 | |
| 821 | StringRef ProgName(sys::path::filename(argv[0])); |
| 822 | if (argc > 1) { |
Craig Topper | e6cb63e | 2014-04-25 04:24:47 +0000 | [diff] [blame] | 823 | int (*func)(int, const char *[]) = nullptr; |
Justin Bogner | 618bcea | 2014-03-19 02:20:46 +0000 | [diff] [blame] | 824 | |
| 825 | if (strcmp(argv[1], "merge") == 0) |
| 826 | func = merge_main; |
Justin Bogner | 9af28ef | 2014-03-21 17:29:44 +0000 | [diff] [blame] | 827 | else if (strcmp(argv[1], "show") == 0) |
| 828 | func = show_main; |
Justin Bogner | 618bcea | 2014-03-19 02:20:46 +0000 | [diff] [blame] | 829 | |
| 830 | if (func) { |
| 831 | std::string Invocation(ProgName.str() + " " + argv[1]); |
| 832 | argv[1] = Invocation.c_str(); |
| 833 | return func(argc - 1, argv + 1); |
| 834 | } |
| 835 | |
Diego Novillo | d3babdb | 2015-12-14 20:37:15 +0000 | [diff] [blame] | 836 | if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "-help") == 0 || |
Justin Bogner | 618bcea | 2014-03-19 02:20:46 +0000 | [diff] [blame] | 837 | strcmp(argv[1], "--help") == 0) { |
| 838 | |
| 839 | errs() << "OVERVIEW: LLVM profile data tools\n\n" |
| 840 | << "USAGE: " << ProgName << " <command> [args...]\n" |
| 841 | << "USAGE: " << ProgName << " <command> -help\n\n" |
Justin Bogner | 253eb17 | 2016-08-03 23:10:51 +0000 | [diff] [blame] | 842 | << "See each individual command --help for more details.\n" |
Justin Bogner | 9af28ef | 2014-03-21 17:29:44 +0000 | [diff] [blame] | 843 | << "Available commands: merge, show\n"; |
Justin Bogner | 618bcea | 2014-03-19 02:20:46 +0000 | [diff] [blame] | 844 | return 0; |
| 845 | } |
| 846 | } |
| 847 | |
| 848 | if (argc < 2) |
| 849 | errs() << ProgName << ": No command specified!\n"; |
| 850 | else |
| 851 | errs() << ProgName << ": Unknown command!\n"; |
| 852 | |
Justin Bogner | 9af28ef | 2014-03-21 17:29:44 +0000 | [diff] [blame] | 853 | errs() << "USAGE: " << ProgName << " <merge|show> [args...]\n"; |
Justin Bogner | 618bcea | 2014-03-19 02:20:46 +0000 | [diff] [blame] | 854 | return 1; |
| 855 | } |