blob: abab43e11f1f2a5c9cc3565d26a028b6e95c7647 [file] [log] [blame]
// Copyright 2019 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SRC_DEVELOPER_SYSTEM_MONITOR_BIN_HARVESTER_SAMPLE_BUNDLE_H_
#define SRC_DEVELOPER_SYSTEM_MONITOR_BIN_HARVESTER_SAMPLE_BUNDLE_H_
#include <string>
#include "dockyard_proxy.h"
namespace harvester {
// A bundle (group) of samples that will all receive the same timestamp. Avoid
// keeping samples in a bundle for very long before calling Upload() since all
// samples in the bundle will be timestamped when Upload() is called.
class SampleBundle final {
public:
SampleBundle() = default;
// After gathering the data, upload it to |dockyard|.
void Upload(DockyardProxy* dockyard_proxy);
// Add a value to the sample |int_sample_list_|.
void AddIntSample(const std::string& dockyard_path,
dockyard::SampleValue value) {
int_sample_list_.emplace_back(dockyard_path, value);
}
// Helper to add a value to the sample |int_sample_list_|.
void AddIntSample(const std::string& type, uint64_t id,
const std::string& path, dockyard::SampleValue value) {
std::ostringstream label;
label << type << ":" << id << ":" << path;
int_sample_list_.emplace_back(label.str(), value);
}
// Helper to add a value to the sample |string_sample_list_|.
void AddStringSample(const std::string& type, uint64_t id,
const std::string& path, const std::string& value) {
std::ostringstream label;
label << type << ":" << id << ":" << path;
string_sample_list_.emplace_back(label.str(), value);
}
private:
SampleList int_sample_list_;
StringSampleList string_sample_list_;
friend std::ostream& operator<<(std::ostream& out,
const SampleBundle& bundle);
};
} // namespace harvester
#endif // SRC_DEVELOPER_SYSTEM_MONITOR_BIN_HARVESTER_SAMPLE_BUNDLE_H_