1 #pragma once 2 3 #include "metricblob.pb.h" 4 5 #include <unistd.h> 6 7 #include <blobs-ipmid/blobs.hpp> 8 9 #include <atomic> 10 #include <cstdint> 11 #include <string> 12 #include <string_view> 13 #include <unordered_map> 14 #include <vector> 15 16 namespace metric_blob 17 { 18 19 class BmcHealthSnapshot 20 { 21 public: 22 BmcHealthSnapshot(); 23 24 /** 25 * Reads data from this metric 26 * @param offset: offset into the data to read 27 * @param requestedSize: how many bytes to read 28 * @returns Bytes able to read. Returns empty if nothing can be read. 29 */ 30 std::string_view read(uint32_t offset, uint32_t requestedSize); 31 32 /** 33 * Returns information about the amount of readable data and whether the 34 * metric has finished populating. 35 * @param meta: Struct to fill with the metadata info 36 */ 37 bool stat(blobs::BlobMeta& meta); 38 39 /** 40 * Start the metric collection process 41 */ 42 void doWork(); 43 44 /** 45 * The size of the content string. 46 */ 47 uint32_t size(); 48 49 private: 50 /** 51 * Serialize to the pb_dump_ array. 52 */ 53 void serializeSnapshotToArray( 54 const bmcmetrics::metricproto::BmcMetricSnapshot& snapshot); 55 56 // The two following functions access the snapshot's string table so they 57 // have to be member functions. 58 bmcmetrics::metricproto::BmcProcStatMetric getProcStatList(); 59 bmcmetrics::metricproto::BmcFdStatMetric getFdStatList(); 60 61 int getStringID(const std::string_view s); 62 std::atomic<bool> done; 63 std::vector<char> pbDump; 64 std::unordered_map<std::string, int> stringTable; 65 int stringId; 66 long ticksPerSec; 67 }; 68 69 } // namespace metric_blob 70