#ifdef WITH_SEASTAR
CephContext::CephContext()
: _conf{ceph::common::local_conf()},
+ _perf_counters_collection{ceph::common::local_perf_coll()},
_crypto_random{std::make_unique<CryptoRandom>()}
{}
}
}
-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
#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"
~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:
set(crimson_common_srcs
common/config_proxy.cc
+ common/perf_counters_collection.cc
common/assert.cc
common/log.cc)
--- /dev/null
+#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;
+
+}
+
+
--- /dev/null
+#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();
+}
+
+}
+
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)
+
--- /dev/null
+#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);
+ });
+ });
+
+}
+
+