blob: 3a5b266016c6228c31d98a68903f99c4d89879e3 [file] [log] [blame]
Justin Bognerf8d79192014-03-21 17:24:48 +00001//=-- InstrProfReader.cpp - Instrumented profiling reader -------------------=//
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 contains support for reading profiling data for clang's
11// instrumentation based PGO and coverage.
12//
13//===----------------------------------------------------------------------===//
14
15#include "llvm/ProfileData/InstrProfReader.h"
Justin Bognerb7aa2632014-04-18 21:48:40 +000016#include "InstrProfIndexed.h"
Benjamin Kramer0a446fd2015-03-01 21:28:53 +000017#include "llvm/ADT/STLExtras.h"
Chandler Carruthd9903882015-01-14 11:23:27 +000018#include "llvm/ProfileData/InstrProf.h"
Justin Bognerf8d79192014-03-21 17:24:48 +000019#include <cassert>
20
21using namespace llvm;
22
Diego Novillofcd55602014-11-03 00:51:45 +000023static ErrorOr<std::unique_ptr<MemoryBuffer>>
24setupMemoryBuffer(std::string Path) {
Rafael Espindolaadf21f22014-07-06 17:43:13 +000025 ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr =
26 MemoryBuffer::getFileOrSTDIN(Path);
27 if (std::error_code EC = BufferOrErr.getError())
Justin Bognerf8d79192014-03-21 17:24:48 +000028 return EC;
Justin Bogner2b6c5372015-02-18 01:58:17 +000029 return std::move(BufferOrErr.get());
Justin Bognerb7aa2632014-04-18 21:48:40 +000030}
31
Rafael Espindoladb4ed0b2014-06-13 02:24:39 +000032static std::error_code initializeReader(InstrProfReader &Reader) {
Justin Bognerb7aa2632014-04-18 21:48:40 +000033 return Reader.readHeader();
34}
35
Diego Novillofcd55602014-11-03 00:51:45 +000036ErrorOr<std::unique_ptr<InstrProfReader>>
37InstrProfReader::create(std::string Path) {
Justin Bognerb7aa2632014-04-18 21:48:40 +000038 // Set up the buffer to read.
Diego Novillofcd55602014-11-03 00:51:45 +000039 auto BufferOrError = setupMemoryBuffer(Path);
40 if (std::error_code EC = BufferOrError.getError())
Justin Bognerb7aa2632014-04-18 21:48:40 +000041 return EC;
Justin Bogner2b6c5372015-02-18 01:58:17 +000042 return InstrProfReader::create(std::move(BufferOrError.get()));
43}
Justin Bognerf8d79192014-03-21 17:24:48 +000044
Justin Bogner2b6c5372015-02-18 01:58:17 +000045ErrorOr<std::unique_ptr<InstrProfReader>>
46InstrProfReader::create(std::unique_ptr<MemoryBuffer> Buffer) {
47 // Sanity check the buffer.
48 if (Buffer->getBufferSize() > std::numeric_limits<unsigned>::max())
49 return instrprof_error::too_large;
50
Diego Novillofcd55602014-11-03 00:51:45 +000051 std::unique_ptr<InstrProfReader> Result;
Duncan P. N. Exon Smith09a67f42014-03-21 20:42:31 +000052 // Create the reader.
Justin Bognerb7aa2632014-04-18 21:48:40 +000053 if (IndexedInstrProfReader::hasFormat(*Buffer))
54 Result.reset(new IndexedInstrProfReader(std::move(Buffer)));
55 else if (RawInstrProfReader64::hasFormat(*Buffer))
Duncan P. N. Exon Smith46803612014-03-23 03:38:12 +000056 Result.reset(new RawInstrProfReader64(std::move(Buffer)));
57 else if (RawInstrProfReader32::hasFormat(*Buffer))
58 Result.reset(new RawInstrProfReader32(std::move(Buffer)));
Duncan P. N. Exon Smith24b4b652014-03-21 18:26:05 +000059 else
Duncan P. N. Exon Smith4c5b7cb2014-03-21 20:42:34 +000060 Result.reset(new TextInstrProfReader(std::move(Buffer)));
Duncan P. N. Exon Smith09a67f42014-03-21 20:42:31 +000061
Justin Bognerb7aa2632014-04-18 21:48:40 +000062 // Initialize the reader and return the result.
Diego Novillofcd55602014-11-03 00:51:45 +000063 if (std::error_code EC = initializeReader(*Result))
64 return EC;
65
66 return std::move(Result);
Justin Bognerb7aa2632014-04-18 21:48:40 +000067}
68
Justin Bognerab89ed72015-02-16 21:28:58 +000069ErrorOr<std::unique_ptr<IndexedInstrProfReader>>
70IndexedInstrProfReader::create(std::string Path) {
Justin Bognerb7aa2632014-04-18 21:48:40 +000071 // Set up the buffer to read.
Diego Novillofcd55602014-11-03 00:51:45 +000072 auto BufferOrError = setupMemoryBuffer(Path);
73 if (std::error_code EC = BufferOrError.getError())
Justin Bognerb7aa2632014-04-18 21:48:40 +000074 return EC;
Justin Bogner2b6c5372015-02-18 01:58:17 +000075 return IndexedInstrProfReader::create(std::move(BufferOrError.get()));
76}
Justin Bognerb7aa2632014-04-18 21:48:40 +000077
Justin Bogner2b6c5372015-02-18 01:58:17 +000078
79ErrorOr<std::unique_ptr<IndexedInstrProfReader>>
80IndexedInstrProfReader::create(std::unique_ptr<MemoryBuffer> Buffer) {
81 // Sanity check the buffer.
82 if (Buffer->getBufferSize() > std::numeric_limits<unsigned>::max())
83 return instrprof_error::too_large;
Justin Bognerab89ed72015-02-16 21:28:58 +000084
Justin Bognerb7aa2632014-04-18 21:48:40 +000085 // Create the reader.
86 if (!IndexedInstrProfReader::hasFormat(*Buffer))
87 return instrprof_error::bad_magic;
Justin Bogner2b6c5372015-02-18 01:58:17 +000088 auto Result = llvm::make_unique<IndexedInstrProfReader>(std::move(Buffer));
Justin Bognerb7aa2632014-04-18 21:48:40 +000089
90 // Initialize the reader and return the result.
Justin Bognerab89ed72015-02-16 21:28:58 +000091 if (std::error_code EC = initializeReader(*Result))
92 return EC;
93
94 return std::move(Result);
Justin Bognerf8d79192014-03-21 17:24:48 +000095}
96
97void InstrProfIterator::Increment() {
98 if (Reader->readNextRecord(Record))
99 *this = InstrProfIterator();
100}
101
Rafael Espindoladb4ed0b2014-06-13 02:24:39 +0000102std::error_code TextInstrProfReader::readNextRecord(InstrProfRecord &Record) {
Justin Bognercf36a362014-07-29 22:29:23 +0000103 // Skip empty lines and comments.
104 while (!Line.is_at_end() && (Line->empty() || Line->startswith("#")))
Justin Bognerf8d79192014-03-21 17:24:48 +0000105 ++Line;
106 // If we hit EOF while looking for a name, we're done.
107 if (Line.is_at_end())
108 return error(instrprof_error::eof);
109
110 // Read the function name.
111 Record.Name = *Line++;
112
113 // Read the function hash.
114 if (Line.is_at_end())
115 return error(instrprof_error::truncated);
Justin Bognerf95ca072015-03-09 18:54:49 +0000116 if ((Line++)->getAsInteger(0, Record.Hash))
Justin Bognerf8d79192014-03-21 17:24:48 +0000117 return error(instrprof_error::malformed);
118
119 // Read the number of counters.
120 uint64_t NumCounters;
121 if (Line.is_at_end())
122 return error(instrprof_error::truncated);
123 if ((Line++)->getAsInteger(10, NumCounters))
124 return error(instrprof_error::malformed);
Justin Bognerb59d7c72014-04-25 02:45:33 +0000125 if (NumCounters == 0)
126 return error(instrprof_error::malformed);
Justin Bognerf8d79192014-03-21 17:24:48 +0000127
128 // Read each counter and fill our internal storage with the values.
129 Counts.clear();
130 Counts.reserve(NumCounters);
131 for (uint64_t I = 0; I < NumCounters; ++I) {
132 if (Line.is_at_end())
133 return error(instrprof_error::truncated);
134 uint64_t Count;
135 if ((Line++)->getAsInteger(10, Count))
136 return error(instrprof_error::malformed);
137 Counts.push_back(Count);
138 }
139 // Give the record a reference to our internal counter storage.
140 Record.Counts = Counts;
141
142 return success();
143}
Duncan P. N. Exon Smith24b4b652014-03-21 18:26:05 +0000144
Duncan P. N. Exon Smith46803612014-03-23 03:38:12 +0000145template <class IntPtrT>
146static uint64_t getRawMagic();
147
148template <>
149uint64_t getRawMagic<uint64_t>() {
Duncan P. N. Exon Smith09a67f42014-03-21 20:42:31 +0000150 return
Duncan P. N. Exon Smith745a2bf2014-03-21 20:42:37 +0000151 uint64_t(255) << 56 |
152 uint64_t('l') << 48 |
153 uint64_t('p') << 40 |
154 uint64_t('r') << 32 |
155 uint64_t('o') << 24 |
156 uint64_t('f') << 16 |
157 uint64_t('r') << 8 |
158 uint64_t(129);
Duncan P. N. Exon Smith09a67f42014-03-21 20:42:31 +0000159}
160
Duncan P. N. Exon Smith46803612014-03-23 03:38:12 +0000161template <>
162uint64_t getRawMagic<uint32_t>() {
163 return
164 uint64_t(255) << 56 |
165 uint64_t('l') << 48 |
166 uint64_t('p') << 40 |
167 uint64_t('r') << 32 |
168 uint64_t('o') << 24 |
169 uint64_t('f') << 16 |
170 uint64_t('R') << 8 |
171 uint64_t(129);
Duncan P. N. Exon Smith09a67f42014-03-21 20:42:31 +0000172}
173
Duncan P. N. Exon Smith46803612014-03-23 03:38:12 +0000174template <class IntPtrT>
175bool RawInstrProfReader<IntPtrT>::hasFormat(const MemoryBuffer &DataBuffer) {
Duncan P. N. Exon Smithd7d83472014-03-24 00:47:18 +0000176 if (DataBuffer.getBufferSize() < sizeof(uint64_t))
Duncan P. N. Exon Smith46803612014-03-23 03:38:12 +0000177 return false;
Duncan P. N. Exon Smithd7d83472014-03-24 00:47:18 +0000178 uint64_t Magic =
179 *reinterpret_cast<const uint64_t *>(DataBuffer.getBufferStart());
180 return getRawMagic<IntPtrT>() == Magic ||
Artyom Skrobovef5e8672014-06-14 11:36:01 +0000181 sys::getSwappedBytes(getRawMagic<IntPtrT>()) == Magic;
Duncan P. N. Exon Smith46803612014-03-23 03:38:12 +0000182}
183
184template <class IntPtrT>
Rafael Espindoladb4ed0b2014-06-13 02:24:39 +0000185std::error_code RawInstrProfReader<IntPtrT>::readHeader() {
Duncan P. N. Exon Smith09a67f42014-03-21 20:42:31 +0000186 if (!hasFormat(*DataBuffer))
187 return error(instrprof_error::bad_magic);
Duncan P. N. Exon Smith24b4b652014-03-21 18:26:05 +0000188 if (DataBuffer->getBufferSize() < sizeof(RawHeader))
Duncan P. N. Exon Smith531bb482014-03-21 20:42:28 +0000189 return error(instrprof_error::bad_header);
Duncan P. N. Exon Smithd7d83472014-03-24 00:47:18 +0000190 auto *Header =
191 reinterpret_cast<const RawHeader *>(DataBuffer->getBufferStart());
Duncan P. N. Exon Smith46803612014-03-23 03:38:12 +0000192 ShouldSwapBytes = Header->Magic != getRawMagic<IntPtrT>();
Duncan P. N. Exon Smith24b4b652014-03-21 18:26:05 +0000193 return readHeader(*Header);
194}
195
Justin Bognera119f322014-05-16 00:38:00 +0000196template <class IntPtrT>
Rafael Espindoladb4ed0b2014-06-13 02:24:39 +0000197std::error_code
198RawInstrProfReader<IntPtrT>::readNextHeader(const char *CurrentPos) {
Justin Bognera119f322014-05-16 00:38:00 +0000199 const char *End = DataBuffer->getBufferEnd();
200 // Skip zero padding between profiles.
201 while (CurrentPos != End && *CurrentPos == 0)
202 ++CurrentPos;
203 // If there's nothing left, we're done.
204 if (CurrentPos == End)
205 return instrprof_error::eof;
206 // If there isn't enough space for another header, this is probably just
207 // garbage at the end of the file.
208 if (CurrentPos + sizeof(RawHeader) > End)
209 return instrprof_error::malformed;
Justin Bogner54b11282014-09-12 21:22:55 +0000210 // The writer ensures each profile is padded to start at an aligned address.
211 if (reinterpret_cast<size_t>(CurrentPos) % alignOf<uint64_t>())
212 return instrprof_error::malformed;
Justin Bognera119f322014-05-16 00:38:00 +0000213 // The magic should have the same byte order as in the previous header.
214 uint64_t Magic = *reinterpret_cast<const uint64_t *>(CurrentPos);
215 if (Magic != swap(getRawMagic<IntPtrT>()))
216 return instrprof_error::bad_magic;
217
218 // There's another profile to read, so we need to process the header.
219 auto *Header = reinterpret_cast<const RawHeader *>(CurrentPos);
220 return readHeader(*Header);
221}
222
Duncan P. N. Exon Smith09a67f42014-03-21 20:42:31 +0000223static uint64_t getRawVersion() {
224 return 1;
225}
226
Duncan P. N. Exon Smith46803612014-03-23 03:38:12 +0000227template <class IntPtrT>
Rafael Espindoladb4ed0b2014-06-13 02:24:39 +0000228std::error_code
229RawInstrProfReader<IntPtrT>::readHeader(const RawHeader &Header) {
Duncan P. N. Exon Smith24b4b652014-03-21 18:26:05 +0000230 if (swap(Header.Version) != getRawVersion())
231 return error(instrprof_error::unsupported_version);
232
233 CountersDelta = swap(Header.CountersDelta);
234 NamesDelta = swap(Header.NamesDelta);
235 auto DataSize = swap(Header.DataSize);
236 auto CountersSize = swap(Header.CountersSize);
237 auto NamesSize = swap(Header.NamesSize);
238
239 ptrdiff_t DataOffset = sizeof(RawHeader);
240 ptrdiff_t CountersOffset = DataOffset + sizeof(ProfileData) * DataSize;
241 ptrdiff_t NamesOffset = CountersOffset + sizeof(uint64_t) * CountersSize;
Justin Bognera119f322014-05-16 00:38:00 +0000242 size_t ProfileSize = NamesOffset + sizeof(char) * NamesSize;
Duncan P. N. Exon Smith24b4b652014-03-21 18:26:05 +0000243
Justin Bognera119f322014-05-16 00:38:00 +0000244 auto *Start = reinterpret_cast<const char *>(&Header);
245 if (Start + ProfileSize > DataBuffer->getBufferEnd())
Duncan P. N. Exon Smith531bb482014-03-21 20:42:28 +0000246 return error(instrprof_error::bad_header);
Duncan P. N. Exon Smith24b4b652014-03-21 18:26:05 +0000247
Duncan P. N. Exon Smithd7d83472014-03-24 00:47:18 +0000248 Data = reinterpret_cast<const ProfileData *>(Start + DataOffset);
Duncan P. N. Exon Smith24b4b652014-03-21 18:26:05 +0000249 DataEnd = Data + DataSize;
Duncan P. N. Exon Smithd7d83472014-03-24 00:47:18 +0000250 CountersStart = reinterpret_cast<const uint64_t *>(Start + CountersOffset);
251 NamesStart = Start + NamesOffset;
Justin Bognera119f322014-05-16 00:38:00 +0000252 ProfileEnd = Start + ProfileSize;
Duncan P. N. Exon Smith24b4b652014-03-21 18:26:05 +0000253
254 return success();
255}
256
Duncan P. N. Exon Smith46803612014-03-23 03:38:12 +0000257template <class IntPtrT>
Rafael Espindoladb4ed0b2014-06-13 02:24:39 +0000258std::error_code
Duncan P. N. Exon Smith46803612014-03-23 03:38:12 +0000259RawInstrProfReader<IntPtrT>::readNextRecord(InstrProfRecord &Record) {
Duncan P. N. Exon Smith24b4b652014-03-21 18:26:05 +0000260 if (Data == DataEnd)
Rafael Espindoladb4ed0b2014-06-13 02:24:39 +0000261 if (std::error_code EC = readNextHeader(ProfileEnd))
Justin Bognera119f322014-05-16 00:38:00 +0000262 return EC;
Duncan P. N. Exon Smith24b4b652014-03-21 18:26:05 +0000263
264 // Get the raw data.
265 StringRef RawName(getName(Data->NamePtr), swap(Data->NameSize));
Justin Bognerb59d7c72014-04-25 02:45:33 +0000266 uint32_t NumCounters = swap(Data->NumCounters);
267 if (NumCounters == 0)
268 return error(instrprof_error::malformed);
269 auto RawCounts = makeArrayRef(getCounter(Data->CounterPtr), NumCounters);
Duncan P. N. Exon Smith24b4b652014-03-21 18:26:05 +0000270
271 // Check bounds.
Duncan P. N. Exon Smithd7d83472014-03-24 00:47:18 +0000272 auto *NamesStartAsCounter = reinterpret_cast<const uint64_t *>(NamesStart);
Duncan P. N. Exon Smith24b4b652014-03-21 18:26:05 +0000273 if (RawName.data() < NamesStart ||
274 RawName.data() + RawName.size() > DataBuffer->getBufferEnd() ||
275 RawCounts.data() < CountersStart ||
Duncan P. N. Exon Smithd7d83472014-03-24 00:47:18 +0000276 RawCounts.data() + RawCounts.size() > NamesStartAsCounter)
Duncan P. N. Exon Smith24b4b652014-03-21 18:26:05 +0000277 return error(instrprof_error::malformed);
278
279 // Store the data in Record, byte-swapping as necessary.
280 Record.Hash = swap(Data->FuncHash);
281 Record.Name = RawName;
282 if (ShouldSwapBytes) {
283 Counts.clear();
284 Counts.reserve(RawCounts.size());
285 for (uint64_t Count : RawCounts)
286 Counts.push_back(swap(Count));
287 Record.Counts = Counts;
288 } else
289 Record.Counts = RawCounts;
290
291 // Iterate.
292 ++Data;
293 return success();
294}
Duncan P. N. Exon Smith46803612014-03-23 03:38:12 +0000295
296namespace llvm {
297template class RawInstrProfReader<uint32_t>;
298template class RawInstrProfReader<uint64_t>;
299}
Justin Bognerb7aa2632014-04-18 21:48:40 +0000300
Justin Bognerb5d368e2014-04-18 22:00:22 +0000301InstrProfLookupTrait::hash_value_type
302InstrProfLookupTrait::ComputeHash(StringRef K) {
303 return IndexedInstrProf::ComputeHash(HashType, K);
304}
305
Justin Bognerb7aa2632014-04-18 21:48:40 +0000306bool IndexedInstrProfReader::hasFormat(const MemoryBuffer &DataBuffer) {
307 if (DataBuffer.getBufferSize() < 8)
308 return false;
309 using namespace support;
310 uint64_t Magic =
311 endian::read<uint64_t, little, aligned>(DataBuffer.getBufferStart());
312 return Magic == IndexedInstrProf::Magic;
313}
314
Rafael Espindoladb4ed0b2014-06-13 02:24:39 +0000315std::error_code IndexedInstrProfReader::readHeader() {
Aaron Ballmana7c9ed52014-05-01 17:16:24 +0000316 const unsigned char *Start =
317 (const unsigned char *)DataBuffer->getBufferStart();
Justin Bognerb7aa2632014-04-18 21:48:40 +0000318 const unsigned char *Cur = Start;
Aaron Ballmana7c9ed52014-05-01 17:16:24 +0000319 if ((const unsigned char *)DataBuffer->getBufferEnd() - Cur < 24)
Justin Bognerb7aa2632014-04-18 21:48:40 +0000320 return error(instrprof_error::truncated);
321
322 using namespace support;
323
324 // Check the magic number.
325 uint64_t Magic = endian::readNext<uint64_t, little, unaligned>(Cur);
326 if (Magic != IndexedInstrProf::Magic)
327 return error(instrprof_error::bad_magic);
328
329 // Read the version.
Justin Bogner821d7472014-08-01 22:50:07 +0000330 FormatVersion = endian::readNext<uint64_t, little, unaligned>(Cur);
331 if (FormatVersion > IndexedInstrProf::Version)
Justin Bognerb7aa2632014-04-18 21:48:40 +0000332 return error(instrprof_error::unsupported_version);
333
334 // Read the maximal function count.
335 MaxFunctionCount = endian::readNext<uint64_t, little, unaligned>(Cur);
336
337 // Read the hash type and start offset.
338 IndexedInstrProf::HashT HashType = static_cast<IndexedInstrProf::HashT>(
339 endian::readNext<uint64_t, little, unaligned>(Cur));
340 if (HashType > IndexedInstrProf::HashT::Last)
341 return error(instrprof_error::unsupported_hash_type);
342 uint64_t HashOffset = endian::readNext<uint64_t, little, unaligned>(Cur);
343
344 // The rest of the file is an on disk hash table.
345 Index.reset(InstrProfReaderIndex::Create(Start + HashOffset, Cur, Start,
346 InstrProfLookupTrait(HashType)));
347 // Set up our iterator for readNextRecord.
348 RecordIterator = Index->data_begin();
349
350 return success();
351}
352
Rafael Espindoladb4ed0b2014-06-13 02:24:39 +0000353std::error_code IndexedInstrProfReader::getFunctionCounts(
Justin Bogner821d7472014-08-01 22:50:07 +0000354 StringRef FuncName, uint64_t FuncHash, std::vector<uint64_t> &Counts) {
355 auto Iter = Index->find(FuncName);
Justin Bognerb7aa2632014-04-18 21:48:40 +0000356 if (Iter == Index->end())
357 return error(instrprof_error::unknown_function);
358
Justin Bogner821d7472014-08-01 22:50:07 +0000359 // Found it. Look for counters with the right hash.
360 ArrayRef<uint64_t> Data = (*Iter).Data;
361 uint64_t NumCounts;
362 for (uint64_t I = 0, E = Data.size(); I != E; I += NumCounts) {
363 // The function hash comes first.
364 uint64_t FoundHash = Data[I++];
365 // In v1, we have at least one count. Later, we have the number of counts.
366 if (I == E)
367 return error(instrprof_error::malformed);
368 NumCounts = FormatVersion == 1 ? E - I : Data[I++];
369 // If we have more counts than data, this is bogus.
370 if (I + NumCounts > E)
371 return error(instrprof_error::malformed);
372 // Check for a match and fill the vector if there is one.
373 if (FoundHash == FuncHash) {
374 Counts = Data.slice(I, NumCounts);
375 return success();
376 }
377 }
378 return error(instrprof_error::hash_mismatch);
Justin Bognerb7aa2632014-04-18 21:48:40 +0000379}
380
Rafael Espindoladb4ed0b2014-06-13 02:24:39 +0000381std::error_code
382IndexedInstrProfReader::readNextRecord(InstrProfRecord &Record) {
Justin Bognerb7aa2632014-04-18 21:48:40 +0000383 // Are we out of records?
384 if (RecordIterator == Index->data_end())
385 return error(instrprof_error::eof);
386
Justin Bogner821d7472014-08-01 22:50:07 +0000387 // Record the current function name.
388 Record.Name = (*RecordIterator).Name;
389
390 ArrayRef<uint64_t> Data = (*RecordIterator).Data;
391 // Valid data starts with a hash and either a count or the number of counts.
392 if (CurrentOffset + 1 > Data.size())
Justin Bognerb7aa2632014-04-18 21:48:40 +0000393 return error(instrprof_error::malformed);
Justin Bogner821d7472014-08-01 22:50:07 +0000394 // First we have a function hash.
395 Record.Hash = Data[CurrentOffset++];
396 // In version 1 we knew the number of counters implicitly, but in newer
397 // versions we store the number of counters next.
398 uint64_t NumCounts =
399 FormatVersion == 1 ? Data.size() - CurrentOffset : Data[CurrentOffset++];
400 if (CurrentOffset + NumCounts > Data.size())
401 return error(instrprof_error::malformed);
402 // And finally the counts themselves.
403 Record.Counts = Data.slice(CurrentOffset, NumCounts);
404
405 // If we've exhausted this function's data, increment the record.
406 CurrentOffset += NumCounts;
407 if (CurrentOffset == Data.size()) {
408 ++RecordIterator;
409 CurrentOffset = 0;
410 }
411
Justin Bognerb7aa2632014-04-18 21:48:40 +0000412 return success();
413}