// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Copyright (C) 2016 Red Hat Inc. */ #pragma once #include #include #include #include #include #include #include #include #include #include #include using ClientId = uint; using ServerId = uint; namespace crimson { namespace qos_simulation { inline void debugger() { raise(SIGCONT); } template void time_stats(std::mutex& mtx, T& time_accumulate, std::function code) { auto t1 = std::chrono::steady_clock::now(); code(); auto t2 = std::chrono::steady_clock::now(); auto duration = t2 - t1; auto cast_duration = std::chrono::duration_cast(duration); std::lock_guard lock(mtx); time_accumulate += cast_duration; } // unfortunately it's hard for the compiler to infer the types, // and therefore when called the template params might have to be // explicit template R time_stats_w_return(std::mutex& mtx, T& time_accumulate, std::function code) { auto t1 = std::chrono::steady_clock::now(); R result = code(); auto t2 = std::chrono::steady_clock::now(); auto duration = t2 - t1; auto cast_duration = std::chrono::duration_cast(duration); std::lock_guard lock(mtx); time_accumulate += cast_duration; return result; } template void count_stats(std::mutex& mtx, T& counter) { std::lock_guard lock(mtx); ++counter; } struct TestRequest { ServerId server; // allows debugging uint32_t epoch; uint32_t op; TestRequest(ServerId _server, uint32_t _epoch, uint32_t _op) : server(_server), epoch(_epoch), op(_op) { // empty } TestRequest(const TestRequest& r) : TestRequest(r.server, r.epoch, r.op) { // empty } }; // struct TestRequest struct TestResponse { uint32_t epoch; TestResponse(uint32_t _epoch) : epoch(_epoch) { // empty } TestResponse(const TestResponse& r) : epoch(r.epoch) { // empty } friend std::ostream& operator<<(std::ostream& out, const TestResponse& resp) { out << "{ "; out << "epoch:" << resp.epoch; out << " }"; return out; } }; // class TestResponse }; // namespace qos_simulation }; // namespace crimson