Skip to content
API Documentation
BastionGuard™
anonymous_namespace{device_health_probe.cpp} Namespace Reference

Functions

DeviceProbeSample take_sample (DiskReader &reader, uint64_t offset, size_t size)
std::string health_to_string (DeviceHealthState state)

Function Documentation

◆ health_to_string()

std::string anonymous_namespace{device_health_probe.cpp}::health_to_string ( DeviceHealthState state)

Definition at line 26 of file device_health_probe.cpp.

26 {
27 switch (state) {
28 case DeviceHealthState::Healthy: return "Healthy";
29 case DeviceHealthState::ReadableWithErrors: return "Readable with errors";
30 case DeviceHealthState::PartiallyReadable: return "Partially readable";
31 case DeviceHealthState::EnumeratedButUnstable: return "Enumerated but unstable";
32 case DeviceHealthState::NotReadable: return "Not readable";
33 }
34 return "Unknown";
35}

References EnumeratedButUnstable, health_to_string(), Healthy, NotReadable, PartiallyReadable, and ReadableWithErrors.

Referenced by health_to_string().

◆ take_sample()

DeviceProbeSample anonymous_namespace{device_health_probe.cpp}::take_sample ( DiskReader & reader,
uint64_t offset,
size_t size )

Definition at line 10 of file device_health_probe.cpp.

10 {
11 DeviceProbeSample sample;
12 sample.offset = offset;
13 sample.size = size;
14 std::array<unsigned char, 4096> buffer{};
15 const size_t to_read = std::min<size_t>(size, buffer.size());
16 const auto start = std::chrono::steady_clock::now();
17 sample.success = reader.read_at(offset, buffer.data(), to_read);
18 sample.latency_ms = static_cast<uint64_t>(std::chrono::duration_cast<std::chrono::milliseconds>(
19 std::chrono::steady_clock::now() - start).count());
20 if (!sample.success) {
21 sample.error = "read failed";
22 }
23 return sample;
24}
bool read_at(uint64_t offset, void *buffer, size_t len)

References DeviceProbeSample::error, DeviceProbeSample::latency_ms, DeviceProbeSample::offset, DiskReader::read_at(), DeviceProbeSample::size, DeviceProbeSample::success, and take_sample().

Referenced by take_sample().