2014-10-30 19:00:06 +01:00
|
|
|
//===- SampleProfWriter.cpp - Write LLVM sample profile data --------------===//
|
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2014-10-30 19:00:06 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the class that writes LLVM sample profiles. It
|
|
|
|
// supports two file formats: text and binary. The textual representation
|
|
|
|
// is useful for debugging and testing purposes. The binary representation
|
|
|
|
// is more compact, resulting in smaller file sizes. However, they can
|
|
|
|
// both be used interchangeably.
|
|
|
|
//
|
|
|
|
// See lib/ProfileData/SampleProfReader.cpp for documentation on each of the
|
|
|
|
// supported formats.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-06-06 13:49:48 +02:00
|
|
|
#include "llvm/ProfileData/SampleProfWriter.h"
|
2017-03-03 02:07:34 +01:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
#include "llvm/ProfileData/ProfileCommon.h"
|
|
|
|
#include "llvm/ProfileData/SampleProf.h"
|
2018-09-14 22:52:59 +02:00
|
|
|
#include "llvm/Support/Endian.h"
|
|
|
|
#include "llvm/Support/EndianStream.h"
|
2014-10-30 19:00:06 +01:00
|
|
|
#include "llvm/Support/ErrorOr.h"
|
2017-03-03 02:07:34 +01:00
|
|
|
#include "llvm/Support/FileSystem.h"
|
2014-10-30 19:00:06 +01:00
|
|
|
#include "llvm/Support/LEB128.h"
|
2018-06-12 00:40:43 +02:00
|
|
|
#include "llvm/Support/MD5.h"
|
2017-03-03 02:07:34 +01:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
#include <algorithm>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <memory>
|
2017-05-12 01:43:44 +02:00
|
|
|
#include <set>
|
2017-03-03 02:07:34 +01:00
|
|
|
#include <system_error>
|
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
2014-10-30 19:00:06 +01:00
|
|
|
|
|
|
|
using namespace llvm;
|
2017-03-03 02:07:34 +01:00
|
|
|
using namespace sampleprof;
|
2014-10-30 19:00:06 +01:00
|
|
|
|
2017-05-12 01:43:44 +02:00
|
|
|
std::error_code
|
|
|
|
SampleProfileWriter::write(const StringMap<FunctionSamples> &ProfileMap) {
|
|
|
|
if (std::error_code EC = writeHeader(ProfileMap))
|
|
|
|
return EC;
|
|
|
|
|
|
|
|
// Sort the ProfileMap by total samples.
|
|
|
|
typedef std::pair<StringRef, const FunctionSamples *> NameFunctionSamples;
|
|
|
|
std::vector<NameFunctionSamples> V;
|
|
|
|
for (const auto &I : ProfileMap)
|
|
|
|
V.push_back(std::make_pair(I.getKey(), &I.second));
|
|
|
|
|
2019-04-23 16:51:27 +02:00
|
|
|
llvm::stable_sort(
|
|
|
|
V, [](const NameFunctionSamples &A, const NameFunctionSamples &B) {
|
2017-05-12 01:43:44 +02:00
|
|
|
if (A.second->getTotalSamples() == B.second->getTotalSamples())
|
|
|
|
return A.first > B.first;
|
|
|
|
return A.second->getTotalSamples() > B.second->getTotalSamples();
|
|
|
|
});
|
|
|
|
|
|
|
|
for (const auto &I : V) {
|
|
|
|
if (std::error_code EC = write(*I.second))
|
|
|
|
return EC;
|
|
|
|
}
|
|
|
|
return sampleprof_error::success;
|
|
|
|
}
|
|
|
|
|
2018-09-14 22:52:59 +02:00
|
|
|
std::error_code SampleProfileWriterCompactBinary::write(
|
|
|
|
const StringMap<FunctionSamples> &ProfileMap) {
|
|
|
|
if (std::error_code EC = SampleProfileWriter::write(ProfileMap))
|
|
|
|
return EC;
|
|
|
|
if (std::error_code EC = writeFuncOffsetTable())
|
|
|
|
return EC;
|
|
|
|
return sampleprof_error::success;
|
|
|
|
}
|
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Write samples to a text file.
|
2015-11-13 21:24:28 +01:00
|
|
|
///
|
|
|
|
/// Note: it may be tempting to implement this in terms of
|
2015-11-19 16:33:08 +01:00
|
|
|
/// FunctionSamples::print(). Please don't. The dump functionality is intended
|
2015-11-13 21:24:28 +01:00
|
|
|
/// for debugging and has no specified form.
|
|
|
|
///
|
|
|
|
/// The format used here is more structured and deliberate because
|
|
|
|
/// it needs to be parsed by the SampleProfileReaderText class.
|
2016-03-03 19:09:32 +01:00
|
|
|
std::error_code SampleProfileWriterText::write(const FunctionSamples &S) {
|
2015-12-10 18:21:42 +01:00
|
|
|
auto &OS = *OutputStream;
|
2016-03-03 19:09:32 +01:00
|
|
|
OS << S.getName() << ":" << S.getTotalSamples();
|
2015-10-08 21:40:37 +02:00
|
|
|
if (Indent == 0)
|
|
|
|
OS << ":" << S.getHeadSamples();
|
|
|
|
OS << "\n";
|
2014-10-30 19:00:06 +01:00
|
|
|
|
2015-11-19 16:33:08 +01:00
|
|
|
SampleSorter<LineLocation, SampleRecord> SortedSamples(S.getBodySamples());
|
|
|
|
for (const auto &I : SortedSamples.get()) {
|
|
|
|
LineLocation Loc = I->first;
|
|
|
|
const SampleRecord &Sample = I->second;
|
2015-10-08 21:40:37 +02:00
|
|
|
OS.indent(Indent + 1);
|
2014-10-30 19:00:06 +01:00
|
|
|
if (Loc.Discriminator == 0)
|
|
|
|
OS << Loc.LineOffset << ": ";
|
|
|
|
else
|
|
|
|
OS << Loc.LineOffset << "." << Loc.Discriminator << ": ";
|
|
|
|
|
|
|
|
OS << Sample.getSamples();
|
|
|
|
|
2014-11-01 01:56:55 +01:00
|
|
|
for (const auto &J : Sample.getCallTargets())
|
|
|
|
OS << " " << J.first() << ":" << J.second;
|
2014-10-30 19:00:06 +01:00
|
|
|
OS << "\n";
|
|
|
|
}
|
|
|
|
|
2017-04-13 21:52:10 +02:00
|
|
|
SampleSorter<LineLocation, FunctionSamplesMap> SortedCallsiteSamples(
|
2015-11-19 16:33:08 +01:00
|
|
|
S.getCallsiteSamples());
|
2015-10-08 21:40:37 +02:00
|
|
|
Indent += 1;
|
2017-04-13 21:52:10 +02:00
|
|
|
for (const auto &I : SortedCallsiteSamples.get())
|
|
|
|
for (const auto &FS : I->second) {
|
|
|
|
LineLocation Loc = I->first;
|
|
|
|
const FunctionSamples &CalleeSamples = FS.second;
|
|
|
|
OS.indent(Indent);
|
|
|
|
if (Loc.Discriminator == 0)
|
|
|
|
OS << Loc.LineOffset << ": ";
|
|
|
|
else
|
|
|
|
OS << Loc.LineOffset << "." << Loc.Discriminator << ": ";
|
|
|
|
if (std::error_code EC = write(CalleeSamples))
|
|
|
|
return EC;
|
|
|
|
}
|
2015-10-08 21:40:37 +02:00
|
|
|
Indent -= 1;
|
|
|
|
|
2015-10-14 00:48:46 +02:00
|
|
|
return sampleprof_error::success;
|
2014-10-30 19:00:06 +01:00
|
|
|
}
|
|
|
|
|
2015-10-14 00:48:46 +02:00
|
|
|
std::error_code SampleProfileWriterBinary::writeNameIdx(StringRef FName) {
|
|
|
|
const auto &ret = NameTable.find(FName);
|
|
|
|
if (ret == NameTable.end())
|
|
|
|
return sampleprof_error::truncated_name_table;
|
2015-12-10 18:21:42 +01:00
|
|
|
encodeULEB128(ret->second, *OutputStream);
|
2015-10-14 00:48:46 +02:00
|
|
|
return sampleprof_error::success;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SampleProfileWriterBinary::addName(StringRef FName) {
|
2017-05-12 01:43:44 +02:00
|
|
|
NameTable.insert(std::make_pair(FName, 0));
|
2015-10-14 00:48:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SampleProfileWriterBinary::addNames(const FunctionSamples &S) {
|
|
|
|
// Add all the names in indirect call targets.
|
|
|
|
for (const auto &I : S.getBodySamples()) {
|
|
|
|
const SampleRecord &Sample = I.second;
|
|
|
|
for (const auto &J : Sample.getCallTargets())
|
|
|
|
addName(J.first());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Recursively add all the names for inlined callsites.
|
2017-04-13 21:52:10 +02:00
|
|
|
for (const auto &J : S.getCallsiteSamples())
|
|
|
|
for (const auto &FS : J.second) {
|
|
|
|
const FunctionSamples &CalleeSamples = FS.second;
|
|
|
|
addName(CalleeSamples.getName());
|
|
|
|
addNames(CalleeSamples);
|
|
|
|
}
|
2015-10-14 00:48:46 +02:00
|
|
|
}
|
2014-10-30 19:00:06 +01:00
|
|
|
|
2018-06-12 00:40:43 +02:00
|
|
|
void SampleProfileWriterBinary::stablizeNameTable(std::set<StringRef> &V) {
|
|
|
|
// Sort the names to make NameTable deterministic.
|
|
|
|
for (const auto &I : NameTable)
|
|
|
|
V.insert(I.first);
|
|
|
|
int i = 0;
|
|
|
|
for (const StringRef &N : V)
|
|
|
|
NameTable[N] = i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::error_code SampleProfileWriterRawBinary::writeNameTable() {
|
2015-12-10 18:21:42 +01:00
|
|
|
auto &OS = *OutputStream;
|
2018-06-12 00:40:43 +02:00
|
|
|
std::set<StringRef> V;
|
|
|
|
stablizeNameTable(V);
|
|
|
|
|
|
|
|
// Write out the name table.
|
|
|
|
encodeULEB128(NameTable.size(), OS);
|
|
|
|
for (auto N : V) {
|
|
|
|
OS << N;
|
|
|
|
encodeULEB128(0, OS);
|
|
|
|
}
|
|
|
|
return sampleprof_error::success;
|
|
|
|
}
|
|
|
|
|
2018-09-14 22:52:59 +02:00
|
|
|
std::error_code SampleProfileWriterCompactBinary::writeFuncOffsetTable() {
|
|
|
|
auto &OS = *OutputStream;
|
|
|
|
|
|
|
|
// Fill the slot remembered by TableOffset with the offset of FuncOffsetTable.
|
|
|
|
auto &OFS = static_cast<raw_fd_ostream &>(OS);
|
|
|
|
uint64_t FuncOffsetTableStart = OS.tell();
|
|
|
|
if (OFS.seek(TableOffset) == (uint64_t)-1)
|
|
|
|
return sampleprof_error::ostream_seek_unsupported;
|
|
|
|
support::endian::Writer Writer(*OutputStream, support::little);
|
|
|
|
Writer.write(FuncOffsetTableStart);
|
|
|
|
if (OFS.seek(FuncOffsetTableStart) == (uint64_t)-1)
|
|
|
|
return sampleprof_error::ostream_seek_unsupported;
|
|
|
|
|
|
|
|
// Write out the table size.
|
|
|
|
encodeULEB128(FuncOffsetTable.size(), OS);
|
|
|
|
|
|
|
|
// Write out FuncOffsetTable.
|
|
|
|
for (auto entry : FuncOffsetTable) {
|
|
|
|
writeNameIdx(entry.first);
|
|
|
|
encodeULEB128(entry.second, OS);
|
|
|
|
}
|
|
|
|
return sampleprof_error::success;
|
|
|
|
}
|
|
|
|
|
2018-06-12 00:40:43 +02:00
|
|
|
std::error_code SampleProfileWriterCompactBinary::writeNameTable() {
|
|
|
|
auto &OS = *OutputStream;
|
|
|
|
std::set<StringRef> V;
|
|
|
|
stablizeNameTable(V);
|
|
|
|
|
|
|
|
// Write out the name table.
|
|
|
|
encodeULEB128(NameTable.size(), OS);
|
|
|
|
for (auto N : V) {
|
|
|
|
encodeULEB128(MD5Hash(N), OS);
|
|
|
|
}
|
|
|
|
return sampleprof_error::success;
|
|
|
|
}
|
2015-12-10 18:21:42 +01:00
|
|
|
|
2018-06-12 00:40:43 +02:00
|
|
|
std::error_code SampleProfileWriterRawBinary::writeMagicIdent() {
|
|
|
|
auto &OS = *OutputStream;
|
2015-10-14 00:48:46 +02:00
|
|
|
// Write file magic identifier.
|
2014-10-30 19:00:06 +01:00
|
|
|
encodeULEB128(SPMagic(), OS);
|
|
|
|
encodeULEB128(SPVersion(), OS);
|
2018-06-12 00:40:43 +02:00
|
|
|
return sampleprof_error::success;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::error_code SampleProfileWriterCompactBinary::writeMagicIdent() {
|
|
|
|
auto &OS = *OutputStream;
|
|
|
|
// Write file magic identifier.
|
|
|
|
encodeULEB128(SPMagic(SPF_Compact_Binary), OS);
|
|
|
|
encodeULEB128(SPVersion(), OS);
|
|
|
|
return sampleprof_error::success;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::error_code SampleProfileWriterBinary::writeHeader(
|
|
|
|
const StringMap<FunctionSamples> &ProfileMap) {
|
|
|
|
writeMagicIdent();
|
2015-10-14 00:48:46 +02:00
|
|
|
|
2016-02-19 04:15:33 +01:00
|
|
|
computeSummary(ProfileMap);
|
|
|
|
if (auto EC = writeSummary())
|
|
|
|
return EC;
|
|
|
|
|
2015-10-14 00:48:46 +02:00
|
|
|
// Generate the name table for all the functions referenced in the profile.
|
|
|
|
for (const auto &I : ProfileMap) {
|
|
|
|
addName(I.first());
|
|
|
|
addNames(I.second);
|
|
|
|
}
|
|
|
|
|
2018-06-12 00:40:43 +02:00
|
|
|
writeNameTable();
|
2015-10-14 00:48:46 +02:00
|
|
|
return sampleprof_error::success;
|
2014-10-30 19:00:06 +01:00
|
|
|
}
|
|
|
|
|
2018-09-14 22:52:59 +02:00
|
|
|
std::error_code SampleProfileWriterCompactBinary::writeHeader(
|
|
|
|
const StringMap<FunctionSamples> &ProfileMap) {
|
|
|
|
support::endian::Writer Writer(*OutputStream, support::little);
|
|
|
|
if (auto EC = SampleProfileWriterBinary::writeHeader(ProfileMap))
|
|
|
|
return EC;
|
|
|
|
|
|
|
|
// Reserve a slot for the offset of function offset table. The slot will
|
|
|
|
// be populated with the offset of FuncOffsetTable later.
|
|
|
|
TableOffset = OutputStream->tell();
|
|
|
|
Writer.write(static_cast<uint64_t>(-2));
|
|
|
|
return sampleprof_error::success;
|
|
|
|
}
|
|
|
|
|
2016-02-19 04:15:33 +01:00
|
|
|
std::error_code SampleProfileWriterBinary::writeSummary() {
|
|
|
|
auto &OS = *OutputStream;
|
2016-05-19 23:53:28 +02:00
|
|
|
encodeULEB128(Summary->getTotalCount(), OS);
|
|
|
|
encodeULEB128(Summary->getMaxCount(), OS);
|
2016-03-29 01:14:29 +02:00
|
|
|
encodeULEB128(Summary->getMaxFunctionCount(), OS);
|
2016-05-19 23:53:28 +02:00
|
|
|
encodeULEB128(Summary->getNumCounts(), OS);
|
2016-02-19 04:15:33 +01:00
|
|
|
encodeULEB128(Summary->getNumFunctions(), OS);
|
|
|
|
std::vector<ProfileSummaryEntry> &Entries = Summary->getDetailedSummary();
|
|
|
|
encodeULEB128(Entries.size(), OS);
|
|
|
|
for (auto Entry : Entries) {
|
|
|
|
encodeULEB128(Entry.Cutoff, OS);
|
|
|
|
encodeULEB128(Entry.MinCount, OS);
|
|
|
|
encodeULEB128(Entry.NumCounts, OS);
|
|
|
|
}
|
|
|
|
return sampleprof_error::success;
|
|
|
|
}
|
2016-03-03 19:09:32 +01:00
|
|
|
std::error_code SampleProfileWriterBinary::writeBody(const FunctionSamples &S) {
|
2015-12-10 18:21:42 +01:00
|
|
|
auto &OS = *OutputStream;
|
|
|
|
|
2016-03-03 19:09:32 +01:00
|
|
|
if (std::error_code EC = writeNameIdx(S.getName()))
|
2015-10-14 00:48:46 +02:00
|
|
|
return EC;
|
|
|
|
|
2014-10-30 19:00:06 +01:00
|
|
|
encodeULEB128(S.getTotalSamples(), OS);
|
2015-10-09 19:54:24 +02:00
|
|
|
|
|
|
|
// Emit all the body samples.
|
2015-10-16 20:54:35 +02:00
|
|
|
encodeULEB128(S.getBodySamples().size(), OS);
|
2014-11-01 01:56:55 +01:00
|
|
|
for (const auto &I : S.getBodySamples()) {
|
|
|
|
LineLocation Loc = I.first;
|
|
|
|
const SampleRecord &Sample = I.second;
|
2014-10-30 19:00:06 +01:00
|
|
|
encodeULEB128(Loc.LineOffset, OS);
|
|
|
|
encodeULEB128(Loc.Discriminator, OS);
|
|
|
|
encodeULEB128(Sample.getSamples(), OS);
|
|
|
|
encodeULEB128(Sample.getCallTargets().size(), OS);
|
2014-11-01 01:56:55 +01:00
|
|
|
for (const auto &J : Sample.getCallTargets()) {
|
2015-10-14 00:48:46 +02:00
|
|
|
StringRef Callee = J.first();
|
2015-10-15 18:36:21 +02:00
|
|
|
uint64_t CalleeSamples = J.second;
|
2015-10-14 00:48:46 +02:00
|
|
|
if (std::error_code EC = writeNameIdx(Callee))
|
|
|
|
return EC;
|
2014-10-30 19:00:06 +01:00
|
|
|
encodeULEB128(CalleeSamples, OS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-09 19:54:24 +02:00
|
|
|
// Recursively emit all the callsite samples.
|
2017-08-03 02:09:18 +02:00
|
|
|
uint64_t NumCallsites = 0;
|
|
|
|
for (const auto &J : S.getCallsiteSamples())
|
|
|
|
NumCallsites += J.second.size();
|
|
|
|
encodeULEB128(NumCallsites, OS);
|
2017-04-13 21:52:10 +02:00
|
|
|
for (const auto &J : S.getCallsiteSamples())
|
|
|
|
for (const auto &FS : J.second) {
|
|
|
|
LineLocation Loc = J.first;
|
|
|
|
const FunctionSamples &CalleeSamples = FS.second;
|
|
|
|
encodeULEB128(Loc.LineOffset, OS);
|
|
|
|
encodeULEB128(Loc.Discriminator, OS);
|
|
|
|
if (std::error_code EC = writeBody(CalleeSamples))
|
|
|
|
return EC;
|
|
|
|
}
|
2015-10-09 19:54:24 +02:00
|
|
|
|
2015-10-14 00:48:46 +02:00
|
|
|
return sampleprof_error::success;
|
2014-10-30 19:00:06 +01:00
|
|
|
}
|
2014-11-01 01:56:55 +01:00
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Write samples of a top-level function to a binary file.
|
2015-10-16 20:54:35 +02:00
|
|
|
///
|
|
|
|
/// \returns true if the samples were written successfully, false otherwise.
|
2016-03-03 19:09:32 +01:00
|
|
|
std::error_code SampleProfileWriterBinary::write(const FunctionSamples &S) {
|
2015-12-10 18:21:42 +01:00
|
|
|
encodeULEB128(S.getHeadSamples(), *OutputStream);
|
2018-09-14 22:52:59 +02:00
|
|
|
return writeBody(S);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::error_code
|
|
|
|
SampleProfileWriterCompactBinary::write(const FunctionSamples &S) {
|
|
|
|
uint64_t Offset = OutputStream->tell();
|
|
|
|
StringRef Name = S.getName();
|
|
|
|
FuncOffsetTable[Name] = Offset;
|
|
|
|
encodeULEB128(S.getHeadSamples(), *OutputStream);
|
2016-03-03 19:09:32 +01:00
|
|
|
return writeBody(S);
|
2015-10-16 20:54:35 +02:00
|
|
|
}
|
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Create a sample profile file writer based on the specified format.
|
2014-11-01 01:56:55 +01:00
|
|
|
///
|
|
|
|
/// \param Filename The file to create.
|
|
|
|
///
|
|
|
|
/// \param Format Encoding format for the profile file.
|
|
|
|
///
|
|
|
|
/// \returns an error code indicating the status of the created writer.
|
2014-11-03 01:51:45 +01:00
|
|
|
ErrorOr<std::unique_ptr<SampleProfileWriter>>
|
|
|
|
SampleProfileWriter::create(StringRef Filename, SampleProfileFormat Format) {
|
2014-11-01 01:56:55 +01:00
|
|
|
std::error_code EC;
|
2015-12-10 18:21:42 +01:00
|
|
|
std::unique_ptr<raw_ostream> OS;
|
2018-06-12 07:53:49 +02:00
|
|
|
if (Format == SPF_Binary || Format == SPF_Compact_Binary)
|
2015-12-10 18:21:42 +01:00
|
|
|
OS.reset(new raw_fd_ostream(Filename, EC, sys::fs::F_None));
|
|
|
|
else
|
|
|
|
OS.reset(new raw_fd_ostream(Filename, EC, sys::fs::F_Text));
|
|
|
|
if (EC)
|
|
|
|
return EC;
|
|
|
|
|
|
|
|
return create(OS, Format);
|
|
|
|
}
|
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Create a sample profile stream writer based on the specified format.
|
2015-12-10 18:21:42 +01:00
|
|
|
///
|
|
|
|
/// \param OS The output stream to store the profile data to.
|
|
|
|
///
|
|
|
|
/// \param Format Encoding format for the profile file.
|
|
|
|
///
|
|
|
|
/// \returns an error code indicating the status of the created writer.
|
|
|
|
ErrorOr<std::unique_ptr<SampleProfileWriter>>
|
|
|
|
SampleProfileWriter::create(std::unique_ptr<raw_ostream> &OS,
|
|
|
|
SampleProfileFormat Format) {
|
|
|
|
std::error_code EC;
|
2014-11-03 01:51:45 +01:00
|
|
|
std::unique_ptr<SampleProfileWriter> Writer;
|
2014-11-01 01:56:55 +01:00
|
|
|
|
2018-06-12 07:53:49 +02:00
|
|
|
if (Format == SPF_Binary)
|
2018-06-12 00:40:43 +02:00
|
|
|
Writer.reset(new SampleProfileWriterRawBinary(OS));
|
|
|
|
else if (Format == SPF_Compact_Binary)
|
|
|
|
Writer.reset(new SampleProfileWriterCompactBinary(OS));
|
2014-11-01 01:56:55 +01:00
|
|
|
else if (Format == SPF_Text)
|
2015-12-10 18:21:42 +01:00
|
|
|
Writer.reset(new SampleProfileWriterText(OS));
|
2015-10-14 00:48:46 +02:00
|
|
|
else if (Format == SPF_GCC)
|
|
|
|
EC = sampleprof_error::unsupported_writing_format;
|
2014-11-01 01:56:55 +01:00
|
|
|
else
|
|
|
|
EC = sampleprof_error::unrecognized_format;
|
|
|
|
|
2014-11-03 01:51:45 +01:00
|
|
|
if (EC)
|
|
|
|
return EC;
|
|
|
|
|
|
|
|
return std::move(Writer);
|
2014-11-01 01:56:55 +01:00
|
|
|
}
|
2016-02-19 04:15:33 +01:00
|
|
|
|
|
|
|
void SampleProfileWriter::computeSummary(
|
|
|
|
const StringMap<FunctionSamples> &ProfileMap) {
|
2016-05-19 23:07:12 +02:00
|
|
|
SampleProfileSummaryBuilder Builder(ProfileSummaryBuilder::DefaultCutoffs);
|
2016-02-19 04:15:33 +01:00
|
|
|
for (const auto &I : ProfileMap) {
|
|
|
|
const FunctionSamples &Profile = I.second;
|
2016-05-19 23:07:12 +02:00
|
|
|
Builder.addRecord(Profile);
|
2016-02-19 04:15:33 +01:00
|
|
|
}
|
2016-05-20 11:18:37 +02:00
|
|
|
Summary = Builder.getSummary();
|
2016-02-19 04:15:33 +01:00
|
|
|
}
|