Skip to content

Commit

Permalink
Merge pull request #4412 from pwojcikdev/tracing-4-develop
Browse files Browse the repository at this point in the history
Tracing
  • Loading branch information
pwojcikdev authored Feb 8, 2024
2 parents ef25ca6 + 3ebb6f7 commit 5abd5ba
Show file tree
Hide file tree
Showing 44 changed files with 2,374 additions and 354 deletions.
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,17 @@ if(NANO_STACKTRACE_BACKTRACE)
endif()
endif()

# Enable NANO_TRACING by default in Debug builds
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
option(NANO_TRACING "Enable trace logging" ON)
else()
option(NANO_TRACING "Enable trace logging" OFF)
endif()
if(NANO_TRACING)
message(STATUS "Using trace logging")
add_compile_definitions(NANO_TRACING)
endif()

if(${NANO_TIMED_LOCKS} GREATER 0)
add_definitions(-DNANO_TIMED_LOCKS=${NANO_TIMED_LOCKS})
add_definitions(-DNANO_TIMED_LOCKS_FILTER=${NANO_TIMED_LOCKS_FILTER})
Expand Down
1 change: 1 addition & 0 deletions ci/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ cmake \
-DACTIVE_NETWORK=nano_${NANO_NETWORK:-"live"}_network \
-DNANO_TEST=${NANO_TEST:-OFF} \
-DNANO_GUI=${NANO_GUI:-OFF} \
-DNANO_TRACING=${NANO_TRACING:-OFF} \
-DCOVERAGE=${COVERAGE:-OFF} \
-DCI_TAG=${CI_TAG:-OFF} \
-DCI_VERSION_PRE_RELEASE=${CI_VERSION_PRE_RELEASE:-OFF} \
Expand Down
3 changes: 2 additions & 1 deletion nano/core_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ add_executable(
ipc.cpp
ledger.cpp
locks.cpp
logger.cpp
logging.cpp
message.cpp
message_deserializer.cpp
memory_pool.cpp
network.cpp
network_filter.cpp
node.cpp
object_stream.cpp
optimistic_scheduler.cpp
processing_queue.cpp
processor_service.cpp
Expand Down
4 changes: 2 additions & 2 deletions nano/core_test/election.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,6 @@ TEST (election, continuous_voting)
ASSERT_TRUE (nano::test::process (node1, { send2 }));
ASSERT_TIMELY (5s, node1.active.active (*send2));

// Ensure votes are generated in continuous manner
ASSERT_TIMELY (5s, node1.stats.count (nano::stat::type::election, nano::stat::detail::generate_vote) >= 5);
// Ensure votes are broadcasted in continuous manner
ASSERT_TIMELY (5s, node1.stats.count (nano::stat::type::election, nano::stat::detail::broadcast_vote) >= 5);
}
16 changes: 0 additions & 16 deletions nano/core_test/logger.cpp

This file was deleted.

106 changes: 106 additions & 0 deletions nano/core_test/logging.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#include <nano/lib/logging.hpp>
#include <nano/test_common/testutil.hpp>

#include <gtest/gtest.h>

#include <ostream>

using namespace std::chrono_literals;

namespace
{
struct non_copyable
{
non_copyable () = default;
non_copyable (non_copyable const &) = delete;
non_copyable (non_copyable &&) = default;
non_copyable & operator= (non_copyable const &) = delete;
non_copyable & operator= (non_copyable &&) = default;

friend std::ostream & operator<< (std::ostream & os, non_copyable const & nc)
{
os << "non_copyable";
return os;
}
};
}

TEST (tracing, no_copy)
{
non_copyable nc;

nano::logger logger;
logger.trace (nano::log::type::test, nano::log::detail::test, nano::log::arg{ "non_copyable", nc });
}

namespace
{
struct non_moveable
{
non_moveable () = default;
non_moveable (non_moveable const &) = delete;
non_moveable (non_moveable &&) = delete;
non_moveable & operator= (non_moveable const &) = delete;
non_moveable & operator= (non_moveable &&) = delete;

friend std::ostream & operator<< (std::ostream & os, non_moveable const & nm)
{
os << "non_moveable";
return os;
}
};
}

TEST (tracing, no_move)
{
non_moveable nm;

nano::logger logger;
logger.trace (nano::log::type::test, nano::log::detail::test, nano::log::arg{ "non_moveable", nm });
}

TEST (log_parse, parse_level)
{
ASSERT_EQ (nano::log::parse_level ("error"), nano::log::level::error);
ASSERT_EQ (nano::log::parse_level ("off"), nano::log::level::off);
ASSERT_THROW (nano::log::parse_level ("enumnotpresent"), std::invalid_argument);
ASSERT_THROW (nano::log::parse_level (""), std::invalid_argument);
ASSERT_THROW (nano::log::parse_level ("_last"), std::invalid_argument);
ASSERT_THROW (nano::log::parse_level ("_error"), std::invalid_argument);
}

TEST (log_parse, parse_type)
{
ASSERT_EQ (nano::log::parse_type ("node"), nano::log::type::node);
ASSERT_THROW (nano::log::parse_type ("enumnotpresent"), std::invalid_argument);
ASSERT_THROW (nano::log::parse_type (""), std::invalid_argument);
ASSERT_THROW (nano::log::parse_type ("_last"), std::invalid_argument);
ASSERT_THROW (nano::log::parse_type ("_node"), std::invalid_argument);
}

TEST (log_parse, parse_detail)
{
ASSERT_EQ (nano::log::parse_detail ("all"), nano::log::detail::all);
ASSERT_EQ (nano::log::parse_detail ("process_confirmed"), nano::log::detail::process_confirmed);
ASSERT_THROW (nano::log::parse_detail ("enumnotpresent"), std::invalid_argument);
ASSERT_THROW (nano::log::parse_detail (""), std::invalid_argument);
ASSERT_THROW (nano::log::parse_detail ("_last"), std::invalid_argument);
ASSERT_THROW (nano::log::parse_detail ("_all"), std::invalid_argument);
}

TEST (log_parse, parse_logger_id)
{
ASSERT_EQ (nano::log::parse_logger_id ("node"), std::make_pair (nano::log::type::node, nano::log::detail::all));
ASSERT_EQ (nano::log::parse_logger_id ("node::all"), std::make_pair (nano::log::type::node, nano::log::detail::all));
ASSERT_EQ (nano::log::parse_logger_id ("node::process_confirmed"), std::make_pair (nano::log::type::node, nano::log::detail::process_confirmed));
ASSERT_THROW (nano::log::parse_logger_id ("_last"), std::invalid_argument);
ASSERT_THROW (nano::log::parse_logger_id ("node::enumnotpresent"), std::invalid_argument);
ASSERT_THROW (nano::log::parse_logger_id ("node::"), std::invalid_argument);
ASSERT_THROW (nano::log::parse_logger_id ("node::_all"), std::invalid_argument);
ASSERT_THROW (nano::log::parse_logger_id ("enumnotpresent"), std::invalid_argument);
ASSERT_THROW (nano::log::parse_logger_id ("invalid."), std::invalid_argument);
ASSERT_THROW (nano::log::parse_logger_id ("invalid._all"), std::invalid_argument);
ASSERT_THROW (nano::log::parse_logger_id ("::"), std::invalid_argument);
ASSERT_THROW (nano::log::parse_logger_id ("::all"), std::invalid_argument);
ASSERT_THROW (nano::log::parse_logger_id (""), std::invalid_argument);
}
Loading

0 comments on commit 5abd5ba

Please sign in to comment.