* Interprets the uncompressed log messages (created by the compile-time * generated code) contained in the *from buffer and compresses them to * the internal buffer. The encoded data can later be retrieved via swapBuffer() * * \param from * A buffer containing the uncompressed log message created by the * compile-time generated code * \param nbytes * Maximum number of bytes
| 206 | * insufficient space in the internal buffer to fit the compressed message. |
| 207 | */ |
| 208 | long |
| 209 | Log::Encoder::encodeLogMsgs(char *from, |
| 210 | uint64_t nbytes, |
| 211 | uint32_t bufferId, |
| 212 | bool newPass, |
| 213 | uint64_t *numEventsCompressed) |
| 214 | { |
| 215 | if (!encodeBufferExtentStart(bufferId, newPass)) |
| 216 | return 0; |
| 217 | |
| 218 | uint64_t lastTimestamp = 0; |
| 219 | long remaining = nbytes; |
| 220 | long numEventsProcessed = 0; |
| 221 | char *bufferStart = writePos; |
| 222 | |
| 223 | while (remaining > 0) { |
| 224 | auto *entry = reinterpret_cast<UncompressedEntry*>(from); |
| 225 | |
| 226 | if (entry->entrySize > remaining) { |
| 227 | if (entry->entrySize < (NanoLogConfig::STAGING_BUFFER_SIZE/2)) |
| 228 | break; |
| 229 | |
| 230 | GeneratedFunctions::LogMetadata &lm |
| 231 | = GeneratedFunctions::logId2Metadata[entry->fmtId]; |
| 232 | fprintf(stderr, "ERROR: Attempting to log a message that is %u " |
| 233 | "bytes while the maximum allowable size is %u.\r\n" |
| 234 | "This occurs for the log message %s:%u '%s'\r\n", |
| 235 | entry->entrySize, |
| 236 | NanoLogConfig::STAGING_BUFFER_SIZE/2, |
| 237 | lm.fileName, lm.lineNumber, lm.fmtString); |
| 238 | } |
| 239 | |
| 240 | // Check for free space using the worst case assumption that |
| 241 | // none of the arguments compressed and there are as many Nibbles |
| 242 | // as there are data bytes. |
| 243 | uint32_t maxCompressedSize = downCast<uint32_t>(2*entry->entrySize |
| 244 | + sizeof(Log::UncompressedEntry)); |
| 245 | if (maxCompressedSize > (endOfBuffer - writePos)) |
| 246 | break; |
| 247 | |
| 248 | compressLogHeader(entry, &writePos, lastTimestamp); |
| 249 | lastTimestamp = entry->timestamp; |
| 250 | |
| 251 | size_t argBytesWritten = |
| 252 | GeneratedFunctions::compressFnArray[entry->fmtId](entry, writePos); |
| 253 | writePos += argBytesWritten; |
| 254 | |
| 255 | remaining -= entry->entrySize; |
| 256 | from += entry->entrySize; |
| 257 | |
| 258 | ++numEventsProcessed; |
| 259 | } |
| 260 | |
| 261 | assert(currentExtentSize); |
| 262 | *currentExtentSize += downCast<uint32_t>(writePos - bufferStart); |
| 263 | |
| 264 | if (numEventsCompressed) |
| 265 | *numEventsCompressed += numEventsProcessed; |