MCPcopy Create free account
hub / github.com/PlatformLab/NanoLog / readBufferExtent

Method readBufferExtent

runtime/Log.cc:1181–1226  ·  view source on GitHub ↗

* Read in the next buffer fragment from the compressed log. If an error occurs * the file descriptor will be in an undefined state. * * \param fd * File stream to read it from * \param[out] wrapAround * Indicates whether a wrap around was indicated in the log or not. * * \return * indicates whether the operation succeeded (true) or failed due to * a malformed log data

Source from the content-addressed store, hash-verified

1179 * a malformed log data.
1180 */
1181bool
1182Log::Decoder::BufferFragment::readBufferExtent(FILE *fd, bool *wrapAround) {
1183 validBytes = fread(storage, 1, sizeof(BufferExtent), fd);
1184 BufferExtent *be = reinterpret_cast<BufferExtent*>(storage);
1185
1186 if (be->entryType != EntryType::BUFFER_EXTENT ||
1187 validBytes < sizeof(BufferExtent) ||
1188 be->length > sizeof(storage)) {
1189 reset();
1190 return false;
1191 }
1192
1193 assert(be->length >= validBytes);
1194 uint64_t remaining = be->length - validBytes;
1195 validBytes += fread(storage + validBytes, 1, remaining, fd);
1196
1197 if (validBytes != be->length) {
1198 reset();
1199 return false;
1200 }
1201
1202 readPos = storage + sizeof(BufferExtent);
1203 endOfBuffer = storage + validBytes;
1204
1205 if (be->isShort)
1206 runtimeId = be->threadIdOrPackNibble;
1207 else
1208 runtimeId = BufferUtils::unpack<uint32_t>(
1209 &readPos, be->threadIdOrPackNibble);
1210
1211 if (wrapAround)
1212 *wrapAround = be->wrapAround;
1213
1214 // The buffer has no log messages, skip it (this may be possible in cases
1215 // where we want to mark wrapArounds or the output buffer ran out of space).
1216 if (readPos == endOfBuffer) {
1217 hasMoreLogs = false;
1218 return true;
1219 }
1220
1221 hasMoreLogs = decompressLogHeader(&readPos, 0, nextLogId, nextLogTimestamp);
1222 if (!hasMoreLogs)
1223 reset();
1224
1225 return hasMoreLogs;
1226}
1227
1228/**
1229 * Helper to decompressNextLogStatement to print a single PrintFragment

Callers 4

decompressToMethod · 0.80
getNextLogStatementMethod · 0.80
TEST_FFunction · 0.80

Calls 1

decompressLogHeaderFunction · 0.85

Tested by 1

TEST_FFunction · 0.64