Please use GitHub pull requests for new patches. Avoid migrating existing patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
llvm/lib/XRay/Profile.cpp
Show All 23 Lines | |||||
Profile::Profile(const Profile &O) { | Profile::Profile(const Profile &O) { | ||||
// We need to re-create all the tries from the original (O), into the current | // We need to re-create all the tries from the original (O), into the current | ||||
// Profile being initialized, through the Block instances we see. | // Profile being initialized, through the Block instances we see. | ||||
for (const auto &Block : O) { | for (const auto &Block : O) { | ||||
Blocks.push_back({Block.Thread, {}}); | Blocks.push_back({Block.Thread, {}}); | ||||
auto &B = Blocks.back(); | auto &B = Blocks.back(); | ||||
for (const auto &PathData : Block.PathData) | for (const auto &PathData : Block.PathData) | ||||
B.PathData.push_back({internPath(cantFail(O.expandPath(PathData.first))), | B.PathData.push_back({internPath(llvm_cantFail(O.expandPath(PathData.first))), | ||||
PathData.second}); | PathData.second}); | ||||
} | } | ||||
} | } | ||||
Profile &Profile::operator=(const Profile &O) { | Profile &Profile::operator=(const Profile &O) { | ||||
Profile P = O; | Profile P = O; | ||||
*this = std::move(P); | *this = std::move(P); | ||||
return *this; | return *this; | ||||
▲ Show 20 Lines • Show All 161 Lines • ▼ Show 20 Lines | for (const auto &P : {std::ref(L), std::ref(R)}) | ||||
for (const auto &Block : P.get()) { | for (const auto &Block : P.get()) { | ||||
ThreadProfileIndexMap::iterator It; | ThreadProfileIndexMap::iterator It; | ||||
std::tie(It, std::ignore) = ThreadProfileIndex.insert( | std::tie(It, std::ignore) = ThreadProfileIndex.insert( | ||||
{Block.Thread, PathDataMapPtr{new PathDataMap()}}); | {Block.Thread, PathDataMapPtr{new PathDataMap()}}); | ||||
for (const auto &PathAndData : Block.PathData) { | for (const auto &PathAndData : Block.PathData) { | ||||
auto &PathID = PathAndData.first; | auto &PathID = PathAndData.first; | ||||
auto &Data = PathAndData.second; | auto &Data = PathAndData.second; | ||||
auto NewPathID = | auto NewPathID = | ||||
Merged.internPath(cantFail(P.get().expandPath(PathID))); | Merged.internPath(llvm_cantFail(P.get().expandPath(PathID))); | ||||
PathDataMap::iterator PathDataIt; | PathDataMap::iterator PathDataIt; | ||||
bool Inserted; | bool Inserted; | ||||
std::tie(PathDataIt, Inserted) = It->second->insert({NewPathID, Data}); | std::tie(PathDataIt, Inserted) = It->second->insert({NewPathID, Data}); | ||||
if (!Inserted) { | if (!Inserted) { | ||||
auto &ExistingData = PathDataIt->second; | auto &ExistingData = PathDataIt->second; | ||||
ExistingData.CallCount += Data.CallCount; | ExistingData.CallCount += Data.CallCount; | ||||
ExistingData.CumulativeLocalTime += Data.CumulativeLocalTime; | ExistingData.CumulativeLocalTime += Data.CumulativeLocalTime; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
for (const auto &IndexedThreadBlock : ThreadProfileIndex) { | for (const auto &IndexedThreadBlock : ThreadProfileIndex) { | ||||
PathDataVector PathAndData; | PathDataVector PathAndData; | ||||
PathAndData.reserve(IndexedThreadBlock.second->size()); | PathAndData.reserve(IndexedThreadBlock.second->size()); | ||||
copy(*IndexedThreadBlock.second, std::back_inserter(PathAndData)); | copy(*IndexedThreadBlock.second, std::back_inserter(PathAndData)); | ||||
cantFail( | llvm_cantFail( | ||||
Merged.addBlock({IndexedThreadBlock.first, std::move(PathAndData)})); | Merged.addBlock({IndexedThreadBlock.first, std::move(PathAndData)})); | ||||
} | } | ||||
return Merged; | return Merged; | ||||
} | } | ||||
Profile mergeProfilesByStack(const Profile &L, const Profile &R) { | Profile mergeProfilesByStack(const Profile &L, const Profile &R) { | ||||
Profile Merged; | Profile Merged; | ||||
using PathDataMap = DenseMap<Profile::PathID, Profile::Data>; | using PathDataMap = DenseMap<Profile::PathID, Profile::Data>; | ||||
PathDataMap PathData; | PathDataMap PathData; | ||||
using PathDataVector = decltype(Profile::Block::PathData); | using PathDataVector = decltype(Profile::Block::PathData); | ||||
for (const auto &P : {std::ref(L), std::ref(R)}) | for (const auto &P : {std::ref(L), std::ref(R)}) | ||||
for (const auto &Block : P.get()) | for (const auto &Block : P.get()) | ||||
for (const auto &PathAndData : Block.PathData) { | for (const auto &PathAndData : Block.PathData) { | ||||
auto &PathId = PathAndData.first; | auto &PathId = PathAndData.first; | ||||
auto &Data = PathAndData.second; | auto &Data = PathAndData.second; | ||||
auto NewPathID = | auto NewPathID = | ||||
Merged.internPath(cantFail(P.get().expandPath(PathId))); | Merged.internPath(llvm_cantFail(P.get().expandPath(PathId))); | ||||
PathDataMap::iterator PathDataIt; | PathDataMap::iterator PathDataIt; | ||||
bool Inserted; | bool Inserted; | ||||
std::tie(PathDataIt, Inserted) = PathData.insert({NewPathID, Data}); | std::tie(PathDataIt, Inserted) = PathData.insert({NewPathID, Data}); | ||||
if (!Inserted) { | if (!Inserted) { | ||||
auto &ExistingData = PathDataIt->second; | auto &ExistingData = PathDataIt->second; | ||||
ExistingData.CallCount += Data.CallCount; | ExistingData.CallCount += Data.CallCount; | ||||
ExistingData.CumulativeLocalTime += Data.CumulativeLocalTime; | ExistingData.CumulativeLocalTime += Data.CumulativeLocalTime; | ||||
} | } | ||||
} | } | ||||
// In the end there's a single Block, for thread 0. | // In the end there's a single Block, for thread 0. | ||||
PathDataVector Block; | PathDataVector Block; | ||||
Block.reserve(PathData.size()); | Block.reserve(PathData.size()); | ||||
copy(PathData, std::back_inserter(Block)); | copy(PathData, std::back_inserter(Block)); | ||||
cantFail(Merged.addBlock({0, std::move(Block)})); | llvm_cantFail(Merged.addBlock({0, std::move(Block)})); | ||||
return Merged; | return Merged; | ||||
} | } | ||||
Expected<Profile> loadProfile(StringRef Filename) { | Expected<Profile> loadProfile(StringRef Filename) { | ||||
Expected<sys::fs::file_t> FdOrErr = sys::fs::openNativeFileForRead(Filename); | Expected<sys::fs::file_t> FdOrErr = sys::fs::openNativeFileForRead(Filename); | ||||
if (!FdOrErr) | if (!FdOrErr) | ||||
return FdOrErr.takeError(); | return FdOrErr.takeError(); | ||||
▲ Show 20 Lines • Show All 137 Lines • Show Last 20 Lines |