From f66e4be5877a7e5556511ccfe9ecc5ecab4d5366 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Wed, 1 Mar 2023 12:47:50 +0000 Subject: Use typesafe time in vespalog --- vespalog/src/test/bufferedlogskiptest.cpp | 17 ++++++++++---- vespalog/src/test/bufferedlogtest.cpp | 30 ++++++++++++++++-------- vespalog/src/vespa/log/bufferedlogger.cpp | 38 ++++++++++++++++--------------- vespalog/src/vespa/log/bufferedlogger.h | 4 ++-- vespalog/src/vespa/log/log.cpp | 33 ++++++++++++--------------- vespalog/src/vespa/log/log.h | 28 +++++++++++++++-------- 6 files changed, 87 insertions(+), 63 deletions(-) diff --git a/vespalog/src/test/bufferedlogskiptest.cpp b/vespalog/src/test/bufferedlogskiptest.cpp index 8b7f1982678..abb5705b612 100644 --- a/vespalog/src/test/bufferedlogskiptest.cpp +++ b/vespalog/src/test/bufferedlogskiptest.cpp @@ -9,6 +9,15 @@ LOG_SETUP("bufferedlogskiptest"); +using namespace std::literals::chrono_literals; + +/** Test timer returning just a given time. Used in tests to fake time. */ +struct TestTimer : public ns_log::Timer { + uint64_t & _time; + TestTimer(uint64_t & timeVar) : _time(timeVar) { } + ns_log::system_time getTimestamp() const override { return ns_log::system_time(std::chrono::microseconds(_time)); } +}; + std::string readFile(const std::string& file) { std::ostringstream ost; std::ifstream is(file.c_str()); @@ -62,8 +71,8 @@ void testSkipBufferOnDebug(const std::string& file, uint64_t & timer) void reset(uint64_t & timer) { timer = 0; ns_log::BufferedLogger::instance().setMaxCacheSize(10); - ns_log::BufferedLogger::instance().setMaxEntryAge(300); - ns_log::BufferedLogger::instance().setCountFactor(5); + ns_log::BufferedLogger::instance().setMaxEntryAge(300s); + ns_log::BufferedLogger::instance().setCountFactor(5s); } int @@ -75,8 +84,8 @@ main(int argc, char **argv) } ns_log::Logger::fakePid = true; uint64_t timer; - ns_log_logger.setTimer(std::unique_ptr(new ns_log::TestTimer(timer))); - ns_log::BufferedLogger::instance().setTimer(std::unique_ptr(new ns_log::TestTimer(timer))); + ns_log_logger.setTimer(std::make_unique(timer)); + ns_log::BufferedLogger::instance().setTimer(std::make_unique(timer)); reset(timer); testSkipBufferOnDebug(argv[1], timer); diff --git a/vespalog/src/test/bufferedlogtest.cpp b/vespalog/src/test/bufferedlogtest.cpp index 365f8fb85a7..d3fc1c28d63 100644 --- a/vespalog/src/test/bufferedlogtest.cpp +++ b/vespalog/src/test/bufferedlogtest.cpp @@ -12,6 +12,16 @@ LOG_SETUP("bufferedlogtest"); +using namespace std::literals::chrono_literals; + + +/** Test timer returning just a given time. Used in tests to fake time. */ +struct TestTimer : public ns_log::Timer { + uint64_t & _time; + TestTimer(uint64_t & timeVar) : _time(timeVar) { } + ns_log::system_time getTimestamp() const override { return ns_log::system_time(std::chrono::microseconds(_time)); } +}; + std::string readFile(const std::string& file) { std::ostringstream ost; std::ifstream is(file.c_str()); @@ -112,9 +122,9 @@ void testThatEntriesWithHighCountsAreEventuallyRemoved( // Should eventually throw out the entries with high count timer = 10 * 1000000 + 4; // Make sure we don't remove due to age. - ns_log::BufferedLogger::instance().setMaxEntryAge(1000000); + ns_log::BufferedLogger::instance().setMaxEntryAge(1000000s); // Let each count, count for 5 seconds. - ns_log::BufferedLogger::instance().setCountFactor(5); + ns_log::BufferedLogger::instance().setCountFactor(5s); LOGBM(info, "Starting up, using logfile %s", file.c_str()); timer = 100 * 1000000 + 4; @@ -147,9 +157,9 @@ void testThatEntriesExpire( // Test that we don't keep entries longer than max age timer = 10 * 1000000 + 4; // Time out after 120 seconds - ns_log::BufferedLogger::instance().setMaxEntryAge(120); + ns_log::BufferedLogger::instance().setMaxEntryAge(120s); // Let counts count much, so they expire due to time instead - ns_log::BufferedLogger::instance().setCountFactor(100000); + ns_log::BufferedLogger::instance().setCountFactor(100000s); LOGBM(info, "Starting up, using logfile %s", file.c_str()); timer = 100 * 1000000 + 4; @@ -217,9 +227,9 @@ void testThatHighCountEntriesDontStarveOthers( std::cerr << "testThatHighCountEntriesDontStarveOthers ...\n"; timer = 10 * 1000000 + 4; // Long time out, we don't want to rely on timeout to prevent starvation - ns_log::BufferedLogger::instance().setMaxEntryAge(12000000); + ns_log::BufferedLogger::instance().setMaxEntryAge(12000000s); // Let counts count much, so they score high - ns_log::BufferedLogger::instance().setCountFactor(100000); + ns_log::BufferedLogger::instance().setCountFactor(100000s); LOGBM(info, "Starting up, using logfile %s", file.c_str()); timer = 100 * 1000000; @@ -372,8 +382,8 @@ void testNonBufferedLoggerTriggersBufferedLogTrim(const std::string& file, void reset(uint64_t& timer) { timer = 0; - ns_log::BufferedLogger::instance().setMaxEntryAge(300); - ns_log::BufferedLogger::instance().setCountFactor(5); + ns_log::BufferedLogger::instance().setMaxEntryAge(300s); + ns_log::BufferedLogger::instance().setCountFactor(5s); } int @@ -386,8 +396,8 @@ main(int argc, char **argv) ns_log::Logger::fakePid = true; ns_log::BufferedLogger::instance().setMaxCacheSize(10); uint64_t timer; - ns_log_logger.setTimer(std::unique_ptr(new ns_log::TestTimer(timer))); - ns_log::BufferedLogger::instance().setTimer(std::unique_ptr(new ns_log::TestTimer(timer))); + ns_log_logger.setTimer(std::make_unique(timer)); + ns_log::BufferedLogger::instance().setTimer(std::make_unique(timer)); reset(timer); testThatEntriesWithHighCountIsKept(argv[1], timer); diff --git a/vespalog/src/vespa/log/bufferedlogger.cpp b/vespalog/src/vespa/log/bufferedlogger.cpp index 33ff3da7366..7ad878a568c 100644 --- a/vespalog/src/vespa/log/bufferedlogger.cpp +++ b/vespalog/src/vespa/log/bufferedlogger.cpp @@ -14,6 +14,8 @@ #include #include +using namespace std::literals::chrono_literals; + namespace ns_log { // implementation details for BufferedLogger @@ -25,7 +27,7 @@ public: /** Lock needed to access cache. */ mutable std::mutex _mutex; - static uint64_t _countFactor; + static duration _countFactor; /** Struct keeping information about log message. */ struct Entry { @@ -35,7 +37,7 @@ public: std::string _token; std::string _message; uint32_t _count; - uint64_t _timestamp; + system_time _timestamp; Logger* _logger; Entry(const Entry &); @@ -44,13 +46,13 @@ public: Entry & operator=(Entry &&) noexcept; Entry(Logger::LogLevel level, const char* file, int line, const std::string& token, const std::string& message, - uint64_t timestamp, Logger&); + system_time timestamp, Logger&); ~Entry(); bool operator==(const Entry& entry) const; bool operator<(const Entry& entry) const; - uint64_t getAgeFactor() const; + system_time getAgeFactor() const; std::string toString() const; }; @@ -73,7 +75,7 @@ public: >, boost::multi_index::ordered_non_unique< boost::multi_index::const_mem_fun< - Entry, uint64_t, &Entry::getAgeFactor + Entry, system_time, &Entry::getAgeFactor > > > @@ -85,7 +87,7 @@ public: LogCacheBack _cacheBack; uint32_t _maxCacheSize; - uint64_t _maxEntryAge; + duration _maxEntryAge; /** Empty buffer and write all log entries in it. */ void flush(); @@ -97,7 +99,7 @@ public: * Flush parts of cache, so we're below max size and only have messages of * acceptable age. Calling this, _mutex should already be locked. */ - void trimCache(uint64_t currentTime); + void trimCache(system_time currentTime); /** * Trim the cache up to current time. Used externally to check if we @@ -125,11 +127,11 @@ public: }; // Let each hit count for 5 seconds -uint64_t BackingBuffer::_countFactor = VESPA_LOG_COUNTAGEFACTOR * 1000 * 1000; +duration BackingBuffer::_countFactor = VESPA_LOG_COUNTAGEFACTOR * 1s; BackingBuffer::Entry::Entry(Logger::LogLevel level, const char* file, int line, const std::string& token, const std::string& msg, - uint64_t timestamp, Logger& l) + system_time timestamp, Logger& l) : _level(level), _file(file), _line(line), @@ -171,11 +173,11 @@ BackingBuffer::Entry::toString() const std::ostringstream ost; ost << "Entry(" << _level << ", " << _file << ":" << _line << ": " << _message << " [" << _token << "], count " << _count - << ", timestamp " << _timestamp << ")"; + << ", timestamp " << count_us(_timestamp.time_since_epoch()) << ")"; return ost.str(); } -uint64_t +system_time BackingBuffer::Entry::getAgeFactor() const { return _timestamp + _countFactor * _count; @@ -288,7 +290,7 @@ BufferedLogger::flush() { } void -BackingBuffer::trimCache(uint64_t currentTime) +BackingBuffer::trimCache(system_time currentTime) { // Remove entries that have been in here too long. while (!_cacheBack.empty() && @@ -330,8 +332,8 @@ BackingBuffer::log(const Entry& e) const if (e._count > 1) { std::ostringstream ost; ost << e._message << " (Repeated " << (e._count - 1) - << " times since " << (e._timestamp / 1000000) << "." - << std::setw(6) << std::setfill('0') << (e._timestamp % 1000000) + << " times since " << count_s(e._timestamp.time_since_epoch()) << "." + << std::setw(6) << std::setfill('0') << (count_us(e._timestamp.time_since_epoch()) % 1000000) << ")"; e._logger->doLogCore(_timer->getTimestamp(), e._level, e._file.c_str(), e._line, ost.str().c_str(), ost.str().size()); @@ -365,13 +367,13 @@ BufferedLogger::setMaxCacheSize(uint32_t size) { } void -BufferedLogger::setMaxEntryAge(uint64_t seconds) { - _backing->_maxEntryAge = seconds * 1000000; +BufferedLogger::setMaxEntryAge(duration maxAge) { + _backing->_maxEntryAge = maxAge; } void -BufferedLogger::setCountFactor(uint64_t factor) { - _backing->_countFactor = factor * 1000000; +BufferedLogger::setCountFactor(duration factor) { + _backing->_countFactor = factor; } /** Set a fake timer to use for log messages. Used in unit testing. */ diff --git a/vespalog/src/vespa/log/bufferedlogger.h b/vespalog/src/vespa/log/bufferedlogger.h index 8baa32445a5..31e194e63bb 100644 --- a/vespalog/src/vespa/log/bufferedlogger.h +++ b/vespalog/src/vespa/log/bufferedlogger.h @@ -178,8 +178,8 @@ public: // to easier be able to test all aspects of the buffer, and be independent // of the default settings for applications void setMaxCacheSize(uint32_t size); - void setMaxEntryAge(uint64_t seconds); - void setCountFactor(uint64_t factor); + void setMaxEntryAge(duration seconds); + void setCountFactor(duration factor); void doLog(Logger&, Logger::LogLevel level, const char *file, int line, const std::string& token, diff --git a/vespalog/src/vespa/log/log.cpp b/vespalog/src/vespa/log/log.cpp index 7430815122d..9ca993b84fc 100644 --- a/vespalog/src/vespa/log/log.cpp +++ b/vespalog/src/vespa/log/log.cpp @@ -20,13 +20,9 @@ LOG_SETUP_INDIRECT(".log", "$Id$"); namespace ns_log { -uint64_t Timer::getTimestamp() const { - struct timeval tv; - gettimeofday(&tv, nullptr); - uint64_t timestamp = tv.tv_sec; - timestamp *= 1000000; - timestamp += tv.tv_usec; - return timestamp; +system_time +Timer::getTimestamp() const { + return std::chrono::system_clock::now(); } LogTarget *Logger::_target = 0; @@ -220,8 +216,7 @@ Logger::tryLog(int sizeofPayload, LogLevel level, const char *file, int line, co const int actualSize = vsnprintf(payload, sizeofPayload, fmt, args); if (actualSize < sizeofPayload) { - uint64_t timestamp = _timer->getTimestamp(); - doLogCore(timestamp, level, file, line, payload, actualSize); + doLogCore(_timer->getTimestamp(), level, file, line, payload, actualSize); } delete[] payload; return actualSize; @@ -242,8 +237,9 @@ Logger::doLog(LogLevel level, const char *file, int line, const char *fmt, ...) ns_log::BufferedLogger::instance().trimCache(); } -void Logger::doLogCore(uint64_t timestamp, LogLevel level, - const char *file, int line, const char *msg, size_t msgSize) +void +Logger::doLogCore(system_time timestamp, LogLevel level, + const char *file, int line, const char *msg, size_t msgSize) { const size_t sizeofEscapedPayload(msgSize*4+1); const size_t sizeofTotalMessage(sizeofEscapedPayload + 1000); @@ -281,23 +277,23 @@ void Logger::doLogCore(uint64_t timestamp, LogLevel level, // found to be too inaccurate. int32_t tid = (fakePid ? -1 : gettid(pthread_self()) % 0xffff); + time_t secs = count_s(timestamp.time_since_epoch()); + uint32_t usecs_part = count_us(timestamp.time_since_epoch()) % 1000000; if (_target->makeHumanReadable()) { - time_t secs = static_cast(timestamp / 1000000); struct tm tmbuf; localtime_r(&secs, &tmbuf); char timebuf[100]; strftime(timebuf, 100, "%Y-%m-%d %H:%M:%S", &tmbuf); snprintf(totalMessage.get(), sizeofTotalMessage, "[%s.%06u] %d/%d (%s%s) %s: %s\n", - timebuf, static_cast(timestamp % 1000000), + timebuf, usecs_part, fakePid ? -1 : getpid(), tid, _prefix, _appendix, levelName(level), msg); } else if (level == debug || level == spam) { snprintf(totalMessage.get(), sizeofTotalMessage, - "%u.%06u\t%s\t%d/%d\t%s\t%s%s\t%s\t%s:%d %s%s\n", - static_cast(timestamp / 1000000), - static_cast(timestamp % 1000000), + "%lu.%06u\t%s\t%d/%d\t%s\t%s%s\t%s\t%s:%d %s%s\n", + secs, usecs_part, _hostname, fakePid ? -1 : getpid(), tid, _serviceName, _prefix, _appendix, levelName(level), file, line, @@ -305,9 +301,8 @@ void Logger::doLogCore(uint64_t timestamp, LogLevel level, escapedPayload.get()); } else { snprintf(totalMessage.get(), sizeofTotalMessage, - "%u.%06u\t%s\t%d/%d\t%s\t%s%s\t%s\t%s\n", - static_cast(timestamp / 1000000), - static_cast(timestamp % 1000000), + "%lu.%06u\t%s\t%d/%d\t%s\t%s%s\t%s\t%s\n", + secs, usecs_part, _hostname, fakePid ? -1 : getpid(), tid, _serviceName, _prefix, _appendix, levelName(level), escapedPayload.get()); diff --git a/vespalog/src/vespa/log/log.h b/vespalog/src/vespa/log/log.h index 888e24a0f28..88d24ba7e18 100644 --- a/vespalog/src/vespa/log/log.h +++ b/vespalog/src/vespa/log/log.h @@ -3,12 +3,15 @@ #include #include -#include // for pid_t #include // for placement new #include // for malloc #include // for memset #include // for va_list #include +#include +#include // for pid_t + + /** * If this macro is defined, the regular LOG calls will go through the @@ -144,19 +147,24 @@ namespace ns_log { class LogTarget; class ControlFile; +using system_time = std::chrono::system_clock::time_point; +using duration = std::chrono::nanoseconds; + +constexpr int64_t +count_s(duration d) { + return std::chrono::duration_cast(d).count(); +} + +constexpr int64_t +count_us(duration d) { + return std::chrono::duration_cast(d).count(); +} // XXX this is way too complicated, must be some simpler way to do this /** Timer class used to retrieve timestamp, such that we can override in test */ struct Timer { virtual ~Timer() = default; - virtual uint64_t getTimestamp() const; -}; - -/** Test timer returning just a given time. Used in tests to fake time. */ -struct TestTimer : public Timer { - uint64_t & _time; - TestTimer(uint64_t & timeVar) : _time(timeVar) { } - uint64_t getTimestamp() const override { return _time; } + virtual system_time getTimestamp() const; }; class Logger { @@ -219,7 +227,7 @@ public: * * @param timestamp Time in microseconds. */ - void doLogCore(uint64_t timestamp, LogLevel level, + void doLogCore(system_time timestamp, LogLevel level, const char *file, int line, const char *msg, size_t msgSize); void doEventStarting(const char *name); void doEventStopping(const char *name, const char *why); -- cgit v1.2.3 From 9298ba38f3f62ec7f6a27403fa663f31f366a604 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Wed, 1 Mar 2023 16:04:10 +0000 Subject: Reduce transitive includes. --- config/src/apps/vespa-get-config/getconfig.cpp | 1 + config/src/tests/functiontest/functiontest.cpp | 1 + config/src/vespa/config/frt/frtconfigagent.cpp | 1 + config/src/vespa/config/set/configsetsource.cpp | 1 + .../config/subscription/configsubscriptionset.cpp | 1 + configd/src/apps/sentinel/config-owner.cpp | 2 +- configd/src/apps/sentinel/logctl.cpp | 2 +- configd/src/apps/sentinel/model-owner.cpp | 1 + logd/src/logd/watcher.cpp | 1 + messagebus/src/tests/sequencer/sequencer.cpp | 1 + .../tests/proton/attribute/attributeflush_test.cpp | 1 + .../proton/attribute/attribute_initializer.cpp | 1 + .../vespa/searchcore/proton/index/index_writer.cpp | 1 + .../searchcore/proton/server/fileconfigmanager.cpp | 1 + .../proton/server/memory_flush_config_updater.cpp | 1 + .../vespa/searchcore/proton/server/memoryflush.cpp | 1 + .../vespa/searchcore/proton/server/simpleflush.cpp | 5 +-- .../searchcore/proton/server/summaryadapter.cpp | 1 + .../vespa/searchcorespi/index/indexflushtarget.cpp | 1 + .../searchcorespi/index/indexfusiontarget.cpp | 1 + searchlib/src/apps/uniform/uniform.cpp | 3 +- .../vespa-index-inspect/vespa-index-inspect.cpp | 33 ++++++++-------- .../tests/attribute/postinglist/postinglist.cpp | 1 + .../reference_attribute_test.cpp | 1 + .../bitcompression/expgolomb/expgolomb_test.cpp | 1 + .../location_iterator/location_iterator_test.cpp | 1 + .../tests/diskindex/pagedict4/pagedict4test.cpp | 1 + .../memoryindex/datastore/feature_store_test.cpp | 1 + searchlib/src/tests/sortspec/multilevelsort.cpp | 1 + .../src/vespa/searchlib/common/bitvectorcache.cpp | 1 + .../src/vespa/searchlib/diskindex/fileheader.cpp | 1 + .../src/vespa/searchlib/docstore/compacter.cpp | 1 + .../src/vespa/searchlib/engine/proto_converter.cpp | 3 +- .../searchlib/features/random_normal_feature.cpp | 1 + .../features/random_normal_stable_feature.cpp | 1 + .../src/vespa/searchlib/features/randomfeature.cpp | 1 + .../predicate/predicate_range_term_expander.h | 1 + .../test/fakedata/fakeegcompr64filterocc.cpp | 1 + .../src/vespa/searchlib/transactionlog/session.cpp | 1 + .../vespa/searchlib/util/filesizecalculator.cpp | 1 + searchlib/src/vespa/searchlib/util/url.cpp | 1 + searchsummary/src/vespa/juniper/Matcher.cpp | 6 ++- searchsummary/src/vespa/juniper/sumdesc.cpp | 1 + searchsummary/src/vespa/juniper/tokenizer.cpp | 1 + .../vespa/storage/distributor/messagetracker.cpp | 1 + .../external/twophaseupdateoperation.cpp | 2 +- .../vespa/storage/distributor/sentmessagemap.cpp | 1 + .../defaultimplementation/thread/threadimpl.cpp | 1 + vespalib/src/tests/btree/iteratespeed.cpp | 5 +-- .../tests/datastore/datastore/datastore_test.cpp | 1 + .../generation_handler_stress_test.cpp | 7 +++- .../src/vespa/vespalib/data/slime/json_format.cpp | 1 + vespalib/src/vespa/vespalib/net/native_epoll.cpp | 1 + .../vespa/vespalib/util/process_memory_stats.cpp | 1 + vespalog/src/logctl/logctl.cpp | 3 +- vespalog/src/logger/llreader.cpp | 11 ++---- vespalog/src/test/bufferedlogskiptest.cpp | 9 +++-- vespalog/src/test/bufferedlogtest.cpp | 21 ++++++----- vespalog/src/test/threads/testthreads.cpp | 1 + vespalog/src/vespa/log/bufferedlogger.cpp | 43 ++++++++++++--------- vespalog/src/vespa/log/bufferedlogger.h | 11 ++---- vespalog/src/vespa/log/component.cpp | 1 + vespalog/src/vespa/log/internal.h | 21 +++++++++++ vespalog/src/vespa/log/llparser.cpp | 1 + vespalog/src/vespa/log/log-target-file.cpp | 10 ++--- vespalog/src/vespa/log/log.cpp | 38 +++++++------------ vespalog/src/vespa/log/log.h | 44 +++------------------- 67 files changed, 180 insertions(+), 146 deletions(-) diff --git a/config/src/apps/vespa-get-config/getconfig.cpp b/config/src/apps/vespa-get-config/getconfig.cpp index 74380390095..03a049044ae 100644 --- a/config/src/apps/vespa-get-config/getconfig.cpp +++ b/config/src/apps/vespa-get-config/getconfig.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include diff --git a/config/src/tests/functiontest/functiontest.cpp b/config/src/tests/functiontest/functiontest.cpp index 333645176a0..9d6605be9c1 100644 --- a/config/src/tests/functiontest/functiontest.cpp +++ b/config/src/tests/functiontest/functiontest.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include diff --git a/config/src/vespa/config/frt/frtconfigagent.cpp b/config/src/vespa/config/frt/frtconfigagent.cpp index b5bcb3591f0..15b605ad690 100644 --- a/config/src/vespa/config/frt/frtconfigagent.cpp +++ b/config/src/vespa/config/frt/frtconfigagent.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include LOG_SETUP(".config.frt.frtconfigagent"); diff --git a/config/src/vespa/config/set/configsetsource.cpp b/config/src/vespa/config/set/configsetsource.cpp index 41886a12d01..b84f6411855 100644 --- a/config/src/vespa/config/set/configsetsource.cpp +++ b/config/src/vespa/config/set/configsetsource.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include LOG_SETUP(".config.set.configsetsource"); diff --git a/config/src/vespa/config/subscription/configsubscriptionset.cpp b/config/src/vespa/config/subscription/configsubscriptionset.cpp index 4f7bf64f603..9c09a508fff 100644 --- a/config/src/vespa/config/subscription/configsubscriptionset.cpp +++ b/config/src/vespa/config/subscription/configsubscriptionset.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include LOG_SETUP(".config.subscription.configsubscriptionset"); diff --git a/configd/src/apps/sentinel/config-owner.cpp b/configd/src/apps/sentinel/config-owner.cpp index 90ceb705dc7..1fe361ef739 100644 --- a/configd/src/apps/sentinel/config-owner.cpp +++ b/configd/src/apps/sentinel/config-owner.cpp @@ -2,6 +2,7 @@ #include "config-owner.h" #include +#include #include LOG_SETUP(".sentinel.config-owner"); @@ -9,7 +10,6 @@ LOG_SETUP(".sentinel.config-owner"); namespace config::sentinel { ConfigOwner::ConfigOwner() = default; - ConfigOwner::~ConfigOwner() = default; void diff --git a/configd/src/apps/sentinel/logctl.cpp b/configd/src/apps/sentinel/logctl.cpp index 94759d4f102..057178cec2e 100644 --- a/configd/src/apps/sentinel/logctl.cpp +++ b/configd/src/apps/sentinel/logctl.cpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include LOG_SETUP(".sentinel.logctl"); diff --git a/configd/src/apps/sentinel/model-owner.cpp b/configd/src/apps/sentinel/model-owner.cpp index 5dd7a033933..93024911f4e 100644 --- a/configd/src/apps/sentinel/model-owner.cpp +++ b/configd/src/apps/sentinel/model-owner.cpp @@ -3,6 +3,7 @@ #include "model-owner.h" #include #include +#include #include LOG_SETUP(".sentinel.model-owner"); diff --git a/logd/src/logd/watcher.cpp b/logd/src/logd/watcher.cpp index c3752fcc3e8..af1efc3077d 100644 --- a/logd/src/logd/watcher.cpp +++ b/logd/src/logd/watcher.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include diff --git a/messagebus/src/tests/sequencer/sequencer.cpp b/messagebus/src/tests/sequencer/sequencer.cpp index 25d9934fe8d..7a3aaab9b1f 100644 --- a/messagebus/src/tests/sequencer/sequencer.cpp +++ b/messagebus/src/tests/sequencer/sequencer.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include LOG_SETUP("sequencer_test"); diff --git a/searchcore/src/tests/proton/attribute/attributeflush_test.cpp b/searchcore/src/tests/proton/attribute/attributeflush_test.cpp index b94df75c7be..a10fec131e0 100644 --- a/searchcore/src/tests/proton/attribute/attributeflush_test.cpp +++ b/searchcore/src/tests/proton/attribute/attributeflush_test.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include LOG_SETUP("attributeflush_test"); diff --git a/searchcore/src/vespa/searchcore/proton/attribute/attribute_initializer.cpp b/searchcore/src/vespa/searchcore/proton/attribute/attribute_initializer.cpp index 16be2c1bd25..d39d2873edb 100644 --- a/searchcore/src/vespa/searchcore/proton/attribute/attribute_initializer.cpp +++ b/searchcore/src/vespa/searchcore/proton/attribute/attribute_initializer.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include LOG_SETUP(".proton.attribute.attribute_initializer"); diff --git a/searchcore/src/vespa/searchcore/proton/index/index_writer.cpp b/searchcore/src/vespa/searchcore/proton/index/index_writer.cpp index 3512d2eebad..2c26b043fad 100644 --- a/searchcore/src/vespa/searchcore/proton/index/index_writer.cpp +++ b/searchcore/src/vespa/searchcore/proton/index/index_writer.cpp @@ -2,6 +2,7 @@ #include "index_writer.h" #include +#include #include LOG_SETUP(".proton.server.indexadapter"); diff --git a/searchcore/src/vespa/searchcore/proton/server/fileconfigmanager.cpp b/searchcore/src/vespa/searchcore/proton/server/fileconfigmanager.cpp index 7ee6a02d03e..e4a4e6761aa 100644 --- a/searchcore/src/vespa/searchcore/proton/server/fileconfigmanager.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/fileconfigmanager.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include diff --git a/searchcore/src/vespa/searchcore/proton/server/memory_flush_config_updater.cpp b/searchcore/src/vespa/searchcore/proton/server/memory_flush_config_updater.cpp index 50a499c8a73..3222cbc3a06 100644 --- a/searchcore/src/vespa/searchcore/proton/server/memory_flush_config_updater.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/memory_flush_config_updater.cpp @@ -2,6 +2,7 @@ #include "memory_flush_config_updater.h" #include +#include #include LOG_SETUP(".proton.server.memory_flush_config_updater"); diff --git a/searchcore/src/vespa/searchcore/proton/server/memoryflush.cpp b/searchcore/src/vespa/searchcore/proton/server/memoryflush.cpp index f8d7519fd0c..fbc6e2beaf5 100644 --- a/searchcore/src/vespa/searchcore/proton/server/memoryflush.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/memoryflush.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include LOG_SETUP(".proton.server.memoryflush"); diff --git a/searchcore/src/vespa/searchcore/proton/server/simpleflush.cpp b/searchcore/src/vespa/searchcore/proton/server/simpleflush.cpp index a1234ccc8fc..4de426b56d1 100644 --- a/searchcore/src/vespa/searchcore/proton/server/simpleflush.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/simpleflush.cpp @@ -2,15 +2,14 @@ #include "simpleflush.h" #include +#include #include LOG_SETUP(".proton.server.simpleflush"); namespace proton { -SimpleFlush::SimpleFlush() -{ -} +SimpleFlush::SimpleFlush() = default; FlushContext::List SimpleFlush::getFlushTargets(const FlushContext::List& targetList, diff --git a/searchcore/src/vespa/searchcore/proton/server/summaryadapter.cpp b/searchcore/src/vespa/searchcore/proton/server/summaryadapter.cpp index 038af801b80..b4565003e9e 100644 --- a/searchcore/src/vespa/searchcore/proton/server/summaryadapter.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/summaryadapter.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include LOG_SETUP(".proton.server.summaryadapter"); diff --git a/searchcore/src/vespa/searchcorespi/index/indexflushtarget.cpp b/searchcore/src/vespa/searchcorespi/index/indexflushtarget.cpp index e72525d0aaa..53fb21bf1ed 100644 --- a/searchcore/src/vespa/searchcorespi/index/indexflushtarget.cpp +++ b/searchcore/src/vespa/searchcorespi/index/indexflushtarget.cpp @@ -2,6 +2,7 @@ #include "indexflushtarget.h" #include +#include #include LOG_SETUP(".searchcorespi.index.indexflushtarget"); diff --git a/searchcore/src/vespa/searchcorespi/index/indexfusiontarget.cpp b/searchcore/src/vespa/searchcorespi/index/indexfusiontarget.cpp index 1df6d321f99..6755976939b 100644 --- a/searchcore/src/vespa/searchcorespi/index/indexfusiontarget.cpp +++ b/searchcore/src/vespa/searchcorespi/index/indexfusiontarget.cpp @@ -1,6 +1,7 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "indexfusiontarget.h" +#include #include LOG_SETUP(".searchcorespi.index.indexfusiontarget"); diff --git a/searchlib/src/apps/uniform/uniform.cpp b/searchlib/src/apps/uniform/uniform.cpp index 784c69f4647..807b8d61a9e 100644 --- a/searchlib/src/apps/uniform/uniform.cpp +++ b/searchlib/src/apps/uniform/uniform.cpp @@ -2,8 +2,7 @@ #include #include -#include - +#include static uint64_t maxExpGolombVal(uint64_t kValue, uint64_t maxBits) diff --git a/searchlib/src/apps/vespa-index-inspect/vespa-index-inspect.cpp b/searchlib/src/apps/vespa-index-inspect/vespa-index-inspect.cpp index a5d950c0f31..6278b216b52 100644 --- a/searchlib/src/apps/vespa-index-inspect/vespa-index-inspect.cpp +++ b/searchlib/src/apps/vespa-index-inspect/vespa-index-inspect.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -256,12 +257,12 @@ ShowPostingListSubApp::getOptions(int argc, char **argv) int c; int longopt_index = 0; static struct option longopts[] = { - { "indexdir", 1, NULL, 0 }, - { "field", 1, NULL, 0 }, - { "transpose", 0, NULL, 0 }, - { "docidlimit", 1, NULL, 0 }, - { "mindocid", 1, NULL, 0 }, - { NULL, 0, NULL, 0 } + { "indexdir", 1, nullptr, 0 }, + { "field", 1, nullptr, 0 }, + { "transpose", 0, nullptr, 0 }, + { "docidlimit", 1, nullptr, 0 }, + { "mindocid", 1, nullptr, 0 }, + { nullptr, 0, nullptr, 0 } }; enum longopts_enum { LONGOPT_INDEXDIR, @@ -293,7 +294,7 @@ ShowPostingListSubApp::getOptions(int argc, char **argv) _minDocId = atoi(optarg); break; default: - if (optarg != NULL) { + if (optarg != nullptr) { LOG(error, "longopt %s with arg %s", longopts[longopt_index].name, optarg); @@ -683,9 +684,7 @@ DumpWordsSubApp::DumpWordsSubApp() } -DumpWordsSubApp::~DumpWordsSubApp() -{ -} +DumpWordsSubApp::~DumpWordsSubApp() = default; void @@ -708,12 +707,12 @@ DumpWordsSubApp::getOptions(int argc, char **argv) int c; int longopt_index = 0; static struct option longopts[] = { - { "indexdir", 1, NULL, 0 }, - { "field", 1, NULL, 0 }, - { "minnumdocs", 1, NULL, 0 }, - { "verbose", 0, NULL, 0 }, - { "wordnum", 0, NULL, 0 }, - { NULL, 0, NULL, 0 } + { "indexdir", 1, nullptr, 0 }, + { "field", 1, nullptr, 0 }, + { "minnumdocs", 1, nullptr, 0 }, + { "verbose", 0, nullptr, 0 }, + { "wordnum", 0, nullptr, 0 }, + { nullptr, 0, nullptr, 0 } }; enum longopts_enum { LONGOPT_INDEXDIR, @@ -745,7 +744,7 @@ DumpWordsSubApp::getOptions(int argc, char **argv) _showWordNum = true; break; default: - if (optarg != NULL) { + if (optarg != nullptr) { LOG(error, "longopt %s with arg %s", longopts[longopt_index].name, optarg); diff --git a/searchlib/src/tests/attribute/postinglist/postinglist.cpp b/searchlib/src/tests/attribute/postinglist/postinglist.cpp index 3f07faa159f..7d2a89b6e5b 100644 --- a/searchlib/src/tests/attribute/postinglist/postinglist.cpp +++ b/searchlib/src/tests/attribute/postinglist/postinglist.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include LOG_SETUP("postinglist_test"); diff --git a/searchlib/src/tests/attribute/reference_attribute/reference_attribute_test.cpp b/searchlib/src/tests/attribute/reference_attribute/reference_attribute_test.cpp index b5101f1ea58..e356187a19f 100644 --- a/searchlib/src/tests/attribute/reference_attribute/reference_attribute_test.cpp +++ b/searchlib/src/tests/attribute/reference_attribute/reference_attribute_test.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include LOG_SETUP("reference_attribute_test"); diff --git a/searchlib/src/tests/bitcompression/expgolomb/expgolomb_test.cpp b/searchlib/src/tests/bitcompression/expgolomb/expgolomb_test.cpp index 5bb36a8462e..9a726f9d8a6 100644 --- a/searchlib/src/tests/bitcompression/expgolomb/expgolomb_test.cpp +++ b/searchlib/src/tests/bitcompression/expgolomb/expgolomb_test.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include LOG_SETUP("expglomb_test"); diff --git a/searchlib/src/tests/common/location_iterator/location_iterator_test.cpp b/searchlib/src/tests/common/location_iterator/location_iterator_test.cpp index 44a2f1697cd..bf372c0e62f 100644 --- a/searchlib/src/tests/common/location_iterator/location_iterator_test.cpp +++ b/searchlib/src/tests/common/location_iterator/location_iterator_test.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include LOG_SETUP("location_iterator_test"); diff --git a/searchlib/src/tests/diskindex/pagedict4/pagedict4test.cpp b/searchlib/src/tests/diskindex/pagedict4/pagedict4test.cpp index f1729f21f39..408cf370c59 100644 --- a/searchlib/src/tests/diskindex/pagedict4/pagedict4test.cpp +++ b/searchlib/src/tests/diskindex/pagedict4/pagedict4test.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include LOG_SETUP("pagedict4test"); diff --git a/searchlib/src/tests/memoryindex/datastore/feature_store_test.cpp b/searchlib/src/tests/memoryindex/datastore/feature_store_test.cpp index 564824031a6..f4dda88b6f0 100644 --- a/searchlib/src/tests/memoryindex/datastore/feature_store_test.cpp +++ b/searchlib/src/tests/memoryindex/datastore/feature_store_test.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include LOG_SETUP("feature_store_test"); diff --git a/searchlib/src/tests/sortspec/multilevelsort.cpp b/searchlib/src/tests/sortspec/multilevelsort.cpp index ec14f0c97e1..001903ff302 100644 --- a/searchlib/src/tests/sortspec/multilevelsort.cpp +++ b/searchlib/src/tests/sortspec/multilevelsort.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include LOG_SETUP("multilevelsort_test"); diff --git a/searchlib/src/vespa/searchlib/common/bitvectorcache.cpp b/searchlib/src/vespa/searchlib/common/bitvectorcache.cpp index cb4d112b77e..8bb24bcbbec 100644 --- a/searchlib/src/vespa/searchlib/common/bitvectorcache.cpp +++ b/searchlib/src/vespa/searchlib/common/bitvectorcache.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include LOG_SETUP(".searchlib.common.bitvectorcache"); diff --git a/searchlib/src/vespa/searchlib/diskindex/fileheader.cpp b/searchlib/src/vespa/searchlib/diskindex/fileheader.cpp index e1c31c1ed8d..5399d70fbe7 100644 --- a/searchlib/src/vespa/searchlib/diskindex/fileheader.cpp +++ b/searchlib/src/vespa/searchlib/diskindex/fileheader.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include diff --git a/searchlib/src/vespa/searchlib/docstore/compacter.cpp b/searchlib/src/vespa/searchlib/docstore/compacter.cpp index 04ff150c741..c886e52659f 100644 --- a/searchlib/src/vespa/searchlib/docstore/compacter.cpp +++ b/searchlib/src/vespa/searchlib/docstore/compacter.cpp @@ -4,6 +4,7 @@ #include "logdatastore.h" #include #include +#include #include LOG_SETUP(".searchlib.docstore.compacter"); diff --git a/searchlib/src/vespa/searchlib/engine/proto_converter.cpp b/searchlib/src/vespa/searchlib/engine/proto_converter.cpp index ae00889850b..b03dbf5ff37 100644 --- a/searchlib/src/vespa/searchlib/engine/proto_converter.cpp +++ b/searchlib/src/vespa/searchlib/engine/proto_converter.cpp @@ -6,8 +6,9 @@ #include #include #include -#include +#include +#include LOG_SETUP(".searchlib.engine.proto_converter"); namespace search::engine { diff --git a/searchlib/src/vespa/searchlib/features/random_normal_feature.cpp b/searchlib/src/vespa/searchlib/features/random_normal_feature.cpp index 91ccd390692..ad92f8ef6e0 100644 --- a/searchlib/src/vespa/searchlib/features/random_normal_feature.cpp +++ b/searchlib/src/vespa/searchlib/features/random_normal_feature.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include LOG_SETUP(".features.randomnormalfeature"); diff --git a/searchlib/src/vespa/searchlib/features/random_normal_stable_feature.cpp b/searchlib/src/vespa/searchlib/features/random_normal_stable_feature.cpp index f7fcffca8cb..f1a42da1266 100644 --- a/searchlib/src/vespa/searchlib/features/random_normal_stable_feature.cpp +++ b/searchlib/src/vespa/searchlib/features/random_normal_stable_feature.cpp @@ -4,6 +4,7 @@ #include "utils.h" #include #include +#include #include LOG_SETUP(".features.randomnormalstablefeature"); diff --git a/searchlib/src/vespa/searchlib/features/randomfeature.cpp b/searchlib/src/vespa/searchlib/features/randomfeature.cpp index a8f2dd275a7..30a313d54d2 100644 --- a/searchlib/src/vespa/searchlib/features/randomfeature.cpp +++ b/searchlib/src/vespa/searchlib/features/randomfeature.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include LOG_SETUP(".features.randomfeature"); diff --git a/searchlib/src/vespa/searchlib/predicate/predicate_range_term_expander.h b/searchlib/src/vespa/searchlib/predicate/predicate_range_term_expander.h index 42de8646091..6a6b91e20f2 100644 --- a/searchlib/src/vespa/searchlib/predicate/predicate_range_term_expander.h +++ b/searchlib/src/vespa/searchlib/predicate/predicate_range_term_expander.h @@ -5,6 +5,7 @@ #include #include #include +#include namespace search::predicate { diff --git a/searchlib/src/vespa/searchlib/test/fakedata/fakeegcompr64filterocc.cpp b/searchlib/src/vespa/searchlib/test/fakedata/fakeegcompr64filterocc.cpp index e3cf067bd49..6bba9d96d02 100644 --- a/searchlib/src/vespa/searchlib/test/fakedata/fakeegcompr64filterocc.cpp +++ b/searchlib/src/vespa/searchlib/test/fakedata/fakeegcompr64filterocc.cpp @@ -5,6 +5,7 @@ #include "bitdecode64.h" #include "fpfactory.h" #include +#include #include LOG_SETUP(".searchlib.test.fake_eg_compr64_filter_occ"); diff --git a/searchlib/src/vespa/searchlib/transactionlog/session.cpp b/searchlib/src/vespa/searchlib/transactionlog/session.cpp index b11f4027ae7..ec77a5f150e 100644 --- a/searchlib/src/vespa/searchlib/transactionlog/session.cpp +++ b/searchlib/src/vespa/searchlib/transactionlog/session.cpp @@ -4,6 +4,7 @@ #include "domainpart.h" #include #include +#include #include LOG_SETUP(".transactionlog.session"); diff --git a/searchlib/src/vespa/searchlib/util/filesizecalculator.cpp b/searchlib/src/vespa/searchlib/util/filesizecalculator.cpp index 16a96c7b439..c50d402db0e 100644 --- a/searchlib/src/vespa/searchlib/util/filesizecalculator.cpp +++ b/searchlib/src/vespa/searchlib/util/filesizecalculator.cpp @@ -2,6 +2,7 @@ #include "filesizecalculator.h" #include +#include #include LOG_SETUP(".searchlib.util.filesizecalculator"); diff --git a/searchlib/src/vespa/searchlib/util/url.cpp b/searchlib/src/vespa/searchlib/util/url.cpp index 5eeb16e3f3b..141f54363e9 100644 --- a/searchlib/src/vespa/searchlib/util/url.cpp +++ b/searchlib/src/vespa/searchlib/util/url.cpp @@ -3,6 +3,7 @@ #include "url.h" #include #include +#include #include LOG_SETUP(".searchlib.util.url"); diff --git a/searchsummary/src/vespa/juniper/Matcher.cpp b/searchsummary/src/vespa/juniper/Matcher.cpp index 22d1bbc7e96..73362aac5a3 100644 --- a/searchsummary/src/vespa/juniper/Matcher.cpp +++ b/searchsummary/src/vespa/juniper/Matcher.cpp @@ -1,7 +1,5 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include -#include #include "query.h" #include "juniperdebug.h" #include "sumdesc.h" @@ -10,6 +8,10 @@ #include "juniperparams.h" #include "config.h" #include +#include +#include +#include + #include LOG_SETUP(".juniper.matcher"); diff --git a/searchsummary/src/vespa/juniper/sumdesc.cpp b/searchsummary/src/vespa/juniper/sumdesc.cpp index 18e1b7bbd11..aa6aededa0c 100644 --- a/searchsummary/src/vespa/juniper/sumdesc.cpp +++ b/searchsummary/src/vespa/juniper/sumdesc.cpp @@ -6,6 +6,7 @@ #include "Matcher.h" #include "appender.h" #include +#include #include LOG_SETUP(".juniper.sumdesc"); diff --git a/searchsummary/src/vespa/juniper/tokenizer.cpp b/searchsummary/src/vespa/juniper/tokenizer.cpp index 1b58be2d451..965befe01e3 100644 --- a/searchsummary/src/vespa/juniper/tokenizer.cpp +++ b/searchsummary/src/vespa/juniper/tokenizer.cpp @@ -3,6 +3,7 @@ #include "tokenizer.h" #include "juniperdebug.h" #include +#include #include LOG_SETUP(".juniper.tokenizer"); diff --git a/storage/src/vespa/storage/distributor/messagetracker.cpp b/storage/src/vespa/storage/distributor/messagetracker.cpp index 93db31bdc29..8830e5ecabc 100644 --- a/storage/src/vespa/storage/distributor/messagetracker.cpp +++ b/storage/src/vespa/storage/distributor/messagetracker.cpp @@ -3,6 +3,7 @@ #include "messagetracker.h" #include #include +#include #include LOG_SETUP(".messagetracker"); diff --git a/storage/src/vespa/storage/distributor/operations/external/twophaseupdateoperation.cpp b/storage/src/vespa/storage/distributor/operations/external/twophaseupdateoperation.cpp index 55fe2e039e1..bdf4fa2ba72 100644 --- a/storage/src/vespa/storage/distributor/operations/external/twophaseupdateoperation.cpp +++ b/storage/src/vespa/storage/distributor/operations/external/twophaseupdateoperation.cpp @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include LOG_SETUP(".distributor.callback.twophaseupdate"); diff --git a/storage/src/vespa/storage/distributor/sentmessagemap.cpp b/storage/src/vespa/storage/distributor/sentmessagemap.cpp index 44dd4fbde89..4b7292c1e81 100644 --- a/storage/src/vespa/storage/distributor/sentmessagemap.cpp +++ b/storage/src/vespa/storage/distributor/sentmessagemap.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include LOG_SETUP(".distributor.callback.map"); diff --git a/storage/src/vespa/storageframework/defaultimplementation/thread/threadimpl.cpp b/storage/src/vespa/storageframework/defaultimplementation/thread/threadimpl.cpp index 314434a4c1a..c1fa2aac708 100644 --- a/storage/src/vespa/storageframework/defaultimplementation/thread/threadimpl.cpp +++ b/storage/src/vespa/storageframework/defaultimplementation/thread/threadimpl.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include LOG_SETUP(".framework.thread.impl"); diff --git a/vespalib/src/tests/btree/iteratespeed.cpp b/vespalib/src/tests/btree/iteratespeed.cpp index fceaf01a785..48c4b4a1c39 100644 --- a/vespalib/src/tests/btree/iteratespeed.cpp +++ b/vespalib/src/tests/btree/iteratespeed.cpp @@ -1,10 +1,8 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include #include #include #include -#include #include #include #include @@ -12,11 +10,10 @@ #include #include #include -#include #include #include #include - +#include #include #include diff --git a/vespalib/src/tests/datastore/datastore/datastore_test.cpp b/vespalib/src/tests/datastore/datastore/datastore_test.cpp index 645871d3ef6..e17ac94775e 100644 --- a/vespalib/src/tests/datastore/datastore/datastore_test.cpp +++ b/vespalib/src/tests/datastore/datastore/datastore_test.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include LOG_SETUP("datastore_test"); diff --git a/vespalib/src/tests/util/generationhandler_stress/generation_handler_stress_test.cpp b/vespalib/src/tests/util/generationhandler_stress/generation_handler_stress_test.cpp index 1cc54da7f2e..4abae54e06f 100644 --- a/vespalib/src/tests/util/generationhandler_stress/generation_handler_stress_test.cpp +++ b/vespalib/src/tests/util/generationhandler_stress/generation_handler_stress_test.cpp @@ -1,12 +1,15 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include -LOG_SETUP("generation_handler_stress_test"); + #include #include #include #include #include #include +#include + +#include +LOG_SETUP("generation_handler_stress_test"); using vespalib::Executor; using vespalib::GenerationHandler; diff --git a/vespalib/src/vespa/vespalib/data/slime/json_format.cpp b/vespalib/src/vespa/vespalib/data/slime/json_format.cpp index 2681ba6f52b..9cda8a7fae1 100644 --- a/vespalib/src/vespa/vespalib/data/slime/json_format.cpp +++ b/vespalib/src/vespa/vespalib/data/slime/json_format.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include diff --git a/vespalib/src/vespa/vespalib/net/native_epoll.cpp b/vespalib/src/vespa/vespalib/net/native_epoll.cpp index 1e68826a145..8b73b092ab2 100644 --- a/vespalib/src/vespa/vespalib/net/native_epoll.cpp +++ b/vespalib/src/vespa/vespalib/net/native_epoll.cpp @@ -3,6 +3,7 @@ #include "native_epoll.h" #include #include +#include #include #include diff --git a/vespalib/src/vespa/vespalib/util/process_memory_stats.cpp b/vespalib/src/vespa/vespalib/util/process_memory_stats.cpp index f7e8e087727..41f1e282c4b 100644 --- a/vespalib/src/vespa/vespalib/util/process_memory_stats.cpp +++ b/vespalib/src/vespa/vespalib/util/process_memory_stats.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include diff --git a/vespalog/src/logctl/logctl.cpp b/vespalog/src/logctl/logctl.cpp index 4cf44e9cd22..9a8987fc462 100644 --- a/vespalog/src/logctl/logctl.cpp +++ b/vespalog/src/logctl/logctl.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -16,7 +17,7 @@ LOG_SETUP("vespa-logctl"); using namespace ns_log; static void modifyLevels(const char *file, const char *component, const char *levels, - bool shouldCreateFile, bool shouldCreateEntry); + bool shouldCreateFile, bool shouldCreateEntry); static void readLevels(const char *file, const char *component); diff --git a/vespalog/src/logger/llreader.cpp b/vespalog/src/logger/llreader.cpp index cb25b6747bf..200f4bb039d 100644 --- a/vespalog/src/logger/llreader.cpp +++ b/vespalog/src/logger/llreader.cpp @@ -1,17 +1,12 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include -#include -#include -#include -#include -#include -#include #include "llreader.h" +#include +#include +#include namespace ns_log { - InputBuf::InputBuf(int fd) : _inputfd(fd), _size(1000), diff --git a/vespalog/src/test/bufferedlogskiptest.cpp b/vespalog/src/test/bufferedlogskiptest.cpp index abb5705b612..29e5e119c34 100644 --- a/vespalog/src/test/bufferedlogskiptest.cpp +++ b/vespalog/src/test/bufferedlogskiptest.cpp @@ -1,6 +1,7 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include +#include #include #include @@ -15,7 +16,9 @@ using namespace std::literals::chrono_literals; struct TestTimer : public ns_log::Timer { uint64_t & _time; TestTimer(uint64_t & timeVar) : _time(timeVar) { } - ns_log::system_time getTimestamp() const override { return ns_log::system_time(std::chrono::microseconds(_time)); } + ns_log::system_time getTimestamp() const noexcept override { + return ns_log::system_time(std::chrono::microseconds(_time)); + } }; std::string readFile(const std::string& file) { @@ -71,8 +74,8 @@ void testSkipBufferOnDebug(const std::string& file, uint64_t & timer) void reset(uint64_t & timer) { timer = 0; ns_log::BufferedLogger::instance().setMaxCacheSize(10); - ns_log::BufferedLogger::instance().setMaxEntryAge(300s); - ns_log::BufferedLogger::instance().setCountFactor(5s); + ns_log::BufferedLogger::instance().setMaxEntryAge(300); + ns_log::BufferedLogger::instance().setCountFactor(5); } int diff --git a/vespalog/src/test/bufferedlogtest.cpp b/vespalog/src/test/bufferedlogtest.cpp index d3fc1c28d63..a2dfdd7c6b8 100644 --- a/vespalog/src/test/bufferedlogtest.cpp +++ b/vespalog/src/test/bufferedlogtest.cpp @@ -1,6 +1,7 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include +#include #include "bufferedlogtest.logger1.h" #include "bufferedlogtest.logger2.h" @@ -19,7 +20,9 @@ using namespace std::literals::chrono_literals; struct TestTimer : public ns_log::Timer { uint64_t & _time; TestTimer(uint64_t & timeVar) : _time(timeVar) { } - ns_log::system_time getTimestamp() const override { return ns_log::system_time(std::chrono::microseconds(_time)); } + ns_log::system_time getTimestamp() const noexcept override { + return ns_log::system_time(std::chrono::microseconds(_time)); + } }; std::string readFile(const std::string& file) { @@ -122,9 +125,9 @@ void testThatEntriesWithHighCountsAreEventuallyRemoved( // Should eventually throw out the entries with high count timer = 10 * 1000000 + 4; // Make sure we don't remove due to age. - ns_log::BufferedLogger::instance().setMaxEntryAge(1000000s); + ns_log::BufferedLogger::instance().setMaxEntryAge(1000000); // Let each count, count for 5 seconds. - ns_log::BufferedLogger::instance().setCountFactor(5s); + ns_log::BufferedLogger::instance().setCountFactor(5); LOGBM(info, "Starting up, using logfile %s", file.c_str()); timer = 100 * 1000000 + 4; @@ -157,9 +160,9 @@ void testThatEntriesExpire( // Test that we don't keep entries longer than max age timer = 10 * 1000000 + 4; // Time out after 120 seconds - ns_log::BufferedLogger::instance().setMaxEntryAge(120s); + ns_log::BufferedLogger::instance().setMaxEntryAge(120); // Let counts count much, so they expire due to time instead - ns_log::BufferedLogger::instance().setCountFactor(100000s); + ns_log::BufferedLogger::instance().setCountFactor(100000); LOGBM(info, "Starting up, using logfile %s", file.c_str()); timer = 100 * 1000000 + 4; @@ -227,9 +230,9 @@ void testThatHighCountEntriesDontStarveOthers( std::cerr << "testThatHighCountEntriesDontStarveOthers ...\n"; timer = 10 * 1000000 + 4; // Long time out, we don't want to rely on timeout to prevent starvation - ns_log::BufferedLogger::instance().setMaxEntryAge(12000000s); + ns_log::BufferedLogger::instance().setMaxEntryAge(12000000); // Let counts count much, so they score high - ns_log::BufferedLogger::instance().setCountFactor(100000s); + ns_log::BufferedLogger::instance().setCountFactor(100000); LOGBM(info, "Starting up, using logfile %s", file.c_str()); timer = 100 * 1000000; @@ -382,8 +385,8 @@ void testNonBufferedLoggerTriggersBufferedLogTrim(const std::string& file, void reset(uint64_t& timer) { timer = 0; - ns_log::BufferedLogger::instance().setMaxEntryAge(300s); - ns_log::BufferedLogger::instance().setCountFactor(5s); + ns_log::BufferedLogger::instance().setMaxEntryAge(300); + ns_log::BufferedLogger::instance().setCountFactor(5); } int diff --git a/vespalog/src/test/threads/testthreads.cpp b/vespalog/src/test/threads/testthreads.cpp index 0c9b3a1cdb2..6a9d5c18a18 100644 --- a/vespalog/src/test/threads/testthreads.cpp +++ b/vespalog/src/test/threads/testthreads.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include using std::string; diff --git a/vespalog/src/vespa/log/bufferedlogger.cpp b/vespalog/src/vespa/log/bufferedlogger.cpp index 7ad878a568c..c589e0ae424 100644 --- a/vespalog/src/vespa/log/bufferedlogger.cpp +++ b/vespalog/src/vespa/log/bufferedlogger.cpp @@ -1,9 +1,9 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "bufferedlogger.h" +#include "internal.h" #include #include -#include #include #include #include @@ -208,16 +208,25 @@ BufferedLogger::~BufferedLogger() } namespace { - typedef boost::multi_index::nth_index< - BackingBuffer::LogCacheFront, 0>::type LogCacheFrontTimestamp; - typedef boost::multi_index::nth_index< - BackingBuffer::LogCacheFront, 1>::type LogCacheFrontToken; - typedef boost::multi_index::nth_index< - BackingBuffer::LogCacheBack, 0>::type LogCacheBackTimestamp; - typedef boost::multi_index::nth_index< - BackingBuffer::LogCacheBack, 1>::type LogCacheBackToken; - typedef boost::multi_index::nth_index< - BackingBuffer::LogCacheBack, 2>::type LogCacheBackAge; + +typedef boost::multi_index::nth_index< + BackingBuffer::LogCacheFront, 0>::type LogCacheFrontTimestamp; +typedef boost::multi_index::nth_index< + BackingBuffer::LogCacheFront, 1>::type LogCacheFrontToken; +typedef boost::multi_index::nth_index< + BackingBuffer::LogCacheBack, 0>::type LogCacheBackTimestamp; +typedef boost::multi_index::nth_index< + BackingBuffer::LogCacheBack, 1>::type LogCacheBackToken; +typedef boost::multi_index::nth_index< + BackingBuffer::LogCacheBack, 2>::type LogCacheBackAge; + +struct TimeStampWrapper : public Timer { + TimeStampWrapper(system_time timeStamp) : _timeStamp(timeStamp) {} + system_time getTimestamp() const noexcept override { return _timeStamp; } + + system_time _timeStamp; +}; + } void @@ -260,7 +269,7 @@ BackingBuffer::logImpl(Logger& l, Logger::LogLevel level, _cacheBack.get<1>().replace(it2, copy); } else { // If entry didn't already exist, add it to the cache and log it - l.doLogCore(entry._timestamp, level, file, line, message.c_str(), message.size()); + l.doLogCore(TimeStampWrapper(entry._timestamp), level, file, line, message.c_str(), message.size()); _cacheFront.push_back(entry); } trimCache(entry._timestamp); @@ -335,7 +344,7 @@ BackingBuffer::log(const Entry& e) const << " times since " << count_s(e._timestamp.time_since_epoch()) << "." << std::setw(6) << std::setfill('0') << (count_us(e._timestamp.time_since_epoch()) % 1000000) << ")"; - e._logger->doLogCore(_timer->getTimestamp(), e._level, e._file.c_str(), + e._logger->doLogCore(*_timer, e._level, e._file.c_str(), e._line, ost.str().c_str(), ost.str().size()); } } @@ -367,13 +376,13 @@ BufferedLogger::setMaxCacheSize(uint32_t size) { } void -BufferedLogger::setMaxEntryAge(duration maxAge) { - _backing->_maxEntryAge = maxAge; +BufferedLogger::setMaxEntryAge(uint64_t seconds) { + _backing->_maxEntryAge = std::chrono::seconds(seconds); } void -BufferedLogger::setCountFactor(duration factor) { - _backing->_countFactor = factor; +BufferedLogger::setCountFactor(uint64_t seconds) { + _backing->_countFactor = std::chrono::seconds(seconds); } /** Set a fake timer to use for log messages. Used in unit testing. */ diff --git a/vespalog/src/vespa/log/bufferedlogger.h b/vespalog/src/vespa/log/bufferedlogger.h index 31e194e63bb..f3aee2fb3f6 100644 --- a/vespalog/src/vespa/log/bufferedlogger.h +++ b/vespalog/src/vespa/log/bufferedlogger.h @@ -167,10 +167,10 @@ class BackingBuffer; class BufferedLogger { BackingBuffer *_backing; - BufferedLogger(const BufferedLogger & buf); - BufferedLogger & operator = (const BufferedLogger & buf); public: + BufferedLogger(const BufferedLogger & buf) = delete; + BufferedLogger & operator = (const BufferedLogger & buf) = delete; BufferedLogger(); ~BufferedLogger(); @@ -178,8 +178,8 @@ public: // to easier be able to test all aspects of the buffer, and be independent // of the default settings for applications void setMaxCacheSize(uint32_t size); - void setMaxEntryAge(duration seconds); - void setCountFactor(duration factor); + void setMaxEntryAge(uint64_t seconds); + void setCountFactor(uint64_t seconds); void doLog(Logger&, Logger::LogLevel level, const char *file, int line, const std::string& token, @@ -188,9 +188,6 @@ public: /** Empty buffer and write all log entries in it. */ void flush(); - /** Gives all current content of log buffer. Useful for debugging. */ - std::string toString() const; - /** Set a fake timer to use for log messages. Used in unit testing. */ void setTimer(std::unique_ptr timer); diff --git a/vespalog/src/vespa/log/component.cpp b/vespalog/src/vespa/log/component.cpp index 009a69ad0c5..36b1d15e457 100644 --- a/vespalog/src/vespa/log/component.cpp +++ b/vespalog/src/vespa/log/component.cpp @@ -9,6 +9,7 @@ LOG_SETUP_INDIRECT(".log.control", "$Id$"); #include "component.h" #include "control-file.h" #include "internal.h" +#include namespace ns_log { diff --git a/vespalog/src/vespa/log/internal.h b/vespalog/src/vespa/log/internal.h index c25c7cc44b6..7e6bf16f39f 100644 --- a/vespalog/src/vespa/log/internal.h +++ b/vespalog/src/vespa/log/internal.h @@ -3,6 +3,7 @@ #include #include +#include namespace ns_log { @@ -20,4 +21,24 @@ public: [[nodiscard]] const char *what() const { return _what.c_str(); } }; +using system_time = std::chrono::system_clock::time_point; +using duration = std::chrono::nanoseconds; + +constexpr int64_t +count_s(duration d) noexcept { + return std::chrono::duration_cast(d).count(); +} + +constexpr int64_t +count_us(duration d) noexcept { + return std::chrono::duration_cast(d).count(); +} + +// XXX this is way too complicated, must be some simpler way to do this +/** Timer class used to retrieve timestamp, such that we can override in test */ +struct Timer { + virtual ~Timer() = default; + virtual system_time getTimestamp() const noexcept; +}; + } // end namespace ns_log diff --git a/vespalog/src/vespa/log/llparser.cpp b/vespalog/src/vespa/log/llparser.cpp index 1585b9fde33..063220e50ef 100644 --- a/vespalog/src/vespa/log/llparser.cpp +++ b/vespalog/src/vespa/log/llparser.cpp @@ -4,6 +4,7 @@ #include "llparser.h" #include "internal.h" #include +#include #include #include #include diff --git a/vespalog/src/vespa/log/log-target-file.cpp b/vespalog/src/vespa/log/log-target-file.cpp index 4337d6b5bbb..87a9810e3c7 100644 --- a/vespalog/src/vespa/log/log-target-file.cpp +++ b/vespalog/src/vespa/log/log-target-file.cpp @@ -1,15 +1,15 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include "log.h" +LOG_SETUP(".log"); +#include "log-target-file.h" +#include "internal.h" + #include #include #include #include #include -#include "log.h" -LOG_SETUP(".log"); -#include "log-target-file.h" -#include "internal.h" - namespace ns_log { #ifndef O_LARGEFILE diff --git a/vespalog/src/vespa/log/log.cpp b/vespalog/src/vespa/log/log.cpp index 9ca993b84fc..73cbeef08aa 100644 --- a/vespalog/src/vespa/log/log.cpp +++ b/vespalog/src/vespa/log/log.cpp @@ -6,7 +6,6 @@ LOG_SETUP_INDIRECT(".log", "$Id$"); #undef LOG #define LOG LOG_INDIRECT -#include "lock.h" #include "log-target.h" #include "internal.h" #include "control-file.h" @@ -15,13 +14,15 @@ LOG_SETUP_INDIRECT(".log", "$Id$"); #include #include #include +#include +#include #include #include namespace ns_log { system_time -Timer::getTimestamp() const { +Timer::getTimestamp() const noexcept { return std::chrono::system_clock::now(); } @@ -131,7 +132,7 @@ Logger::ensureHostname() Logger::Logger(const char *name, const char *rcsId) : _logLevels(ControlFile::defaultLevels()), - _timer(new Timer()) + _timer(std::make_unique()) { _numInstances++; memset(_rcsId, 0, sizeof(_rcsId)); @@ -168,7 +169,6 @@ Logger::Logger(const char *name, const char *rcsId) } } - Logger::~Logger() { _numInstances--; @@ -186,6 +186,10 @@ Logger::~Logger() } } +void +Logger::setTimer(std::unique_ptr timer) { + _timer = std::move(timer); +} int Logger::setRcsId(const char *id) @@ -216,7 +220,7 @@ Logger::tryLog(int sizeofPayload, LogLevel level, const char *file, int line, co const int actualSize = vsnprintf(payload, sizeofPayload, fmt, args); if (actualSize < sizeofPayload) { - doLogCore(_timer->getTimestamp(), level, file, line, payload, actualSize); + doLogCore(*_timer, level, file, line, payload, actualSize); } delete[] payload; return actualSize; @@ -238,9 +242,10 @@ Logger::doLog(LogLevel level, const char *file, int line, const char *fmt, ...) } void -Logger::doLogCore(system_time timestamp, LogLevel level, +Logger::doLogCore(const Timer & timer, LogLevel level, const char *file, int line, const char *msg, size_t msgSize) { + system_time timestamp = timer.getTimestamp(); const size_t sizeofEscapedPayload(msgSize*4+1); const size_t sizeofTotalMessage(sizeofEscapedPayload + 1000); auto escapedPayload = std::make_unique(sizeofEscapedPayload); @@ -349,35 +354,20 @@ Logger::doEventStarted(const char *name) void Logger::doEventStopped(const char *name, pid_t pid, int exitCode) { - doLog(event, "", 0, "stopped/1 name=\"%s\" pid=%d exitcode=%d", name, - static_cast(pid), exitCode); -} - -void -Logger::doEventReloading(const char *name) -{ - doLog(event, "", 0, "reloading/1 name=\"%s\"", name); -} - -void -Logger::doEventReloaded(const char *name) -{ - doLog(event, "", 0, "reloaded/1 name=\"%s\"", name); + doLog(event, "", 0, "stopped/1 name=\"%s\" pid=%d exitcode=%d", name, static_cast(pid), exitCode); } void Logger::doEventCrash(const char *name, pid_t pid, int signal) { - doLog(event, "", 0, "crash/1 name=\"%s\" pid=%d signal=\"%s\"", name, pid, - strsignal(signal)); + doLog(event, "", 0, "crash/1 name=\"%s\" pid=%d signal=\"%s\"", name, pid, strsignal(signal)); } void Logger::doEventProgress(const char *name, double value, double total) { if (total > 0) { - doLog(event, "", 0, "progress/1 name=\"%s\" value=%.18g total=%.18g", - name, value, total); + doLog(event, "", 0, "progress/1 name=\"%s\" value=%.18g total=%.18g", name, value, total); } else { doLog(event, "", 0, "progress/1 name=\"%s\" value=%.18g", name, value); } diff --git a/vespalog/src/vespa/log/log.h b/vespalog/src/vespa/log/log.h index 88d24ba7e18..857bf4f2b97 100644 --- a/vespalog/src/vespa/log/log.h +++ b/vespalog/src/vespa/log/log.h @@ -2,17 +2,9 @@ #pragma once #include -#include #include // for placement new -#include // for malloc -#include // for memset -#include // for va_list -#include -#include #include // for pid_t - - /** * If this macro is defined, the regular LOG calls will go through the * buffered logger, using the whole messages as tokens. @@ -27,7 +19,7 @@ static ns_log::Logger ns_log_logger(__VA_ARGS__) // NOLINT #define LOG_SETUP_INDIRECT(x, id) \ -static ns_log::Logger *ns_log_indirect_logger=NULL; \ +static ns_log::Logger *ns_log_indirect_logger=nullptr; \ static bool logInitialised = false; \ static const char *logName = x; \ static const char *indirectRcsId = id @@ -37,9 +29,6 @@ static const char *indirectRcsId = id #define LOG_INDIRECT_WOULD_LOG(levelName) \ ns_log_indirect_logger->wants(ns_log::Logger::levelName) -#define LOG_RCSID(x) \ -static int log_dummmy __attribute__((unused)) = ns_log_logger.setRcsId(x) - // Define LOG if not using log buffer. Otherwise log buffer will define them #ifndef VESPA_LOG_USELOGBUFFERFORREGULARLOG #define LOG(level, ...) \ @@ -147,25 +136,7 @@ namespace ns_log { class LogTarget; class ControlFile; -using system_time = std::chrono::system_clock::time_point; -using duration = std::chrono::nanoseconds; - -constexpr int64_t -count_s(duration d) { - return std::chrono::duration_cast(d).count(); -} - -constexpr int64_t -count_us(duration d) { - return std::chrono::duration_cast(d).count(); -} - -// XXX this is way too complicated, must be some simpler way to do this -/** Timer class used to retrieve timestamp, such that we can override in test */ -struct Timer { - virtual ~Timer() = default; - virtual system_time getTimestamp() const; -}; +struct Timer; class Logger { public: @@ -182,9 +153,6 @@ public: static bool fakePid; private: - Logger(const Logger &); - Logger& operator =(const Logger &); - unsigned int *_logLevels; static char _prefix[64]; @@ -214,6 +182,8 @@ private: public: ~Logger(); explicit Logger(const char *name, const char *rcsId = nullptr); + Logger(const Logger &) = delete; + Logger & operator=(const Logger &) = delete; int setRcsId(const char *rcsId); static const char *levelName(LogLevel level); @@ -227,14 +197,12 @@ public: * * @param timestamp Time in microseconds. */ - void doLogCore(system_time timestamp, LogLevel level, + void doLogCore(const Timer &, LogLevel level, const char *file, int line, const char *msg, size_t msgSize); void doEventStarting(const char *name); void doEventStopping(const char *name, const char *why); void doEventStarted(const char *name); void doEventStopped(const char *name, pid_t pid, int exitCode); - void doEventReloading(const char *name); - void doEventReloaded(const char *name); void doEventCrash(const char *name, pid_t pid, int signal); void doEventProgress(const char *name, double value, double total = 0); void doEventCount(const char *name, uint64_t value); @@ -242,7 +210,7 @@ public: void doEventState(const char *name, const char *value); // Only for unit testing - void setTimer(std::unique_ptr timer) { _timer = std::move(timer); } + void setTimer(std::unique_ptr timer); // Only for internal use static LogTarget *getCurrentTarget(); -- cgit v1.2.3 From f78e5a0a44d6edf3d0c0da20b412a499140a6607 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Wed, 1 Mar 2023 16:44:41 +0000 Subject: c++11 way of iterating. --- vespalog/src/vespa/log/bufferedlogger.cpp | 32 ++++++++++--------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/vespalog/src/vespa/log/bufferedlogger.cpp b/vespalog/src/vespa/log/bufferedlogger.cpp index c589e0ae424..7123d1bb5fa 100644 --- a/vespalog/src/vespa/log/bufferedlogger.cpp +++ b/vespalog/src/vespa/log/bufferedlogger.cpp @@ -193,9 +193,7 @@ BackingBuffer::BackingBuffer() { } -BackingBuffer::~BackingBuffer() -{ -} +BackingBuffer::~BackingBuffer() = default; BufferedLogger::BufferedLogger() { @@ -279,16 +277,12 @@ void BackingBuffer::flush() { std::lock_guard guard(_mutex); - for (LogCacheBack::const_iterator it = _cacheBack.begin(); - it != _cacheBack.end(); ++it) - { - log(*it); + for (const auto & entry : _cacheBack) { + log(entry); } _cacheBack.clear(); - for (LogCacheFront::const_iterator it = _cacheFront.begin(); - it != _cacheFront.end(); ++it) - { - log(*it); + for (const auto & entry : _cacheFront) { + log(entry); } _cacheFront.clear(); } @@ -321,9 +315,7 @@ BackingBuffer::trimCache(system_time currentTime) _cacheBack.push_back(e); } // Remove entries from back based on count modified age. - for (uint32_t i = _cacheFront.size() + _cacheBack.size(); - i > _maxCacheSize; --i) - { + for (uint32_t i = _cacheFront.size() + _cacheBack.size(); i > _maxCacheSize; --i) { log(*_cacheBack.get<2>().begin()); _cacheBack.get<2>().erase(_cacheBack.get<2>().begin()); } @@ -355,16 +347,12 @@ BackingBuffer::toString() const std::ostringstream ost; ost << "Front log cache content:\n"; std::lock_guard guard(_mutex); - for (LogCacheFront::const_iterator it = _cacheFront.begin(); - it != _cacheFront.end(); ++it) - { - ost << " " << it->toString() << "\n"; + for (const auto & entry : _cacheFront) { + ost << " " << entry.toString() << "\n"; } ost << "Back log cache content:\n"; - for (LogCacheBack::const_iterator it = _cacheBack.begin(); - it != _cacheBack.end(); ++it) - { - ost << " " << it->toString() << "\n"; + for (const auto & entry : _cacheBack) { + ost << " " << entry.toString() << "\n"; } return ost.str(); } -- cgit v1.2.3