From: Adam Kupczyk Date: Tue, 26 Sep 2017 11:04:47 +0000 (+0200) Subject: common/log: Performance test for logging. X-Git-Tag: v13.0.1~45^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=2c332eb83fd0455d78d18d70d038e9612b1c4014;p=ceph.git common/log: Performance test for logging. Signed-off-by: Adam Kupczyk --- diff --git a/src/log/test.cc b/src/log/test.cc index fc50878c4817..36fde96eb491 100644 --- a/src/log/test.cc +++ b/src/log/test.cc @@ -6,6 +6,11 @@ #include "include/coredumpctl.h" #include "SubsystemMap.h" +#include "global/global_init.h" +#include "common/ceph_argparse.h" +#include "global/global_context.h" +#include "common/dout.h" + using namespace ceph::logging; TEST(Log, Simple) @@ -274,3 +279,78 @@ TEST(Log, TimeFormat) ASSERT_EQ(6u, std::strlen(c + 1)); } } + +#define dout_subsys ceph_subsys_context + +template struct do_log +{ + void log(CephContext* cct); +}; + +template struct do_log<12, x> +{ + void log(CephContext* cct); +}; + +template void do_log::log(CephContext* cct) +{ + ldout(cct, 20) << "Log depth=" << depth << " x=" << x << dendl; + if (rand() % 2) { + do_log log; + log.log(cct); + } else { + do_log log; + log.log(cct); + } +} + +std::string recursion(CephContext* cct) +{ + ldout(cct, 20) << "Preparing recursion string" << dendl; + return "here-recursion"; +} + +template void do_log<12, x>::log(CephContext* cct) +{ + if ((rand() % 16) == 0) { + ldout(cct, 20) << "End " << recursion(cct) << "x=" << x << dendl; + } else { + ldout(cct, 20) << "End x=" << x << dendl; + } +} + +TEST(Log, Speed_gather) +{ + do_log<0,0> start; + g_ceph_context->_conf->subsys.set_gather_level(ceph_subsys_context, 30); + g_ceph_context->_conf->subsys.set_log_level(ceph_subsys_context, 0); + for (int i=0; i<100000;i++) { + ldout(g_ceph_context, 20) << "Iteration " << i << dendl; + start.log(g_ceph_context); + } +} + +TEST(Log, Speed_nogather) +{ + do_log<0,0> start; + g_ceph_context->_conf->subsys.set_gather_level(ceph_subsys_context, 0); + g_ceph_context->_conf->subsys.set_log_level(ceph_subsys_context, 0); + for (int i=0; i<100000;i++) { + ldout(g_ceph_context, 20) << "Iteration " << i << dendl; + start.log(g_ceph_context); + } +} + + +int main(int argc, char **argv) +{ + vector args; + argv_to_vec(argc, (const char **)argv, args); + + auto cct = global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, + CODE_ENVIRONMENT_UTILITY, 0); + common_init_finish(g_ceph_context); + + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +}