|
| 1 | +#pragma once |
| 2 | +#include <chimbuko_config.h> |
| 3 | +#include <chimbuko/ad/ADLocalFuncStatistics.hpp> |
| 4 | +#include <chimbuko/ad/ADLocalCounterStatistics.hpp> |
| 5 | + |
| 6 | +namespace chimbuko{ |
| 7 | + /** |
| 8 | + * @brief A class that combines all data that is sent to the PS into a single send transmission |
| 9 | + */ |
| 10 | + class ADcombinedPSdata{ |
| 11 | + public: |
| 12 | + ADcombinedPSdata(ADLocalFuncStatistics &func_stats, ADLocalCounterStatistics &counter_stats, PerfStats* perf=nullptr): |
| 13 | + m_func_stats(func_stats), m_counter_stats(counter_stats), m_perf(perf){} |
| 14 | + |
| 15 | + ADLocalCounterStatistics &get_counter_stats(){ return m_counter_stats; } |
| 16 | + const ADLocalCounterStatistics &get_counter_stats() const{ return m_counter_stats; } |
| 17 | + |
| 18 | + ADLocalFuncStatistics &get_func_stats(){ return m_func_stats; } |
| 19 | + const ADLocalFuncStatistics &get_func_stats() const{ return m_func_stats; } |
| 20 | + |
| 21 | + /** |
| 22 | + * @brief The State object is what is serialized for the communication |
| 23 | + */ |
| 24 | + struct State{ |
| 25 | + ADLocalFuncStatistics::State func_stats_state; |
| 26 | + ADLocalCounterStatistics::State counter_stats_state; |
| 27 | + |
| 28 | + /** |
| 29 | + * @brief Serialize using cereal |
| 30 | + */ |
| 31 | + template<class Archive> |
| 32 | + void serialize(Archive & archive){ |
| 33 | + archive(func_stats_state , counter_stats_state); |
| 34 | + } |
| 35 | + |
| 36 | + /** |
| 37 | + * Serialize into Cereal portable binary format |
| 38 | + */ |
| 39 | + std::string serialize_cerealpb() const; |
| 40 | + |
| 41 | + /** |
| 42 | + * Serialize from Cereal portable binary format |
| 43 | + */ |
| 44 | + void deserialize_cerealpb(const std::string &strstate); |
| 45 | + }; |
| 46 | + |
| 47 | + /** |
| 48 | + * @brief Get the current state as a state object |
| 49 | + * |
| 50 | + * The string dump of this object is the serialized form sent to the parameter server |
| 51 | + */ |
| 52 | + State get_state() const; |
| 53 | + |
| 54 | + |
| 55 | + /** |
| 56 | + * @brief Set the internal variables to the given state object |
| 57 | + */ |
| 58 | + void set_state(const State &s); |
| 59 | + |
| 60 | + |
| 61 | + /** |
| 62 | + * @brief Serialize this class for communication over the network |
| 63 | + */ |
| 64 | + std::string net_serialize() const; |
| 65 | + |
| 66 | + /** |
| 67 | + * @brief Unserialize this class after communication over the network |
| 68 | + */ |
| 69 | + void net_deserialize(const std::string &s); |
| 70 | + |
| 71 | + |
| 72 | + /** |
| 73 | + * @brief Send the data to the pserver |
| 74 | + * @param net_client The network client object |
| 75 | + * @return std::pair<size_t, size_t> [sent, recv] message size |
| 76 | + */ |
| 77 | + std::pair<size_t, size_t> send(ADNetClient &net_client) const; |
| 78 | + |
| 79 | + |
| 80 | + private: |
| 81 | + ADLocalFuncStatistics &m_func_stats; |
| 82 | + ADLocalCounterStatistics &m_counter_stats; |
| 83 | + PerfStats* m_perf; |
| 84 | + }; |
| 85 | + |
| 86 | + |
| 87 | +} |
0 commit comments