]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson:port perfcounters to seastar 24141/head
authorchunmei Liu <chunmei.liu@intel.com>
Wed, 24 Oct 2018 00:13:56 +0000 (17:13 -0700)
committerchunmei Liu <chunmei.liu@intel.com>
Tue, 30 Oct 2018 18:46:21 +0000 (11:46 -0700)
reuse PerfCounterCollectionImpl to port it to seastar. create
shard service for perfcounters, each seastar thread has its own
perfcounterscollection and perfcunters m_loggers.

Signed-off-by: chunmei Liu <chunmei.liu@intel.com>
src/common/ceph_context.cc
src/common/ceph_context.h
src/crimson/CMakeLists.txt
src/crimson/common/perf_counters_collection.cc [new file with mode: 0644]
src/crimson/common/perf_counters_collection.h [new file with mode: 0644]
src/test/crimson/CMakeLists.txt
src/test/crimson/test_perfcounters.cc [new file with mode: 0644]

index f88b38e8590c2f4d1b203ceac360d2dcfdfafe3c..4235d1f5cd124b10972bc9b6194c4c165669ddcf 100644 (file)
@@ -48,6 +48,7 @@ using ceph::HeartbeatMap;
 #ifdef WITH_SEASTAR
 CephContext::CephContext()
   : _conf{ceph::common::local_conf()},
+    _perf_counters_collection{ceph::common::local_perf_coll()},
     _crypto_random{std::make_unique<CryptoRandom>()}
 {}
 
@@ -73,9 +74,9 @@ void CephContext::put()
   }
 }
 
-PerfCountersCollection* CephContext::get_perfcounters_collection()
+PerfCountersCollectionImpl* CephContext::get_perfcounters_collection()
 {
-  throw std::runtime_error("not yet implemented");
+  return _perf_counters_collection.get_perf_collection();
 }
 
 #else  // WITH_SEASTAR
index 388e1db980956e3692504f8fc1d10e59383221c1..ceed4c055f7a0e9f70e2049a75ff4b03c2c1b97b 100644 (file)
 #include "common/code_environment.h"
 #ifdef WITH_SEASTAR
 #include "crimson/common/config_proxy.h"
+#include "crimson/common/perf_counters_collection.h"
 #else
 #include "common/config_proxy.h"
 #include "include/spinlock.h"
-#endif
 #include "common/perf_counters_collection.h"
+#endif
 
 
 #include "crush/CrushLocation.h"
@@ -67,8 +68,9 @@ public:
   ~CephContext();
 
   CryptoRandom* random() const;
-  PerfCountersCollection* get_perfcounters_collection();
+  PerfCountersCollectionImpl* get_perfcounters_collection();
   ceph::common::ConfigProxy& _conf;
+  ceph::common::PerfCountersCollection& _perf_counters_collection;
   CephContext* get();
   void put();
 private:
