add option to reduce dump flush buffer size to 1
This commit is contained in:
@@ -123,6 +123,7 @@ static struct options opt = {
|
|||||||
false, // dump
|
false, // dump
|
||||||
"/tmp/" PACKAGE "_dump.bin", // dumpFile
|
"/tmp/" PACKAGE "_dump.bin", // dumpFile
|
||||||
100, // dumpSize
|
100, // dumpSize
|
||||||
|
false, // dumpFlush
|
||||||
};
|
};
|
||||||
|
|
||||||
/** the @a MessageMap instance, or nullptr. */
|
/** the @a MessageMap instance, or nullptr. */
|
||||||
@@ -174,6 +175,7 @@ static const char argpdoc[] =
|
|||||||
#define O_RAWSIZ (O_RAWFIL+1)
|
#define O_RAWSIZ (O_RAWFIL+1)
|
||||||
#define O_DMPFIL (O_RAWSIZ+1)
|
#define O_DMPFIL (O_RAWSIZ+1)
|
||||||
#define O_DMPSIZ (O_DMPFIL+1)
|
#define O_DMPSIZ (O_DMPFIL+1)
|
||||||
|
#define O_DMPFLU (O_DMPSIZ+1)
|
||||||
|
|
||||||
/** the definition of the known program arguments. */
|
/** the definition of the known program arguments. */
|
||||||
static const struct argp_option argpoptions[] = {
|
static const struct argp_option argpoptions[] = {
|
||||||
@@ -242,6 +244,7 @@ static const struct argp_option argpoptions[] = {
|
|||||||
{"dump", 'D', nullptr, 0, "Enable binary dump of received bytes", 0 },
|
{"dump", 'D', nullptr, 0, "Enable binary dump of received bytes", 0 },
|
||||||
{"dumpfile", O_DMPFIL, "FILE", 0, "Dump received bytes to FILE [/tmp/" PACKAGE "_dump.bin]", 0 },
|
{"dumpfile", O_DMPFIL, "FILE", 0, "Dump received bytes to FILE [/tmp/" PACKAGE "_dump.bin]", 0 },
|
||||||
{"dumpsize", O_DMPSIZ, "SIZE", 0, "Make dump file no larger than SIZE kB [100]", 0 },
|
{"dumpsize", O_DMPSIZ, "SIZE", 0, "Make dump file no larger than SIZE kB [100]", 0 },
|
||||||
|
{"dumpflush", O_DMPFLU, nullptr, 0, "Flush each byte", 0 },
|
||||||
|
|
||||||
{nullptr, 0, nullptr, 0, nullptr, 0 },
|
{nullptr, 0, nullptr, 0, nullptr, 0 },
|
||||||
};
|
};
|
||||||
@@ -581,6 +584,9 @@ error_t parse_opt(int key, char *arg, struct argp_state *state) {
|
|||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case O_DMPFLU: // --dumpflush
|
||||||
|
opt->dumpFlush = true;
|
||||||
|
break;
|
||||||
|
|
||||||
case ARGP_KEY_ARG:
|
case ARGP_KEY_ARG:
|
||||||
if (opt->injectMessages || (opt->checkConfig && opt->scanConfig)) {
|
if (opt->injectMessages || (opt->checkConfig && opt->scanConfig)) {
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ struct options {
|
|||||||
bool dump; //!< binary dump received bytes
|
bool dump; //!< binary dump received bytes
|
||||||
const char* dumpFile; //!< name of dump file [/tmp/ebusd_dump.bin]
|
const char* dumpFile; //!< name of dump file [/tmp/ebusd_dump.bin]
|
||||||
unsigned int dumpSize; //!< maximum size of dump file in kB [100]
|
unsigned int dumpSize; //!< maximum size of dump file in kB [100]
|
||||||
|
bool dumpFlush; //!< flush each byte
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ MainLoop::MainLoop(const struct options& opt, Device *device, MessageMap* messag
|
|||||||
}
|
}
|
||||||
m_device->setListener(this);
|
m_device->setListener(this);
|
||||||
if (opt.dumpFile[0]) {
|
if (opt.dumpFile[0]) {
|
||||||
m_dumpFile = new RotateFile(opt.dumpFile, opt.dumpSize);
|
m_dumpFile = new RotateFile(opt.dumpFile, opt.dumpSize, false, opt.dumpFlush ? 1 : 16);
|
||||||
m_dumpFile->setEnabled(opt.dump);
|
m_dumpFile->setEnabled(opt.dump);
|
||||||
} else {
|
} else {
|
||||||
m_dumpFile = nullptr;
|
m_dumpFile = nullptr;
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ void RotateFile::write(const unsigned char* value, const size_t size, const bool
|
|||||||
fwrite(value, (streamsize)size, 1, m_stream);
|
fwrite(value, (streamsize)size, 1, m_stream);
|
||||||
m_fileSize += size;
|
m_fileSize += size;
|
||||||
m_flushSize += size;
|
m_flushSize += size;
|
||||||
if (m_flushSize > 16) {
|
if (m_flushSize >= m_flushBuffer) {
|
||||||
fflush(m_stream);
|
fflush(m_stream);
|
||||||
m_flushSize = 0;
|
m_flushSize = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,10 +43,11 @@ class RotateFile {
|
|||||||
* @param fileName the name of the file write to.
|
* @param fileName the name of the file write to.
|
||||||
* @param maxSize the maximum size of the file to write to.
|
* @param maxSize the maximum size of the file to write to.
|
||||||
* @param textMode whether to write each byte with prefixed timestamp and direction as text.
|
* @param textMode whether to write each byte with prefixed timestamp and direction as text.
|
||||||
|
* @param flushBuffer the size of the flush buffer.
|
||||||
*/
|
*/
|
||||||
RotateFile(const string fileName, const unsigned int maxSize, const bool textMode = false)
|
RotateFile(const string fileName, const unsigned int maxSize, const bool textMode = false, const unsigned int flushBuffer = 16)
|
||||||
: m_enabled(false), m_fileName(fileName), m_maxSize(maxSize), m_textMode(textMode), m_stream(), m_fileSize(0),
|
: m_enabled(false), m_fileName(fileName), m_maxSize(maxSize), m_textMode(textMode), m_stream(), m_fileSize(0),
|
||||||
m_flushSize(0) {}
|
m_flushSize(0), m_flushBuffer(flushBuffer) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destructor.
|
* Destructor.
|
||||||
@@ -98,6 +99,9 @@ class RotateFile {
|
|||||||
|
|
||||||
/** the number of bytes written to @a m_file since the last flush. */
|
/** the number of bytes written to @a m_file since the last flush. */
|
||||||
uint64_t m_flushSize;
|
uint64_t m_flushSize;
|
||||||
|
|
||||||
|
/** the size of the flush buffer. */
|
||||||
|
const unsigned int m_flushBuffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ebusd
|
} // namespace ebusd
|
||||||
|
|||||||
Reference in New Issue
Block a user