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

Method compressionThreadMain

runtime/RuntimeLogger.cc:347–621  ·  view source on GitHub ↗

* Main compression thread that handles scanning through the StagingBuffers, * compressing log entries, and outputting a compressed log file. */

Source from the content-addressed store, hash-verified

345* compressing log entries, and outputting a compressed log file.
346*/
347void
348RuntimeLogger::compressionThreadMain() {
349 // Index of the last StagingBuffer checked for uncompressed log messages
350 size_t lastStagingBufferChecked = 0;
351
352 // Marks when the thread wakes up. This value should be used to calculate
353 // the number of cyclesActive right before blocking/sleeping and then updated
354 // to the latest rdtsc() when the thread re-awakens.
355 uint64_t cyclesAwakeStart = PerfUtils::Cycles::rdtsc();
356 cycleAtThreadStart = cyclesAwakeStart;
357
358 // Manages the state associated with compressing log messages
359 Log::Encoder encoder(compressingBuffer, NanoLogConfig::OUTPUT_BUFFER_SIZE);
360
361 // Indicates whether a compression operation failed or not due
362 // to insufficient space in the outputBuffer
363 bool outputBufferFull = false;
364
365 // Indicates that in scanning the StagingBuffers, we have passed the
366 // zero-th index, but have not yet encoded that in he compressed output
367 bool wrapAround = false;
368
369 // Keeps a shadow mapping of the log identifiers to static information
370 // to allow the logging threads to register in parallel with compression
371 // lookup
372 std::vector<StaticLogInfo> shadowStaticInfo;
373
374 // Each iteration of this loop scans for uncompressed log messages in the
375 // thread buffers, compresses as much as possible, and outputs it to a file.
376 while (!compressionThreadShouldExit) {
377 coreId = sched_getcpu();
378
379 // Indicates how many bytes we have consumed from the StagingBuffers
380 // in a single iteration of the while above. A value of 0 means we
381 // were unable to consume anymore data any of the stagingBuffers
382 // (either due to empty stagingBuffers or a full output encoder)
383 uint64_t bytesConsumedThisIteration = 0;
384
385 uint64_t start = PerfUtils::Cycles::rdtsc();
386 // Step 1: Find buffers with entries and compress them
387 {
388 std::unique_lock<std::mutex> lock(bufferMutex);
389 size_t i = lastStagingBufferChecked;
390
391 // Output new dictionary entries, if necessary
392 if (nextInvocationIndexToBePersisted < invocationSites.size())
393 {
394 std::unique_lock<std::mutex> lock (registrationMutex);
395 encoder.encodeNewDictionaryEntries(
396 nextInvocationIndexToBePersisted,
397 invocationSites);
398
399 // update our shadow copy
400 for (uint64_t i = shadowStaticInfo.size();
401 i < nextInvocationIndexToBePersisted; ++i)
402 {
403 shadowStaticInfo.push_back(invocationSites.at(i));
404 }

Callers

nothing calls this directly

Calls 10

rdtscFunction · 0.85
arraySizeFunction · 0.85
peekMethod · 0.80
encodeLogMsgsMethod · 0.80
getIdMethod · 0.80
consumeMethod · 0.80
checkCanDeleteMethod · 0.80
getEncodedBytesMethod · 0.80
swapBufferMethod · 0.80

Tested by

no test coverage detected