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 | |
Duncan P. N. Exon Smith | 846a627 | 2014-02-17 23:22:49 +0000 | [diff] [blame] | 14 | #include "llvm/ADT/StringRef.h" |
Chandler Carruth | d990388 | 2015-01-14 11:23:27 +0000 | [diff] [blame] | 15 | #include "llvm/IR/LLVMContext.h" |
Justin Bogner | f8d7919 | 2014-03-21 17:24:48 +0000 | [diff] [blame] | 16 | #include "llvm/ProfileData/InstrProfReader.h" |
Justin Bogner | b9bd7f8 | 2014-03-21 17:46:22 +0000 | [diff] [blame] | 17 | #include "llvm/ProfileData/InstrProfWriter.h" |
Diego Novillo | d5336ae | 2014-11-01 00:56:55 +0000 | [diff] [blame] | 18 | #include "llvm/ProfileData/SampleProfReader.h" |
| 19 | #include "llvm/ProfileData/SampleProfWriter.h" |
Duncan P. N. Exon Smith | 846a627 | 2014-02-17 23:22:49 +0000 | [diff] [blame] | 20 | #include "llvm/Support/CommandLine.h" |
Benjamin Kramer | d59664f | 2014-04-29 23:26:49 +0000 | [diff] [blame] | 21 | #include "llvm/Support/FileSystem.h" |
Justin Bogner | 423380f | 2014-03-23 20:43:50 +0000 | [diff] [blame] | 22 | #include "llvm/Support/Format.h" |
Duncan P. N. Exon Smith | 846a627 | 2014-02-17 23:22:49 +0000 | [diff] [blame] | 23 | #include "llvm/Support/ManagedStatic.h" |
| 24 | #include "llvm/Support/MemoryBuffer.h" |
Benjamin Kramer | 16132e6 | 2015-03-23 18:07:13 +0000 | [diff] [blame] | 25 | #include "llvm/Support/Path.h" |
Duncan P. N. Exon Smith | 846a627 | 2014-02-17 23:22:49 +0000 | [diff] [blame] | 26 | #include "llvm/Support/PrettyStackTrace.h" |
| 27 | #include "llvm/Support/Signals.h" |
| 28 | #include "llvm/Support/raw_ostream.h" |
| 29 | |
| 30 | using namespace llvm; |
| 31 | |
Justin Bogner | f8d7919 | 2014-03-21 17:24:48 +0000 | [diff] [blame] | 32 | static void exitWithError(const Twine &Message, StringRef Whence = "") { |
| 33 | errs() << "error: "; |
| 34 | if (!Whence.empty()) |
| 35 | errs() << Whence << ": "; |
| 36 | errs() << Message << "\n"; |
Duncan P. N. Exon Smith | 846a627 | 2014-02-17 23:22:49 +0000 | [diff] [blame] | 37 | ::exit(1); |
| 38 | } |
| 39 | |
Duncan P. N. Exon Smith | 02b6fa9 | 2015-06-16 00:43:04 +0000 | [diff] [blame] | 40 | namespace { |
Diego Novillo | d5336ae | 2014-11-01 00:56:55 +0000 | [diff] [blame] | 41 | enum ProfileKinds { instr, sample }; |
Duncan P. N. Exon Smith | 02b6fa9 | 2015-06-16 00:43:04 +0000 | [diff] [blame] | 42 | } |
Justin Bogner | 618bcea | 2014-03-19 02:20:46 +0000 | [diff] [blame] | 43 | |
Benjamin Kramer | f044d3f | 2015-03-09 16:23:46 +0000 | [diff] [blame] | 44 | static void mergeInstrProfile(const cl::list<std::string> &Inputs, |
| 45 | StringRef OutputFilename) { |
Justin Bogner | b7aa263 | 2014-04-18 21:48:40 +0000 | [diff] [blame] | 46 | if (OutputFilename.compare("-") == 0) |
| 47 | exitWithError("Cannot write indexed profdata format to stdout."); |
Justin Bogner | ec49f98 | 2014-03-12 22:00:57 +0000 | [diff] [blame] | 48 | |
Rafael Espindola | 3fd1e99 | 2014-08-25 18:16:47 +0000 | [diff] [blame] | 49 | std::error_code EC; |
| 50 | raw_fd_ostream Output(OutputFilename.data(), EC, sys::fs::F_None); |
| 51 | if (EC) |
| 52 | exitWithError(EC.message(), OutputFilename); |
Justin Bogner | ec49f98 | 2014-03-12 22:00:57 +0000 | [diff] [blame] | 53 | |
Justin Bogner | b9bd7f8 | 2014-03-21 17:46:22 +0000 | [diff] [blame] | 54 | InstrProfWriter Writer; |
| 55 | for (const auto &Filename : Inputs) { |
Diego Novillo | fcd5560 | 2014-11-03 00:51:45 +0000 | [diff] [blame] | 56 | auto ReaderOrErr = InstrProfReader::create(Filename); |
| 57 | if (std::error_code ec = ReaderOrErr.getError()) |
Justin Bogner | b9bd7f8 | 2014-03-21 17:46:22 +0000 | [diff] [blame] | 58 | exitWithError(ec.message(), Filename); |
Justin Bogner | f8d7919 | 2014-03-21 17:24:48 +0000 | [diff] [blame] | 59 | |
Diego Novillo | fcd5560 | 2014-11-03 00:51:45 +0000 | [diff] [blame] | 60 | auto Reader = std::move(ReaderOrErr.get()); |
Justin Bogner | 9e9a057 | 2015-09-29 22:13:58 +0000 | [diff] [blame] | 61 | for (auto &I : *Reader) |
| 62 | if (std::error_code EC = Writer.addRecord(std::move(I))) |
Justin Bogner | b9bd7f8 | 2014-03-21 17:46:22 +0000 | [diff] [blame] | 63 | errs() << Filename << ": " << I.Name << ": " << EC.message() << "\n"; |
| 64 | if (Reader->hasError()) |
| 65 | exitWithError(Reader->getError().message(), Filename); |
Justin Bogner | bfee8d4 | 2014-03-12 20:14:17 +0000 | [diff] [blame] | 66 | } |
Justin Bogner | b9bd7f8 | 2014-03-21 17:46:22 +0000 | [diff] [blame] | 67 | Writer.write(Output); |
Diego Novillo | d5336ae | 2014-11-01 00:56:55 +0000 | [diff] [blame] | 68 | } |
| 69 | |
Benjamin Kramer | f044d3f | 2015-03-09 16:23:46 +0000 | [diff] [blame] | 70 | static void mergeSampleProfile(const cl::list<std::string> &Inputs, |
| 71 | StringRef OutputFilename, |
| 72 | sampleprof::SampleProfileFormat OutputFormat) { |
Diego Novillo | d5336ae | 2014-11-01 00:56:55 +0000 | [diff] [blame] | 73 | using namespace sampleprof; |
Diego Novillo | fcd5560 | 2014-11-03 00:51:45 +0000 | [diff] [blame] | 74 | auto WriterOrErr = SampleProfileWriter::create(OutputFilename, OutputFormat); |
| 75 | if (std::error_code EC = WriterOrErr.getError()) |
Diego Novillo | d5336ae | 2014-11-01 00:56:55 +0000 | [diff] [blame] | 76 | exitWithError(EC.message(), OutputFilename); |
| 77 | |
Diego Novillo | fcd5560 | 2014-11-03 00:51:45 +0000 | [diff] [blame] | 78 | auto Writer = std::move(WriterOrErr.get()); |
Diego Novillo | d5336ae | 2014-11-01 00:56:55 +0000 | [diff] [blame] | 79 | StringMap<FunctionSamples> ProfileMap; |
Diego Novillo | aae1ed8 | 2015-10-08 19:40:37 +0000 | [diff] [blame] | 80 | SmallVector<std::unique_ptr<sampleprof::SampleProfileReader>, 5> Readers; |
Diego Novillo | d5336ae | 2014-11-01 00:56:55 +0000 | [diff] [blame] | 81 | for (const auto &Filename : Inputs) { |
Diego Novillo | fcd5560 | 2014-11-03 00:51:45 +0000 | [diff] [blame] | 82 | auto ReaderOrErr = |
| 83 | SampleProfileReader::create(Filename, getGlobalContext()); |
| 84 | if (std::error_code EC = ReaderOrErr.getError()) |
Diego Novillo | d5336ae | 2014-11-01 00:56:55 +0000 | [diff] [blame] | 85 | exitWithError(EC.message(), Filename); |
| 86 | |
Diego Novillo | aae1ed8 | 2015-10-08 19:40:37 +0000 | [diff] [blame] | 87 | // We need to keep the readers around until after all the files are |
| 88 | // read so that we do not lose the function names stored in each |
| 89 | // reader's memory. The function names are needed to write out the |
| 90 | // merged profile map. |
| 91 | Readers.push_back(std::move(ReaderOrErr.get())); |
| 92 | const auto Reader = Readers.back().get(); |
Diego Novillo | d5336ae | 2014-11-01 00:56:55 +0000 | [diff] [blame] | 93 | if (std::error_code EC = Reader->read()) |
| 94 | exitWithError(EC.message(), Filename); |
| 95 | |
| 96 | StringMap<FunctionSamples> &Profiles = Reader->getProfiles(); |
| 97 | for (StringMap<FunctionSamples>::iterator I = Profiles.begin(), |
| 98 | E = Profiles.end(); |
| 99 | I != E; ++I) { |
| 100 | StringRef FName = I->first(); |
| 101 | FunctionSamples &Samples = I->second; |
| 102 | ProfileMap[FName].merge(Samples); |
| 103 | } |
| 104 | } |
| 105 | Writer->write(ProfileMap); |
| 106 | } |
| 107 | |
Benjamin Kramer | f044d3f | 2015-03-09 16:23:46 +0000 | [diff] [blame] | 108 | static int merge_main(int argc, const char *argv[]) { |
Diego Novillo | d5336ae | 2014-11-01 00:56:55 +0000 | [diff] [blame] | 109 | cl::list<std::string> Inputs(cl::Positional, cl::Required, cl::OneOrMore, |
| 110 | cl::desc("<filenames...>")); |
| 111 | |
| 112 | cl::opt<std::string> OutputFilename("output", cl::value_desc("output"), |
| 113 | cl::init("-"), cl::Required, |
| 114 | cl::desc("Output file")); |
| 115 | cl::alias OutputFilenameA("o", cl::desc("Alias for --output"), |
| 116 | cl::aliasopt(OutputFilename)); |
| 117 | cl::opt<ProfileKinds> ProfileKind( |
| 118 | cl::desc("Profile kind:"), cl::init(instr), |
| 119 | cl::values(clEnumVal(instr, "Instrumentation profile (default)"), |
| 120 | clEnumVal(sample, "Sample profile"), clEnumValEnd)); |
| 121 | |
| 122 | cl::opt<sampleprof::SampleProfileFormat> OutputFormat( |
| 123 | cl::desc("Format of output profile (only meaningful with --sample)"), |
| 124 | cl::init(sampleprof::SPF_Binary), |
| 125 | cl::values(clEnumValN(sampleprof::SPF_Binary, "binary", |
| 126 | "Binary encoding (default)"), |
| 127 | clEnumValN(sampleprof::SPF_Text, "text", "Text encoding"), |
| 128 | clEnumValN(sampleprof::SPF_GCC, "gcc", "GCC encoding"), |
| 129 | clEnumValEnd)); |
| 130 | |
| 131 | cl::ParseCommandLineOptions(argc, argv, "LLVM profile data merger\n"); |
| 132 | |
| 133 | if (ProfileKind == instr) |
| 134 | mergeInstrProfile(Inputs, OutputFilename); |
| 135 | else |
| 136 | mergeSampleProfile(Inputs, OutputFilename, OutputFormat); |
Justin Bogner | bfee8d4 | 2014-03-12 20:14:17 +0000 | [diff] [blame] | 137 | |
Justin Bogner | ec49f98 | 2014-03-12 22:00:57 +0000 | [diff] [blame] | 138 | return 0; |
Justin Bogner | bfee8d4 | 2014-03-12 20:14:17 +0000 | [diff] [blame] | 139 | } |
Justin Bogner | 618bcea | 2014-03-19 02:20:46 +0000 | [diff] [blame] | 140 | |
Benjamin Kramer | f044d3f | 2015-03-09 16:23:46 +0000 | [diff] [blame] | 141 | static int showInstrProfile(std::string Filename, bool ShowCounts, |
Justin Bogner | 9e9a057 | 2015-09-29 22:13:58 +0000 | [diff] [blame] | 142 | bool ShowIndirectCallTargets, bool ShowAllFunctions, |
| 143 | std::string ShowFunction, raw_fd_ostream &OS) { |
Diego Novillo | fcd5560 | 2014-11-03 00:51:45 +0000 | [diff] [blame] | 144 | auto ReaderOrErr = InstrProfReader::create(Filename); |
| 145 | if (std::error_code EC = ReaderOrErr.getError()) |
Justin Bogner | 9af28ef | 2014-03-21 17:29:44 +0000 | [diff] [blame] | 146 | exitWithError(EC.message(), Filename); |
| 147 | |
Diego Novillo | fcd5560 | 2014-11-03 00:51:45 +0000 | [diff] [blame] | 148 | auto Reader = std::move(ReaderOrErr.get()); |
Justin Bogner | 9af28ef | 2014-03-21 17:29:44 +0000 | [diff] [blame] | 149 | uint64_t MaxFunctionCount = 0, MaxBlockCount = 0; |
| 150 | size_t ShownFunctions = 0, TotalFunctions = 0; |
| 151 | for (const auto &Func : *Reader) { |
Diego Novillo | d5336ae | 2014-11-01 00:56:55 +0000 | [diff] [blame] | 152 | bool Show = |
| 153 | ShowAllFunctions || (!ShowFunction.empty() && |
| 154 | Func.Name.find(ShowFunction) != Func.Name.npos); |
Justin Bogner | 9af28ef | 2014-03-21 17:29:44 +0000 | [diff] [blame] | 155 | |
| 156 | ++TotalFunctions; |
Justin Bogner | b59d7c7 | 2014-04-25 02:45:33 +0000 | [diff] [blame] | 157 | assert(Func.Counts.size() > 0 && "function missing entry counter"); |
Justin Bogner | 9af28ef | 2014-03-21 17:29:44 +0000 | [diff] [blame] | 158 | if (Func.Counts[0] > MaxFunctionCount) |
| 159 | MaxFunctionCount = Func.Counts[0]; |
| 160 | |
| 161 | if (Show) { |
| 162 | if (!ShownFunctions) |
| 163 | OS << "Counters:\n"; |
| 164 | ++ShownFunctions; |
| 165 | |
| 166 | OS << " " << Func.Name << ":\n" |
Justin Bogner | 423380f | 2014-03-23 20:43:50 +0000 | [diff] [blame] | 167 | << " Hash: " << format("0x%016" PRIx64, Func.Hash) << "\n" |
Justin Bogner | 9af28ef | 2014-03-21 17:29:44 +0000 | [diff] [blame] | 168 | << " Counters: " << Func.Counts.size() << "\n" |
| 169 | << " Function count: " << Func.Counts[0] << "\n"; |
Justin Bogner | 9e9a057 | 2015-09-29 22:13:58 +0000 | [diff] [blame] | 170 | if (ShowIndirectCallTargets) |
Xinliang David Li | 2004f00 | 2015-11-02 05:08:23 +0000 | [diff] [blame^] | 171 | OS << " Indirect Call Site Count: " |
| 172 | << Func.getNumValueSites(IPVK_IndirectCallTarget) << "\n"; |
Justin Bogner | 9af28ef | 2014-03-21 17:29:44 +0000 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | if (Show && ShowCounts) |
| 176 | OS << " Block counts: ["; |
| 177 | for (size_t I = 1, E = Func.Counts.size(); I < E; ++I) { |
| 178 | if (Func.Counts[I] > MaxBlockCount) |
| 179 | MaxBlockCount = Func.Counts[I]; |
| 180 | if (Show && ShowCounts) |
| 181 | OS << (I == 1 ? "" : ", ") << Func.Counts[I]; |
| 182 | } |
| 183 | if (Show && ShowCounts) |
| 184 | OS << "]\n"; |
Justin Bogner | 9e9a057 | 2015-09-29 22:13:58 +0000 | [diff] [blame] | 185 | |
| 186 | if (Show && ShowIndirectCallTargets) { |
Xinliang David Li | 2004f00 | 2015-11-02 05:08:23 +0000 | [diff] [blame^] | 187 | uint32_t NS = Func.getNumValueSites(IPVK_IndirectCallTarget); |
Justin Bogner | 9e9a057 | 2015-09-29 22:13:58 +0000 | [diff] [blame] | 188 | OS << " Indirect Target Results: \n"; |
Xinliang David Li | 2004f00 | 2015-11-02 05:08:23 +0000 | [diff] [blame^] | 189 | for (size_t I = 0; I < NS; ++I) { |
| 190 | uint32_t NV = Func.getNumValueDataForSite(IPVK_IndirectCallTarget, I); |
| 191 | std::unique_ptr<InstrProfValueData[]> VD = |
| 192 | Func.getValueForSite(IPVK_IndirectCallTarget, I); |
| 193 | for (uint32_t V = 0; V < NV; V++) { |
Justin Bogner | 9e9a057 | 2015-09-29 22:13:58 +0000 | [diff] [blame] | 194 | OS << "\t[ " << I << ", "; |
Xinliang David Li | 2004f00 | 2015-11-02 05:08:23 +0000 | [diff] [blame^] | 195 | OS << (const char *)VD[V].Value << ", " << VD[V].Count << " ]\n"; |
Justin Bogner | 9e9a057 | 2015-09-29 22:13:58 +0000 | [diff] [blame] | 196 | } |
| 197 | } |
| 198 | } |
Justin Bogner | 9af28ef | 2014-03-21 17:29:44 +0000 | [diff] [blame] | 199 | } |
Justin Bogner | db1225d | 2014-03-23 20:55:53 +0000 | [diff] [blame] | 200 | if (Reader->hasError()) |
| 201 | exitWithError(Reader->getError().message(), Filename); |
Justin Bogner | 9af28ef | 2014-03-21 17:29:44 +0000 | [diff] [blame] | 202 | |
| 203 | if (ShowAllFunctions || !ShowFunction.empty()) |
| 204 | OS << "Functions shown: " << ShownFunctions << "\n"; |
| 205 | OS << "Total functions: " << TotalFunctions << "\n"; |
| 206 | OS << "Maximum function count: " << MaxFunctionCount << "\n"; |
| 207 | OS << "Maximum internal block count: " << MaxBlockCount << "\n"; |
| 208 | return 0; |
| 209 | } |
| 210 | |
Benjamin Kramer | f044d3f | 2015-03-09 16:23:46 +0000 | [diff] [blame] | 211 | static int showSampleProfile(std::string Filename, bool ShowCounts, |
| 212 | bool ShowAllFunctions, std::string ShowFunction, |
| 213 | raw_fd_ostream &OS) { |
Diego Novillo | d5336ae | 2014-11-01 00:56:55 +0000 | [diff] [blame] | 214 | using namespace sampleprof; |
Diego Novillo | fcd5560 | 2014-11-03 00:51:45 +0000 | [diff] [blame] | 215 | auto ReaderOrErr = SampleProfileReader::create(Filename, getGlobalContext()); |
| 216 | if (std::error_code EC = ReaderOrErr.getError()) |
Diego Novillo | d5336ae | 2014-11-01 00:56:55 +0000 | [diff] [blame] | 217 | exitWithError(EC.message(), Filename); |
| 218 | |
Diego Novillo | fcd5560 | 2014-11-03 00:51:45 +0000 | [diff] [blame] | 219 | auto Reader = std::move(ReaderOrErr.get()); |
Diego Novillo | c6d032a | 2015-09-17 00:17:21 +0000 | [diff] [blame] | 220 | if (std::error_code EC = Reader->read()) |
| 221 | exitWithError(EC.message(), Filename); |
| 222 | |
Diego Novillo | d5336ae | 2014-11-01 00:56:55 +0000 | [diff] [blame] | 223 | if (ShowAllFunctions || ShowFunction.empty()) |
| 224 | Reader->dump(OS); |
| 225 | else |
| 226 | Reader->dumpFunctionProfile(ShowFunction, OS); |
| 227 | |
| 228 | return 0; |
| 229 | } |
| 230 | |
Benjamin Kramer | f044d3f | 2015-03-09 16:23:46 +0000 | [diff] [blame] | 231 | static int show_main(int argc, const char *argv[]) { |
Diego Novillo | d5336ae | 2014-11-01 00:56:55 +0000 | [diff] [blame] | 232 | cl::opt<std::string> Filename(cl::Positional, cl::Required, |
| 233 | cl::desc("<profdata-file>")); |
| 234 | |
| 235 | cl::opt<bool> ShowCounts("counts", cl::init(false), |
| 236 | cl::desc("Show counter values for shown functions")); |
Justin Bogner | 9e9a057 | 2015-09-29 22:13:58 +0000 | [diff] [blame] | 237 | cl::opt<bool> ShowIndirectCallTargets( |
| 238 | "ic-targets", cl::init(false), |
| 239 | cl::desc("Show indirect call site target values for shown functions")); |
Diego Novillo | d5336ae | 2014-11-01 00:56:55 +0000 | [diff] [blame] | 240 | cl::opt<bool> ShowAllFunctions("all-functions", cl::init(false), |
| 241 | cl::desc("Details for every function")); |
| 242 | cl::opt<std::string> ShowFunction("function", |
| 243 | cl::desc("Details for matching functions")); |
| 244 | |
| 245 | cl::opt<std::string> OutputFilename("output", cl::value_desc("output"), |
| 246 | cl::init("-"), cl::desc("Output file")); |
| 247 | cl::alias OutputFilenameA("o", cl::desc("Alias for --output"), |
| 248 | cl::aliasopt(OutputFilename)); |
| 249 | cl::opt<ProfileKinds> ProfileKind( |
| 250 | cl::desc("Profile kind:"), cl::init(instr), |
| 251 | cl::values(clEnumVal(instr, "Instrumentation profile (default)"), |
| 252 | clEnumVal(sample, "Sample profile"), clEnumValEnd)); |
| 253 | |
| 254 | cl::ParseCommandLineOptions(argc, argv, "LLVM profile data summary\n"); |
| 255 | |
| 256 | if (OutputFilename.empty()) |
| 257 | OutputFilename = "-"; |
| 258 | |
| 259 | std::error_code EC; |
| 260 | raw_fd_ostream OS(OutputFilename.data(), EC, sys::fs::F_Text); |
| 261 | if (EC) |
| 262 | exitWithError(EC.message(), OutputFilename); |
| 263 | |
| 264 | if (ShowAllFunctions && !ShowFunction.empty()) |
| 265 | errs() << "warning: -function argument ignored: showing all functions\n"; |
| 266 | |
| 267 | if (ProfileKind == instr) |
Justin Bogner | 9e9a057 | 2015-09-29 22:13:58 +0000 | [diff] [blame] | 268 | return showInstrProfile(Filename, ShowCounts, ShowIndirectCallTargets, |
| 269 | ShowAllFunctions, ShowFunction, OS); |
Diego Novillo | d5336ae | 2014-11-01 00:56:55 +0000 | [diff] [blame] | 270 | else |
| 271 | return showSampleProfile(Filename, ShowCounts, ShowAllFunctions, |
| 272 | ShowFunction, OS); |
| 273 | } |
| 274 | |
Justin Bogner | 618bcea | 2014-03-19 02:20:46 +0000 | [diff] [blame] | 275 | int main(int argc, const char *argv[]) { |
| 276 | // Print a stack trace if we signal out. |
| 277 | sys::PrintStackTraceOnErrorSignal(); |
| 278 | PrettyStackTraceProgram X(argc, argv); |
| 279 | llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. |
| 280 | |
| 281 | StringRef ProgName(sys::path::filename(argv[0])); |
| 282 | if (argc > 1) { |
Craig Topper | e6cb63e | 2014-04-25 04:24:47 +0000 | [diff] [blame] | 283 | int (*func)(int, const char *[]) = nullptr; |
Justin Bogner | 618bcea | 2014-03-19 02:20:46 +0000 | [diff] [blame] | 284 | |
| 285 | if (strcmp(argv[1], "merge") == 0) |
| 286 | func = merge_main; |
Justin Bogner | 9af28ef | 2014-03-21 17:29:44 +0000 | [diff] [blame] | 287 | else if (strcmp(argv[1], "show") == 0) |
| 288 | func = show_main; |
Justin Bogner | 618bcea | 2014-03-19 02:20:46 +0000 | [diff] [blame] | 289 | |
| 290 | if (func) { |
| 291 | std::string Invocation(ProgName.str() + " " + argv[1]); |
| 292 | argv[1] = Invocation.c_str(); |
| 293 | return func(argc - 1, argv + 1); |
| 294 | } |
| 295 | |
| 296 | if (strcmp(argv[1], "-h") == 0 || |
| 297 | strcmp(argv[1], "-help") == 0 || |
| 298 | strcmp(argv[1], "--help") == 0) { |
| 299 | |
| 300 | errs() << "OVERVIEW: LLVM profile data tools\n\n" |
| 301 | << "USAGE: " << ProgName << " <command> [args...]\n" |
| 302 | << "USAGE: " << ProgName << " <command> -help\n\n" |
Justin Bogner | 9af28ef | 2014-03-21 17:29:44 +0000 | [diff] [blame] | 303 | << "Available commands: merge, show\n"; |
Justin Bogner | 618bcea | 2014-03-19 02:20:46 +0000 | [diff] [blame] | 304 | return 0; |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | if (argc < 2) |
| 309 | errs() << ProgName << ": No command specified!\n"; |
| 310 | else |
| 311 | errs() << ProgName << ": Unknown command!\n"; |
| 312 | |
Justin Bogner | 9af28ef | 2014-03-21 17:29:44 +0000 | [diff] [blame] | 313 | errs() << "USAGE: " << ProgName << " <merge|show> [args...]\n"; |
Justin Bogner | 618bcea | 2014-03-19 02:20:46 +0000 | [diff] [blame] | 314 | return 1; |
| 315 | } |