diff options
author | Zack Rusin <zack@kde.org> | 2011-08-04 19:45:31 -0400 |
---|---|---|
committer | Zack Rusin <zack@kde.org> | 2011-08-04 19:45:31 -0400 |
commit | c2393d25d1054aeb582892e6c76122bfb9746fe3 (patch) | |
tree | 0f41bd04bd5646535e863ef4419e486a335930f7 | |
parent | b79b23b7b546630ab3d9e4d47653b73eacbdf130 (diff) |
Make buffer size computation easier plus add some debugging helpers.threaded-trace
-rw-r--r-- | ringbuffer.cpp | 9 | ||||
-rw-r--r-- | trace_writer.cpp | 29 |
2 files changed, 35 insertions, 3 deletions
diff --git a/ringbuffer.cpp b/ringbuffer.cpp index 839b6ac5..287046f1 100644 --- a/ringbuffer.cpp +++ b/ringbuffer.cpp @@ -5,6 +5,8 @@ #include <iostream> +//#define DBG 1 + using namespace OS; Ringbuffer::Ringbuffer(long size) @@ -46,6 +48,13 @@ int Ringbuffer::sizeToRead() const void Ringbuffer::write(char *buffer, int size) { +#if DBG + std::cerr << "::write toRead = "<<sizeToRead() + << ", toWrite = " << sizeToWrite() + <<", bufSize = "<<size + <<". " + << std::endl; +#endif if (size > sizeToWrite()) { assert(0); return; diff --git a/trace_writer.cpp b/trace_writer.cpp index 5b599500..9b39e4dc 100644 --- a/trace_writer.cpp +++ b/trace_writer.cpp @@ -32,19 +32,30 @@ #include <zlib.h> + +#include <iostream> #include "os.hpp" #include "trace_writer.hpp" #include "trace_format.hpp" #include "os_thread.hpp" +//#define DBG 1 namespace Trace { -static const int BUFFER_SIZE = 1 * 1024 * 1024; +static const int BUFFER_SIZE = 2 * 1024 * 1024; +static const int MIN_BUFFER_SIZE = BUFFER_SIZE / 2; static void gzipWriteRing(void *gzFile, OS::Ringbuffer *buffer, int bufSize) { +#if DBG + std::cerr << "::read toRead = "<<buffer->sizeToRead() + << ", toWrite = " << buffer->sizeToWrite() + <<", bufSize = "<<bufSize + <<". " + << std::endl; +#endif if (buffer->readOverflows(bufSize)) { int overflow = buffer->readOverflowsBy(bufSize); gzwrite(gzFile, buffer->readPointer(), bufSize - overflow); @@ -54,6 +65,9 @@ gzipWriteRing(void *gzFile, OS::Ringbuffer *buffer, int bufSize) gzwrite(gzFile, buffer->readPointer(), bufSize); buffer->readPointerAdvance(bufSize); } +#if DBG + std::cerr << "\t::read end"<<std::endl; +#endif } static void * THREAD_ROUTINE @@ -61,9 +75,11 @@ gzipWriterThread(void *arg) { Trace::WriterThreadData *td = (Trace::WriterThreadData *)arg; +#if DBG std::cerr << "START gzipWriterThread finished = " << td->finished <<std::endl; +#endif void *gzFile = gzopen(td->filename.c_str(), "wb"); if (!gzFile) { @@ -72,7 +88,10 @@ gzipWriterThread(void *arg) } while (!td->finished) { - while (!td->finished && td->buffer->sizeToRead() < BUFFER_SIZE) { + while (!td->finished && td->buffer->sizeToRead() < MIN_BUFFER_SIZE) { +#if DBG + std::cerr << "\tread sleep....................." <<std::endl; +#endif CondvarWait(td->writeCond, td->writeMutex); } int bufSize = std::min(BUFFER_SIZE, @@ -85,9 +104,11 @@ gzipWriterThread(void *arg) gzipWriteRing(gzFile, td->buffer, bufSize); } +#if DBG std::cerr << "END gzipWriterThread finished = " << td->finished <<std::endl; +#endif if (gzFile != NULL) { gzclose(gzFile); gzFile = NULL; @@ -138,10 +159,12 @@ Writer::close(void) { if (!m_threadData->running) return; +#if DBG std::cerr << "close, running = " << m_threadData->running << ", finished = " <<m_threadData->finished <<std::endl; +#endif m_threadData->finished = true; CondvarSignal(m_threadData->writeCond); OS::ThreadWait(m_thread); @@ -224,7 +247,7 @@ Writer::_write(const void *sBuffer, size_t dwBytesToWrite) { CondvarWait(m_threadData->readCond, m_threadData->readMutex); } m_threadData->buffer->write((char*)sBuffer, dwBytesToWrite); - if (m_threadData->buffer->sizeToRead() >= BUFFER_SIZE) + if (m_threadData->buffer->sizeToRead() >= MIN_BUFFER_SIZE) CondvarSignal(m_threadData->writeCond); } |