You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by sw...@apache.org on 2024/01/23 21:00:56 UTC

(logging-log4cxx) branch lazy_pool_creation created (now c43faa20)

This is an automated email from the ASF dual-hosted git repository.

swebb2066 pushed a change to branch lazy_pool_creation
in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git


      at c43faa20 Reduce logging overhead more

This branch includes the following new commits:

     new c43faa20 Reduce logging overhead more

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(logging-log4cxx) 01/01: Reduce logging overhead more

Posted by sw...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

swebb2066 pushed a commit to branch lazy_pool_creation
in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git

commit c43faa20caf79adc2c944c367f47bc527264f826
Author: Stephen Webb <sw...@gmail.com>
AuthorDate: Wed Jan 24 08:00:36 2024 +1100

    Reduce logging overhead more
---
 src/main/cpp/logger.cpp                 | 29 ++++++++++++-----------------
 src/main/cpp/pool.cpp                   | 31 ++++++++++++++++++++++++-------
 src/main/include/log4cxx/helpers/pool.h |  1 +
 3 files changed, 37 insertions(+), 24 deletions(-)

diff --git a/src/main/cpp/logger.cpp b/src/main/cpp/logger.cpp
index dc1dad90..1b46ccf1 100644
--- a/src/main/cpp/logger.cpp
+++ b/src/main/cpp/logger.cpp
@@ -44,8 +44,7 @@ struct Logger::LoggerPrivate
 		name(name1),
 		repositoryRaw(0),
 		aai(p),
-		additive(true),
-		pool(p) {}
+		additive(true) {}
 
 	/**
 	The name of this logger.
@@ -83,10 +82,6 @@ struct Logger::LoggerPrivate
 	        have their additivity flag set to <code>false</code> too. See
 	        the user manual for more details. */
 	bool additive;
-
-	/** A reference to the Pool held by the LoggerRepository
-	 */
-	Pool& pool;
 };
 
 IMPLEMENT_LOG4CXX_OBJECT(Logger)
@@ -169,7 +164,7 @@ void Logger::addEvent(const LevelPtr& level, std::string&& message, const Locati
 	LOG4CXX_DECODE_CHAR(msg, message);
 	auto event = std::make_shared<LoggingEvent>(m_priv->name, level, location, std::move(msg));
 #endif
-	Pool p(m_priv->pool.create(), true);
+	Pool p;
 	callAppenders(event, p);
 }
 
@@ -184,7 +179,7 @@ void Logger::forcedLog(const LevelPtr& level, const std::string& message,
 	LOG4CXX_DECODE_CHAR(msg, message);
 	auto event = std::make_shared<LoggingEvent>(m_priv->name, level, location, std::move(msg));
 #endif
-	Pool p(m_priv->pool.create(), true);
+	Pool p;
 	callAppenders(event, p);
 }
 
@@ -198,7 +193,7 @@ void Logger::addEventLS(const LevelPtr& level, LogString&& message, const Locati
 	if (!getHierarchy()) // Has removeHierarchy() been called?
 		return;
 	auto event = std::make_shared<LoggingEvent>(m_priv->name, level, location, std::move(message));
-	Pool p(m_priv->pool.create(), true);
+	Pool p;
 	callAppenders(event, p);
 }
 
@@ -208,7 +203,7 @@ void Logger::forcedLogLS(const LevelPtr& level1, const LogString& message,
 	if (!getHierarchy()) // Has removeHierarchy() been called?
 		return;
 	auto event = std::make_shared<LoggingEvent>(m_priv->name, level1, message, location);
-	Pool p(m_priv->pool.create(), true);
+	Pool p;
 	callAppenders(event, p);
 }
 
@@ -750,7 +745,7 @@ void Logger::addEvent(const LevelPtr& level, std::wstring&& message, const Locat
 	LOG4CXX_DECODE_WCHAR(msg, message);
 	auto event = std::make_shared<LoggingEvent>(m_priv->name, level, location, std::move(msg));
 #endif
-	Pool p(m_priv->pool.create(), true);
+	Pool p;
 	callAppenders(event, p);
 }
 
@@ -765,7 +760,7 @@ void Logger::forcedLog(const LevelPtr& level, const std::wstring& message,
 	LOG4CXX_DECODE_WCHAR(msg, message);
 	auto event = std::make_shared<LoggingEvent>(m_priv->name, level, location, std::move(msg));
 #endif
-	Pool p(m_priv->pool.create(), true);
+	Pool p;
 	callAppenders(event, p);
 }
 
@@ -913,7 +908,7 @@ void Logger::addEvent(const LevelPtr& level1, std::basic_string<UniChar>&& messa
 		return;
 	LOG4CXX_DECODE_UNICHAR(msg, message);
 	auto event = std::make_shared<LoggingEvent>(m_priv->name, level1, location, std::move(msg));
-	Pool p(m_priv->pool.create(), true);
+	Pool p;
 	callAppenders(event, p);
 }
 