index 609e63465b216c864b24eb9c94dcb85445806858..fbcb00b4d22051353a22a7b06a5236317f403c61 100644 (file)
@@ -5,6 +5,7 @@ set_target_properties(crimson::cflags PROPERTIES
 
 set(crimson_common_srcs
   common/config_proxy.cc
+  common/perf_counters_collection.cc
   common/assert.cc
   common/log.cc)
 
diff --git a/src/crimson/common/perf_counters_collection.cc b/src/crimson/common/perf_counters_collection.cc
new file mode 100644 (file)
index 0000000..7a19a9f
--- /dev/null
@@ -0,0 +1,22 @@
+#include "perf_counters_collection.h"
+
+namespace ceph::common {
+PerfCountersCollection::PerfCountersCollection()
+{
+  perf_collection = std::make_unique<PerfCountersCollectionImpl>();
+}
+PerfCountersCollection::~PerfCountersCollection()
+{
+  perf_collection->clear();
+}
+
+PerfCountersCollectionImpl* PerfCountersCollection:: get_perf_collection()
+{
+  return perf_collection.get();
+}
+
+PerfCountersCollection::ShardedPerfCountersCollection PerfCountersCollection::sharded_perf_coll;
+
+}
+
+
diff --git a/src/crimson/common/perf_counters_collection.h b/src/crimson/common/perf_counters_collection.h
new file mode 100644 (file)
index 0000000..95e2a4f
--- /dev/null
@@ -0,0 +1,33 @@
+#pragma once
+
+#include "common/perf_counters.h"
+#include <seastar/core/sharded.hh>
+
+namespace ceph::common {
+class PerfCountersCollection: public seastar::sharded<PerfCountersCollection>
+{
+  using ShardedPerfCountersCollection = seastar::sharded<PerfCountersCollection>;
+
+private:
+  std::unique_ptr<PerfCountersCollectionImpl> perf_collection;
+  static ShardedPerfCountersCollection sharded_perf_coll;
+  friend PerfCountersCollection& local_perf_coll();
+  friend ShardedPerfCountersCollection& sharded_perf_coll();
+
+public:
+  PerfCountersCollection();
+  ~PerfCountersCollection();
+  PerfCountersCollectionImpl* get_perf_collection();
+
+};
+
+inline PerfCountersCollection::ShardedPerfCountersCollection& sharded_perf_coll(){
+  return PerfCountersCollection::sharded_perf_coll;
+}
+
+inline PerfCountersCollection& local_perf_coll() {
+  return PerfCountersCollection::sharded_perf_coll.local();
+}
+
+}
+
index 385eca1e47929ec53c1766bb9d711a1e1432b6d4..1e12b3e94da956cdec9787f0d4fc9b378ab9a55e 100644 (file)
@@ -28,3 +28,9 @@ target_link_libraries(unittest_seastar_config crimson)
 add_executable(unittest_seastar_monc
   test_monc.cc)
 target_link_libraries(unittest_seastar_monc crimson)
+
+add_executable(unittest_seastar_perfcounters
+  test_perfcounters.cc)
+add_ceph_unittest(unittest_seastar_perfcounters)
+target_link_libraries(unittest_seastar_perfcounters crimson)
+
diff --git a/src/test/crimson/test_perfcounters.cc b/src/test/crimson/test_perfcounters.cc
new file mode 100644 (file)
index 0000000..581844d
--- /dev/null
@@ -0,0 +1,62 @@
+#include <pthread.h>
+#include <stdlib.h>
+#include <iostream>
+#include <fmt/format.h>
+
+#include "common/Formatter.h"
+#include "common/perf_counters.h"
+#include "crimson/common/perf_counters_collection.h"
+
+#include <seastar/core/app-template.hh>
+#include <seastar/core/sharded.hh>
+
+enum {
+  PERFTEST_FIRST = 1000000,
+  PERFTEST_INDEX,
+  PERFTEST_LAST,
+};
+
+static constexpr uint64_t PERF_VAL = 42;
+
+static seastar::future<> test_perfcounters(){
+  return ceph::common::sharded_perf_coll().start().then([] {
+    return ceph::common::sharded_perf_coll().invoke_on_all([] (auto& s){
+      std::string name =fmt::format("seastar-osd::shard-{}",seastar::engine().cpu_id());
+      PerfCountersBuilder plb(NULL, name, PERFTEST_FIRST,PERFTEST_LAST);
+      plb.add_u64_counter(PERFTEST_INDEX, "perftest_count", "count perftest");
+      auto perf_logger = plb.create_perf_counters();
+      perf_logger->inc(PERFTEST_INDEX,PERF_VAL);
+      s.get_perf_collection()->add(perf_logger);
+    });
+  }).then([]{
+    return ceph::common::sharded_perf_coll().invoke_on_all([] (auto& s){
+      auto pcc = s.get_perf_collection();
+      pcc->with_counters([=](auto& by_path){
+        for (const auto &[path, perf_counter_ref] : by_path) {
+          if (PERF_VAL != perf_counter_ref.perf_counters->get(PERFTEST_INDEX)) {
+            throw std::runtime_error("perf counter does not match");
+          }
+        }
+      });
+    });
+  }).finally([] {
+     return ceph::common::sharded_perf_coll().stop();
+  });
+
+}
+
+int main(int argc, char** argv)
+{
+  seastar::app_template app;
+  return app.run(argc, argv, [&] {
+    return test_perfcounters().then([] {
+      std::cout << "All tests succeeded" << std::endl;
+    }).handle_exception([] (auto eptr) {
+      std::cout << "Test failure" << std::endl;
+      return seastar::make_exception_future<>(eptr);
+    });
+  });
+
+}
+
+