X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fceph%2Fsrc%2Fdmclock%2Fsim%2Fsrc%2Fsim_recs.h;fp=src%2Fceph%2Fsrc%2Fdmclock%2Fsim%2Fsrc%2Fsim_recs.h;h=759ab4e14134ec2c0a9f085885c5cf55598845bb;hb=812ff6ca9fcd3e629e49d4328905f33eee8ca3f5;hp=0000000000000000000000000000000000000000;hpb=15280273faafb77777eab341909a3f495cf248d9;p=stor4nfv.git diff --git a/src/ceph/src/dmclock/sim/src/sim_recs.h b/src/ceph/src/dmclock/sim/src/sim_recs.h new file mode 100644 index 0000000..759ab4e --- /dev/null +++ b/src/ceph/src/dmclock/sim/src/sim_recs.h @@ -0,0 +1,122 @@ +// -*- 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