Lines Matching +full:block +full:- +full:offset
1 //===- Profile.cpp - XRay Profile Abstraction -----------------------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
12 //===----------------------------------------------------------------------===//
26 // We need to re-create all the tries from the original (O), into the current
27 // Profile being initialized, through the Block instances we see.
28 for (const auto &Block : O) {
29 Blocks.push_back({Block.Thread, {}});
31 for (const auto &PathData : Block.PathData)
52 uint64_t &Offset) {
54 uint64_t CurrentOffset = Offset;
55 H.Size = Extractor.getU32(&Offset);
56 if (Offset == CurrentOffset)
58 Twine("Error parsing block header size at offset '") +
61 CurrentOffset = Offset;
62 H.Number = Extractor.getU32(&Offset);
63 if (Offset == CurrentOffset)
65 Twine("Error parsing block header number at offset '") +
68 CurrentOffset = Offset;
69 H.Thread = Extractor.getU64(&Offset);
70 if (Offset == CurrentOffset)
72 Twine("Error parsing block header thread id at offset '") +
79 uint64_t &Offset) {
82 auto CurrentOffset = Offset;
85 FuncId = Extractor.getSigned(&Offset, 4);
86 if (CurrentOffset == Offset)
88 Twine("Error parsing path at offset '") + Twine(CurrentOffset) + "'",
90 CurrentOffset = Offset;
97 uint64_t &Offset) {
99 // - A 64-bit CallCount
100 // - A 64-bit CumulativeLocalTime counter
102 auto CurrentOffset = Offset;
103 D.CallCount = Extractor.getU64(&Offset);
104 if (CurrentOffset == Offset)
106 Twine("Error parsing call counts at offset '") + Twine(CurrentOffset) +
109 CurrentOffset = Offset;
110 D.CumulativeLocalTime = Extractor.getU64(&Offset);
111 if (CurrentOffset == Offset)
113 Twine("Error parsing cumulative local time at offset '") +
121 Error Profile::addBlock(Block &&B) {
124 "Block may not have empty path data.",
138 for (auto Node = It->second; Node; Node = Node->Caller)
139 Path.push_back(Node->Func);
153 find_if(Roots, [PathRoot](TrieNode *N) { return N->Func == PathRoot; });
160 Node->Func = PathRoot;
166 // Now traverse the path, re-creating if necessary.
169 auto CalleeIt = find_if(Node->Callees, [NodeFuncID](TrieNode *N) {
170 return N->Func == NodeFuncID;
172 if (CalleeIt == Node->Callees.end()) {
175 NewNode->Func = NodeFuncID;
176 NewNode->Caller = Node;
177 Node->Callees.push_back(NewNode);
185 assert(Node->Func == P.front());
186 if (Node->ID == 0) {
187 Node->ID = NextID++;
188 PathIDMap.insert({Node->ID, Node});
190 return Node->ID;
197 using PathDataVector = decltype(Profile::Block::PathData);
202 for (const auto &Block : P.get()) {
205 {Block.Thread, std::make_unique<PathDataMap>()});
206 for (const auto &PathAndData : Block.PathData) {
213 std::tie(PathDataIt, Inserted) = It->second->insert({NewPathID, Data});
215 auto &ExistingData = PathDataIt->second;
224 PathAndData.reserve(IndexedThreadBlock.second->size());
236 using PathDataVector = decltype(Profile::Block::PathData);
238 for (const auto &Block : P.get())
239 for (const auto &PathAndData : Block.PathData) {
248 auto &ExistingData = PathDataIt->second;
254 // In the end there's a single Block, for thread 0.
255 PathDataVector Block;
256 Block.reserve(PathData.size());
257 copy(PathData, std::back_inserter(Block));
258 cantFail(Merged.addBlock({0, std::move(Block)}));
283 uint64_t Offset = 0;
286 // For each block we get from the file:
287 while (Offset != MappedFile.size()) {
288 auto HeaderOrError = readBlockHeader(Extractor, Offset);
292 // TODO: Maybe store this header information for each block, even just for
297 auto PathOrError = readPath(Extractor, Offset);
303 auto DataOrError = readData(Extractor, Offset);
309 P.addBlock(Profile::Block{Profile::ThreadID{Header.Thread},
329 // The implementation of the algorithm re-creates the execution of
337 // We then do a pass through the Trace to account data on a per-thread-basis.
386 // Once we've gone through the Trace, we now create one Block per thread in