blob: 0f94d5fa4f071c81f9857da0758bfff5d218ff65 [file] [log] [blame]
Brandon Kimdab96f12021-02-18 11:21:37 -08001// Copyright 2021 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
Sui Chen03eba282021-02-11 11:35:56 -080015#pragma once
Sui Chen03eba282021-02-11 11:35:56 -080016#include <blobs-ipmid/blobs.hpp>
17
18#include <atomic>
19#include <cstdint>
20#include <string>
21#include <string_view>
22#include <unordered_map>
23#include <vector>
24
25namespace metric_blob
26{
27
28class BmcHealthSnapshot
29{
30 public:
31 BmcHealthSnapshot();
32
33 /**
34 * Reads data from this metric
35 * @param offset: offset into the data to read
36 * @param requestedSize: how many bytes to read
37 * @returns Bytes able to read. Returns empty if nothing can be read.
38 */
39 std::string_view read(uint32_t offset, uint32_t requestedSize);
40
41 /**
42 * Returns information about the amount of readable data and whether the
43 * metric has finished populating.
44 * @param meta: Struct to fill with the metadata info
45 */
46 bool stat(blobs::BlobMeta& meta);
47
48 /**
49 * Start the metric collection process
50 */
51 void doWork();
52
53 /**
54 * The size of the content string.
55 */
56 uint32_t size();
57
Sui Chen03eba282021-02-11 11:35:56 -080058 /**
William A. Kennington III7f493702024-02-08 01:09:11 -080059 * Returns the ID of the provided string
Sui Chen03eba282021-02-11 11:35:56 -080060 */
Sui Chen03eba282021-02-11 11:35:56 -080061 int getStringID(const std::string_view s);
William A. Kennington III7f493702024-02-08 01:09:11 -080062
63 private:
Sui Chen03eba282021-02-11 11:35:56 -080064 std::atomic<bool> done;
65 std::vector<char> pbDump;
66 std::unordered_map<std::string, int> stringTable;
67 int stringId;
68 long ticksPerSec;
69};
70
71} // namespace metric_blob