@@ -924,7 +919,7 @@ void Logger::forcedLog(const LevelPtr& level1, const std::basic_string<UniChar>&
 		return;
 	LOG4CXX_DECODE_UNICHAR(msg, message);
 	auto event = std::make_shared<LoggingEvent>(m_priv->name, level1, location, std::move(msg));
-	Pool p(m_priv->pool.create(), true);
+	Pool p;
 	callAppenders(event, p);
 }
 
@@ -935,7 +930,7 @@ void Logger::forcedLog(const LevelPtr& level1, const std::basic_string<UniChar>&
 	LOG4CXX_DECODE_UNICHAR(msg, message);
 	auto event = std::make_shared<LoggingEvent>(m_priv->name, level1, msg,
 			LocationInfo::getLocationUnavailable());
-	Pool p(m_priv->pool.create(), true);
+	Pool p;
 	callAppenders(event, p);
 }
 
@@ -1074,7 +1069,7 @@ void Logger::forcedLog(const LevelPtr& level, const CFStringRef& message,
 		return;
 	LOG4CXX_DECODE_CFSTRING(msg, message);
 	auto event = std::make_shared<LoggingEvent>(m_priv->name, level, location, std::move(msg));
-	Pool p(m_priv->pool.create(), true);
+	Pool p;
 	callAppenders(event, p);
 }
 
@@ -1085,7 +1080,7 @@ void Logger::forcedLog(const LevelPtr& level, const CFStringRef& message) const
 	LOG4CXX_DECODE_CFSTRING(msg, message);
 	auto event = std::make_shared<LoggingEvent>(m_priv->name, level, msg,
 			LocationInfo::getLocationUnavailable());
-	Pool p(m_priv->pool.create(), true);
+	Pool p;
 	callAppenders(event, p);
 }
 
diff --git a/src/main/cpp/pool.cpp b/src/main/cpp/pool.cpp
index 5a715c34..8e3f41d3 100644
--- a/src/main/cpp/pool.cpp
+++ b/src/main/cpp/pool.cpp
@@ -32,12 +32,6 @@ using namespace LOG4CXX_NS;
 
 Pool::Pool() : pool(0), release(true)
 {
-	apr_status_t stat = apr_pool_create(&pool, APRInitializer::getRootPool());
-
-	if (stat != APR_SUCCESS)
-	{
-		throw PoolException(stat);
-	}
 }
 
 Pool::Pool(apr_pool_t* p, bool release1) : pool(p), release(release1)
@@ -47,20 +41,33 @@ Pool::Pool(apr_pool_t* p, bool release1) : pool(p), release(release1)
 
 Pool::~Pool()
 {
-	if (release)
+	if (pool && release)
 	{
 		apr_pool_destroy(pool);
 	}
 }
 
+void Pool::setPool()
+{
+	apr_status_t stat = apr_pool_create(&pool, APRInitializer::getRootPool());
+
+	if (stat != APR_SUCCESS)
+	{
+		throw PoolException(stat);
+	}
+}
 
 apr_pool_t* Pool::getAPRPool()
 {
+	if (!pool)
+		setPool();
 	return pool;
 }
 
 apr_pool_t* Pool::create()
 {
+	if (!pool)
+		setPool();
 	apr_pool_t* child;
 	apr_status_t stat = apr_pool_create(&child, pool);
 
@@ -74,6 +81,8 @@ apr_pool_t* Pool::create()
 
 void* Pool::palloc(size_t size)
 {
+	if (!pool)
+		setPool();
 	return apr_palloc(pool, size);
 }
 
@@ -84,20 +93,28 @@ char* Pool::pstralloc(size_t size)
 
 char* Pool::itoa(int n)
 {
+	if (!pool)
+		setPool();
 	return apr_itoa(pool, n);
 }
 
 char* Pool::pstrndup(const char* s, size_t len)
 {
+	if (!pool)
+		setPool();
 	return apr_pstrndup(pool, s, len);
 }
 
 char* Pool::pstrdup(const char* s)
 {
+	if (!pool)
+		setPool();
 	return apr_pstrdup(pool, s);
 }
 
 char* Pool::pstrdup(const std::string& s)
 {
+	if (!pool)
+		setPool();
 	return apr_pstrndup(pool, s.data(), s.length());
 }
diff --git a/src/main/include/log4cxx/helpers/pool.h b/src/main/include/log4cxx/helpers/pool.h
index 2b87448a..76650f37 100644
--- a/src/main/include/log4cxx/helpers/pool.h
+++ b/src/main/include/log4cxx/helpers/pool.h
@@ -52,6 +52,7 @@ class LOG4CXX_EXPORT Pool
 	private:
 		Pool(const LOG4CXX_NS::helpers::Pool&);
 		Pool& operator=(const Pool&);
+		void setPool();
 };
 } // namespace helpers
 } // namespace log4cxx