blob: 3f01605fd85242e5f3246d5ca1fe7a470cb27bdd [file] [log] [blame]
Dean Michael Berris429bac82017-01-12 07:38:13 +00001//===- xray-account.h - XRay Function Call Accounting ---------------------===//
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// This file implements basic function call accounting from an XRay trace.
11//
12//===----------------------------------------------------------------------===//
13
14#include <algorithm>
15#include <cassert>
Dean Michael Berris0c6392d2017-01-12 07:43:54 +000016#include <numeric>
Dean Michael Berris429bac82017-01-12 07:38:13 +000017#include <system_error>
18#include <utility>
19
20#include "xray-account.h"
Dean Michael Berris429bac82017-01-12 07:38:13 +000021#include "xray-registry.h"
22#include "llvm/Support/ErrorHandling.h"
23#include "llvm/Support/FormatVariadic.h"
Dean Michael Berris0e8abab2017-02-01 00:05:29 +000024#include "llvm/XRay/InstrumentationMap.h"
Dean Michael Berris429bac82017-01-12 07:38:13 +000025#include "llvm/XRay/Trace.h"
26
27using namespace llvm;
28using namespace llvm::xray;
29
30static cl::SubCommand Account("account", "Function call accounting");
31static cl::opt<std::string> AccountInput(cl::Positional,
32 cl::desc("<xray log file>"),
33 cl::Required, cl::sub(Account));
34static cl::opt<bool>
35 AccountKeepGoing("keep-going", cl::desc("Keep going on errors encountered"),
36 cl::sub(Account), cl::init(false));
37static cl::alias AccountKeepGoing2("k", cl::aliasopt(AccountKeepGoing),
38 cl::desc("Alias for -keep_going"),
39 cl::sub(Account));
40static cl::opt<bool> AccountDeduceSiblingCalls(
41 "deduce-sibling-calls",
42 cl::desc("Deduce sibling calls when unrolling function call stacks"),
43 cl::sub(Account), cl::init(false));
44static cl::alias
45 AccountDeduceSiblingCalls2("d", cl::aliasopt(AccountDeduceSiblingCalls),
46 cl::desc("Alias for -deduce_sibling_calls"),
47 cl::sub(Account));
48static cl::opt<std::string>
49 AccountOutput("output", cl::value_desc("output file"), cl::init("-"),
50 cl::desc("output file; use '-' for stdout"),
51 cl::sub(Account));
52static cl::alias AccountOutput2("o", cl::aliasopt(AccountOutput),
53 cl::desc("Alias for -output"),
54 cl::sub(Account));
55enum class AccountOutputFormats { TEXT, CSV };
56static cl::opt<AccountOutputFormats>
57 AccountOutputFormat("format", cl::desc("output format"),
58 cl::values(clEnumValN(AccountOutputFormats::TEXT,
59 "text", "report stats in text"),
60 clEnumValN(AccountOutputFormats::CSV, "csv",
61 "report stats in csv")),
62 cl::sub(Account));
63static cl::alias AccountOutputFormat2("f", cl::desc("Alias of -format"),
64 cl::aliasopt(AccountOutputFormat),
65 cl::sub(Account));
66
67enum class SortField {
68 FUNCID,
69 COUNT,
70 MIN,
71 MED,
72 PCT90,
73 PCT99,
74 MAX,
75 SUM,
76 FUNC,
77};
78
79static cl::opt<SortField> AccountSortOutput(
80 "sort", cl::desc("sort output by this field"), cl::value_desc("field"),
81 cl::sub(Account), cl::init(SortField::FUNCID),
82 cl::values(clEnumValN(SortField::FUNCID, "funcid", "function id"),
83 clEnumValN(SortField::COUNT, "count", "funciton call counts"),
84 clEnumValN(SortField::MIN, "min", "minimum function durations"),
85 clEnumValN(SortField::MED, "med", "median function durations"),
86 clEnumValN(SortField::PCT90, "90p", "90th percentile durations"),
87 clEnumValN(SortField::PCT99, "99p", "99th percentile durations"),
88 clEnumValN(SortField::MAX, "max", "maximum function durations"),
89 clEnumValN(SortField::SUM, "sum", "sum of call durations"),
90 clEnumValN(SortField::FUNC, "func", "function names")));
91static cl::alias AccountSortOutput2("s", cl::aliasopt(AccountSortOutput),
92 cl::desc("Alias for -sort"),
93 cl::sub(Account));
94
95enum class SortDirection {
96 ASCENDING,
97 DESCENDING,
98};
99static cl::opt<SortDirection> AccountSortOrder(
100 "sortorder", cl::desc("sort ordering"), cl::init(SortDirection::ASCENDING),
101 cl::values(clEnumValN(SortDirection::ASCENDING, "asc", "ascending"),
102 clEnumValN(SortDirection::DESCENDING, "dsc", "descending")),
103 cl::sub(Account));
104static cl::alias AccountSortOrder2("r", cl::aliasopt(AccountSortOrder),
105 cl::desc("Alias for -sortorder"),
106 cl::sub(Account));
107
108static cl::opt<int> AccountTop("top", cl::desc("only show the top N results"),
109 cl::value_desc("N"), cl::sub(Account),
110 cl::init(-1));
111static cl::alias AccountTop2("p", cl::desc("Alias for -top"),
112 cl::aliasopt(AccountTop), cl::sub(Account));
113
114static cl::opt<std::string>
115 AccountInstrMap("instr_map",
116 cl::desc("binary with the instrumentation map, or "
117 "a separate instrumentation map"),
118 cl::value_desc("binary with xray_instr_map"),
119 cl::sub(Account), cl::init(""));
120static cl::alias AccountInstrMap2("m", cl::aliasopt(AccountInstrMap),
121 cl::desc("Alias for -instr_map"),
122 cl::sub(Account));
Dean Michael Berris429bac82017-01-12 07:38:13 +0000123
124namespace {
125
126template <class T, class U> void setMinMax(std::pair<T, T> &MM, U &&V) {
127 if (MM.first == 0 || MM.second == 0)
128 MM = std::make_pair(std::forward<U>(V), std::forward<U>(V));
129 else
130 MM = std::make_pair(std::min(MM.first, V), std::max(MM.second, V));
131}
132
133template <class T> T diff(T L, T R) { return std::max(L, R) - std::min(L, R); }
134
135} // namespace
136
137bool LatencyAccountant::accountRecord(const XRayRecord &Record) {
138 setMinMax(PerThreadMinMaxTSC[Record.TId], Record.TSC);
139 setMinMax(PerCPUMinMaxTSC[Record.CPU], Record.TSC);
140
141 if (CurrentMaxTSC == 0)
142 CurrentMaxTSC = Record.TSC;
143
144 if (Record.TSC < CurrentMaxTSC)
145 return false;
146
147 auto &ThreadStack = PerThreadFunctionStack[Record.TId];
148 switch (Record.Type) {
Dean Michael Berris25f8d202018-11-06 08:51:37 +0000149 case RecordTypes::CUSTOM_EVENT:
150 case RecordTypes::TYPED_EVENT:
151 // TODO: Support custom and typed event accounting in the future.
152 return true;
Martin Pelikan10c873f2017-09-27 04:48:03 +0000153 case RecordTypes::ENTER:
154 case RecordTypes::ENTER_ARG: {
Dean Michael Berris429bac82017-01-12 07:38:13 +0000155 ThreadStack.emplace_back(Record.FuncId, Record.TSC);
156 break;
157 }
Dean Michael Berris0f84a7d2017-09-18 06:08:46 +0000158 case RecordTypes::EXIT:
159 case RecordTypes::TAIL_EXIT: {
Dean Michael Berris415f15c2017-08-31 01:07:24 +0000160 if (ThreadStack.empty())
161 return false;
162
Dean Michael Berris429bac82017-01-12 07:38:13 +0000163 if (ThreadStack.back().first == Record.FuncId) {
164 const auto &Top = ThreadStack.back();
165 recordLatency(Top.first, diff(Top.second, Record.TSC));
166 ThreadStack.pop_back();
167 break;
168 }
169
170 if (!DeduceSiblingCalls)
171 return false;
172
173 // Look for the parent up the stack.
174 auto Parent =
175 std::find_if(ThreadStack.rbegin(), ThreadStack.rend(),
176 [&](const std::pair<const int32_t, uint64_t> &E) {
177 return E.first == Record.FuncId;
178 });
179 if (Parent == ThreadStack.rend())
180 return false;
181
182 // Account time for this apparently sibling call exit up the stack.
183 // Considering the following case:
184 //
185 // f()
186 // g()
187 // h()
188 //
189 // We might only ever see the following entries:
190 //
191 // -> f()
192 // -> g()
193 // -> h()
194 // <- h()
195 // <- f()
196 //
197 // Now we don't see the exit to g() because some older version of the XRay
198 // runtime wasn't instrumenting tail exits. If we don't deduce tail calls,
199 // we may potentially never account time for g() -- and this code would have
200 // already bailed out, because `<- f()` doesn't match the current "top" of
201 // stack where we're waiting for the exit to `g()` instead. This is not
202 // ideal and brittle -- so instead we provide a potentially inaccurate
203 // accounting of g() instead, computing it from the exit of f().
204 //
205 // While it might be better that we account the time between `-> g()` and
206 // `-> h()` as the proper accounting of time for g() here, this introduces
207 // complexity to do correctly (need to backtrack, etc.).
208 //
209 // FIXME: Potentially implement the more complex deduction algorithm?
210 auto I = std::next(Parent).base();
211 for (auto &E : make_range(I, ThreadStack.end())) {
212 recordLatency(E.first, diff(E.second, Record.TSC));
213 }
214 ThreadStack.erase(I, ThreadStack.end());
215 break;
216 }
217 }
218
219 return true;
220}
221
222namespace {
223
224// We consolidate the data into a struct which we can output in various forms.
225struct ResultRow {
226 uint64_t Count;
227 double Min;
228 double Median;
229 double Pct90;
230 double Pct99;
231 double Max;
232 double Sum;
233 std::string DebugInfo;
234 std::string Function;
235};
236
237ResultRow getStats(std::vector<uint64_t> &Timings) {
238 assert(!Timings.empty());
239 ResultRow R;
240 R.Sum = std::accumulate(Timings.begin(), Timings.end(), 0.0);
241 auto MinMax = std::minmax_element(Timings.begin(), Timings.end());
242 R.Min = *MinMax.first;
243 R.Max = *MinMax.second;
Martin Pelikancb6422d2018-01-30 18:18:51 +0000244 R.Count = Timings.size();
245
Dean Michael Berris429bac82017-01-12 07:38:13 +0000246 auto MedianOff = Timings.size() / 2;
247 std::nth_element(Timings.begin(), Timings.begin() + MedianOff, Timings.end());
248 R.Median = Timings[MedianOff];
Martin Pelikancb6422d2018-01-30 18:18:51 +0000249
Dean Michael Berris429bac82017-01-12 07:38:13 +0000250 auto Pct90Off = std::floor(Timings.size() * 0.9);
251 std::nth_element(Timings.begin(), Timings.begin() + Pct90Off, Timings.end());
252 R.Pct90 = Timings[Pct90Off];
Martin Pelikancb6422d2018-01-30 18:18:51 +0000253
Dean Michael Berris429bac82017-01-12 07:38:13 +0000254 auto Pct99Off = std::floor(Timings.size() * 0.99);
Martin Pelikancb6422d2018-01-30 18:18:51 +0000255 std::nth_element(Timings.begin(), Timings.begin() + Pct99Off, Timings.end());
Dean Michael Berris429bac82017-01-12 07:38:13 +0000256 R.Pct99 = Timings[Pct99Off];
Dean Michael Berris429bac82017-01-12 07:38:13 +0000257 return R;
258}
259
260} // namespace
261
262template <class F>
263void LatencyAccountant::exportStats(const XRayFileHeader &Header, F Fn) const {
264 using TupleType = std::tuple<int32_t, uint64_t, ResultRow>;
265 std::vector<TupleType> Results;
266 Results.reserve(FunctionLatencies.size());
267 for (auto FT : FunctionLatencies) {
268 const auto &FuncId = FT.first;
269 auto &Timings = FT.second;
270 Results.emplace_back(FuncId, Timings.size(), getStats(Timings));
271 auto &Row = std::get<2>(Results.back());
272 if (Header.CycleFrequency) {
273 double CycleFrequency = Header.CycleFrequency;
274 Row.Min /= CycleFrequency;
275 Row.Median /= CycleFrequency;
276 Row.Pct90 /= CycleFrequency;
277 Row.Pct99 /= CycleFrequency;
278 Row.Max /= CycleFrequency;
279 Row.Sum /= CycleFrequency;
280 }
281
282 Row.Function = FuncIdHelper.SymbolOrNumber(FuncId);
283 Row.DebugInfo = FuncIdHelper.FileLineAndColumn(FuncId);
284 }
285
286 // Sort the data according to user-provided flags.
287 switch (AccountSortOutput) {
288 case SortField::FUNCID:
Fangrui Song0cac7262018-09-27 02:13:45 +0000289 llvm::sort(Results, [](const TupleType &L, const TupleType &R) {
290 if (AccountSortOrder == SortDirection::ASCENDING)
291 return std::get<0>(L) < std::get<0>(R);
292 if (AccountSortOrder == SortDirection::DESCENDING)
293 return std::get<0>(L) > std::get<0>(R);
294 llvm_unreachable("Unknown sort direction");
295 });
Dean Michael Berris429bac82017-01-12 07:38:13 +0000296 break;
297 case SortField::COUNT:
Fangrui Song0cac7262018-09-27 02:13:45 +0000298 llvm::sort(Results, [](const TupleType &L, const TupleType &R) {
299 if (AccountSortOrder == SortDirection::ASCENDING)
300 return std::get<1>(L) < std::get<1>(R);
301 if (AccountSortOrder == SortDirection::DESCENDING)
302 return std::get<1>(L) > std::get<1>(R);
303 llvm_unreachable("Unknown sort direction");
304 });
Dean Michael Berris429bac82017-01-12 07:38:13 +0000305 break;
306 default:
307 // Here we need to look into the ResultRow for the rest of the data that
308 // we want to sort by.
Fangrui Song0cac7262018-09-27 02:13:45 +0000309 llvm::sort(Results, [&](const TupleType &L, const TupleType &R) {
310 auto &LR = std::get<2>(L);
311 auto &RR = std::get<2>(R);
312 switch (AccountSortOutput) {
313 case SortField::COUNT:
314 if (AccountSortOrder == SortDirection::ASCENDING)
315 return LR.Count < RR.Count;
316 if (AccountSortOrder == SortDirection::DESCENDING)
317 return LR.Count > RR.Count;
318 llvm_unreachable("Unknown sort direction");
319 case SortField::MIN:
320 if (AccountSortOrder == SortDirection::ASCENDING)
321 return LR.Min < RR.Min;
322 if (AccountSortOrder == SortDirection::DESCENDING)
323 return LR.Min > RR.Min;
324 llvm_unreachable("Unknown sort direction");
325 case SortField::MED:
326 if (AccountSortOrder == SortDirection::ASCENDING)
327 return LR.Median < RR.Median;
328 if (AccountSortOrder == SortDirection::DESCENDING)
329 return LR.Median > RR.Median;
330 llvm_unreachable("Unknown sort direction");
331 case SortField::PCT90:
332 if (AccountSortOrder == SortDirection::ASCENDING)
333 return LR.Pct90 < RR.Pct90;
334 if (AccountSortOrder == SortDirection::DESCENDING)
335 return LR.Pct90 > RR.Pct90;
336 llvm_unreachable("Unknown sort direction");
337 case SortField::PCT99:
338 if (AccountSortOrder == SortDirection::ASCENDING)
339 return LR.Pct99 < RR.Pct99;
340 if (AccountSortOrder == SortDirection::DESCENDING)
341 return LR.Pct99 > RR.Pct99;
342 llvm_unreachable("Unknown sort direction");
343 case SortField::MAX:
344 if (AccountSortOrder == SortDirection::ASCENDING)
345 return LR.Max < RR.Max;
346 if (AccountSortOrder == SortDirection::DESCENDING)
347 return LR.Max > RR.Max;
348 llvm_unreachable("Unknown sort direction");
349 case SortField::SUM:
350 if (AccountSortOrder == SortDirection::ASCENDING)
351 return LR.Sum < RR.Sum;
352 if (AccountSortOrder == SortDirection::DESCENDING)
353 return LR.Sum > RR.Sum;
354 llvm_unreachable("Unknown sort direction");
355 default:
356 llvm_unreachable("Unsupported sort order");
357 }
358 });
Dean Michael Berris429bac82017-01-12 07:38:13 +0000359 break;
360 }
361
David Carlier38a20c22018-09-18 10:31:10 +0000362 if (AccountTop > 0) {
363 auto MaxTop =
364 std::min(AccountTop.getValue(), static_cast<int>(Results.size()));
365 Results.erase(Results.begin() + MaxTop, Results.end());
366 }
Dean Michael Berris429bac82017-01-12 07:38:13 +0000367
368 for (const auto &R : Results)
369 Fn(std::get<0>(R), std::get<1>(R), std::get<2>(R));
370}
371
372void LatencyAccountant::exportStatsAsText(raw_ostream &OS,
373 const XRayFileHeader &Header) const {
374 OS << "Functions with latencies: " << FunctionLatencies.size() << "\n";
375
376 // We spend some effort to make the text output more readable, so we do the
377 // following formatting decisions for each of the fields:
378 //
379 // - funcid: 32-bit, but we can determine the largest number and be
380 // between
381 // a minimum of 5 characters, up to 9 characters, right aligned.
382 // - count: 64-bit, but we can determine the largest number and be
383 // between
384 // a minimum of 5 characters, up to 9 characters, right aligned.
385 // - min, median, 90pct, 99pct, max: double precision, but we want to keep
386 // the values in seconds, with microsecond precision (0.000'001), so we
387 // have at most 6 significant digits, with the whole number part to be
388 // at
389 // least 1 character. For readability we'll right-align, with full 9
390 // characters each.
391 // - debug info, function name: we format this as a concatenation of the
392 // debug info and the function name.
393 //
394 static constexpr char StatsHeaderFormat[] =
395 "{0,+9} {1,+10} [{2,+9}, {3,+9}, {4,+9}, {5,+9}, {6,+9}] {7,+9}";
396 static constexpr char StatsFormat[] =
397 R"({0,+9} {1,+10} [{2,+9:f6}, {3,+9:f6}, {4,+9:f6}, {5,+9:f6}, {6,+9:f6}] {7,+9:f6})";
398 OS << llvm::formatv(StatsHeaderFormat, "funcid", "count", "min", "med", "90p",
399 "99p", "max", "sum")
400 << llvm::formatv(" {0,-12}\n", "function");
401 exportStats(Header, [&](int32_t FuncId, size_t Count, const ResultRow &Row) {
402 OS << llvm::formatv(StatsFormat, FuncId, Count, Row.Min, Row.Median,
403 Row.Pct90, Row.Pct99, Row.Max, Row.Sum)
404 << " " << Row.DebugInfo << ": " << Row.Function << "\n";
405 });
406}
407
408void LatencyAccountant::exportStatsAsCSV(raw_ostream &OS,
409 const XRayFileHeader &Header) const {
410 OS << "funcid,count,min,median,90%ile,99%ile,max,sum,debug,function\n";
411 exportStats(Header, [&](int32_t FuncId, size_t Count, const ResultRow &Row) {
412 OS << FuncId << ',' << Count << ',' << Row.Min << ',' << Row.Median << ','
413 << Row.Pct90 << ',' << Row.Pct99 << ',' << Row.Max << "," << Row.Sum
414 << ",\"" << Row.DebugInfo << "\",\"" << Row.Function << "\"\n";
415 });
416}
417
418using namespace llvm::xray;
419
Dean Michael Berris415f15c2017-08-31 01:07:24 +0000420namespace llvm {
421template <> struct format_provider<llvm::xray::RecordTypes> {
422 static void format(const llvm::xray::RecordTypes &T, raw_ostream &Stream,
423 StringRef Style) {
Dean Michael Berris25f8d202018-11-06 08:51:37 +0000424 switch (T) {
425 case RecordTypes::ENTER:
426 Stream << "enter";
427 break;
428 case RecordTypes::ENTER_ARG:
429 Stream << "enter-arg";
430 break;
431 case RecordTypes::EXIT:
432 Stream << "exit";
433 break;
434 case RecordTypes::TAIL_EXIT:
435 Stream << "tail-exit";
436 break;
437 case RecordTypes::CUSTOM_EVENT:
438 Stream << "custom-event";
439 break;
440 case RecordTypes::TYPED_EVENT:
441 Stream << "typed-event";
442 break;
Dean Michael Berris415f15c2017-08-31 01:07:24 +0000443 }
444 }
445};
446} // namespace llvm
447
Dean Michael Berris429bac82017-01-12 07:38:13 +0000448static CommandRegistration Unused(&Account, []() -> Error {
Dean Michael Berris0e8abab2017-02-01 00:05:29 +0000449 InstrumentationMap Map;
450 if (!AccountInstrMap.empty()) {
451 auto InstrumentationMapOrError = loadInstrumentationMap(AccountInstrMap);
452 if (!InstrumentationMapOrError)
453 return joinErrors(make_error<StringError>(
454 Twine("Cannot open instrumentation map '") +
455 AccountInstrMap + "'",
456 std::make_error_code(std::errc::invalid_argument)),
457 InstrumentationMapOrError.takeError());
458 Map = std::move(*InstrumentationMapOrError);
459 }
Dean Michael Berris429bac82017-01-12 07:38:13 +0000460
Dean Michael Berris0e8abab2017-02-01 00:05:29 +0000461 std::error_code EC;
Dean Michael Berris429bac82017-01-12 07:38:13 +0000462 raw_fd_ostream OS(AccountOutput, EC, sys::fs::OpenFlags::F_Text);
463 if (EC)
464 return make_error<StringError>(
465 Twine("Cannot open file '") + AccountOutput + "' for writing.", EC);
466
Dean Michael Berris0e8abab2017-02-01 00:05:29 +0000467 const auto &FunctionAddresses = Map.getFunctionAddresses();
Dean Michael Berris429bac82017-01-12 07:38:13 +0000468 symbolize::LLVMSymbolizer::Options Opts(
469 symbolize::FunctionNameKind::LinkageName, true, true, false, "");
470 symbolize::LLVMSymbolizer Symbolizer(Opts);
471 llvm::xray::FuncIdConversionHelper FuncIdHelper(AccountInstrMap, Symbolizer,
472 FunctionAddresses);
473 xray::LatencyAccountant FCA(FuncIdHelper, AccountDeduceSiblingCalls);
Dean Michael Berris0e8abab2017-02-01 00:05:29 +0000474 auto TraceOrErr = loadTraceFile(AccountInput);
475 if (!TraceOrErr)
Dean Michael Berris429bac82017-01-12 07:38:13 +0000476 return joinErrors(
477 make_error<StringError>(
478 Twine("Failed loading input file '") + AccountInput + "'",
Hans Wennborg84da6612017-01-12 18:33:14 +0000479 std::make_error_code(std::errc::executable_format_error)),
Dean Michael Berris429bac82017-01-12 07:38:13 +0000480 TraceOrErr.takeError());
Dean Michael Berris0e8abab2017-02-01 00:05:29 +0000481
482 auto &T = *TraceOrErr;
483 for (const auto &Record : T) {
484 if (FCA.accountRecord(Record))
485 continue;
Dean Michael Berris415f15c2017-08-31 01:07:24 +0000486 errs()
487 << "Error processing record: "
488 << llvm::formatv(
Dean Michael Berris10141262018-07-13 05:38:22 +0000489 R"({{type: {0}; cpu: {1}; record-type: {2}; function-id: {3}; tsc: {4}; thread-id: {5}; process-id: {6}}})",
Dean Michael Berris415f15c2017-08-31 01:07:24 +0000490 Record.RecordType, Record.CPU, Record.Type, Record.FuncId,
Dean Michael Berris10141262018-07-13 05:38:22 +0000491 Record.TSC, Record.TId, Record.PId)
Dean Michael Berris415f15c2017-08-31 01:07:24 +0000492 << '\n';
Dean Michael Berris0e8abab2017-02-01 00:05:29 +0000493 for (const auto &ThreadStack : FCA.getPerThreadFunctionStack()) {
494 errs() << "Thread ID: " << ThreadStack.first << "\n";
Dean Michael Berris415f15c2017-08-31 01:07:24 +0000495 if (ThreadStack.second.empty()) {
496 errs() << " (empty stack)\n";
497 continue;
498 }
Dean Michael Berris0e8abab2017-02-01 00:05:29 +0000499 auto Level = ThreadStack.second.size();
500 for (const auto &Entry : llvm::reverse(ThreadStack.second))
Dean Michael Berris415f15c2017-08-31 01:07:24 +0000501 errs() << " #" << Level-- << "\t"
Dean Michael Berris0e8abab2017-02-01 00:05:29 +0000502 << FuncIdHelper.SymbolOrNumber(Entry.first) << '\n';
503 }
504 if (!AccountKeepGoing)
505 return make_error<StringError>(
506 Twine("Failed accounting function calls in file '") + AccountInput +
507 "'.",
508 std::make_error_code(std::errc::executable_format_error));
509 }
510 switch (AccountOutputFormat) {
511 case AccountOutputFormats::TEXT:
512 FCA.exportStatsAsText(OS, T.getFileHeader());
513 break;
514 case AccountOutputFormats::CSV:
515 FCA.exportStatsAsCSV(OS, T.getFileHeader());
516 break;
Dean Michael Berris429bac82017-01-12 07:38:13 +0000517 }
518
519 return Error::success();
520});