|
16 | 16 | #include "llvm/Support/ErrorHandling.h"
|
17 | 17 | #include "llvm/Support/ManagedStatic.h"
|
18 | 18 |
|
| 19 | +using namespace llvm::sampleprof; |
19 | 20 | using namespace llvm;
|
20 | 21 |
|
21 | 22 | namespace {
|
@@ -55,3 +56,34 @@ static ManagedStatic<SampleProfErrorCategoryType> ErrorCategory;
|
55 | 56 | const std::error_category &llvm::sampleprof_category() {
|
56 | 57 | return *ErrorCategory;
|
57 | 58 | }
|
| 59 | + |
| 60 | +/// \brief Print the samples collected for a function on stream \p OS. |
| 61 | +/// |
| 62 | +/// \param OS Stream to emit the output to. |
| 63 | +void FunctionSamples::print(raw_ostream &OS, unsigned Indent) const { |
| 64 | + OS << TotalSamples << ", " << TotalHeadSamples << ", " << BodySamples.size() |
| 65 | + << " sampled lines\n"; |
| 66 | + for (const auto &SI : BodySamples) { |
| 67 | + LineLocation Loc = SI.first; |
| 68 | + const SampleRecord &Sample = SI.second; |
| 69 | + OS.indent(Indent); |
| 70 | + OS << "line offset: " << Loc.LineOffset |
| 71 | + << ", discriminator: " << Loc.Discriminator |
| 72 | + << ", number of samples: " << Sample.getSamples(); |
| 73 | + if (Sample.hasCalls()) { |
| 74 | + OS << ", calls:"; |
| 75 | + for (const auto &I : Sample.getCallTargets()) |
| 76 | + OS << " " << I.first() << ":" << I.second; |
| 77 | + } |
| 78 | + OS << "\n"; |
| 79 | + } |
| 80 | + for (const auto &CS : CallsiteSamples) { |
| 81 | + CallsiteLocation Loc = CS.first; |
| 82 | + const FunctionSamples &CalleeSamples = CS.second; |
| 83 | + OS.indent(Indent); |
| 84 | + OS << "line offset: " << Loc.LineOffset |
| 85 | + << ", discriminator: " << Loc.Discriminator |
| 86 | + << ", inlined callee: " << Loc.CalleeName << ": "; |
| 87 | + CalleeSamples.print(OS, Indent + 2); |
| 88 | + } |
| 89 | +} |
0 commit comments