mirror of
https://github.com/aristocratos/btop.git
synced 2024-09-29 22:51:35 +02:00
check if at least one object was read before updating ZFS pool io in zfs_collect_pool_total_stats(), use try-catch to prevent possible crashes from int_64t conversions
This commit is contained in:
parent
4969dd8dc6
commit
189cba73e4
@ -1182,13 +1182,14 @@ namespace Mem {
|
|||||||
bool zfs_collect_pool_total_stats(struct disk_info &disk) {
|
bool zfs_collect_pool_total_stats(struct disk_info &disk) {
|
||||||
ifstream diskread;
|
ifstream diskread;
|
||||||
|
|
||||||
int64_t bytes_read, bytes_write, io_ticks, bytes_read_total = 0, bytes_write_total = 0, io_ticks_total = 0;
|
int64_t bytes_read, bytes_write, io_ticks, bytes_read_total = 0, bytes_write_total = 0, io_ticks_total = 0, objects_read = 0;
|
||||||
|
|
||||||
// looking through all files that start with 'objset'
|
// looking through all files that start with 'objset'
|
||||||
for (const auto& file: fs::directory_iterator(disk.stat)) {
|
for (const auto& file: fs::directory_iterator(disk.stat)) {
|
||||||
if ((file.path().filename()).string().starts_with("objset")) {
|
if ((file.path().filename()).string().starts_with("objset")) {
|
||||||
diskread.open(file.path());
|
diskread.open(file.path());
|
||||||
if (diskread.good()) {
|
if (diskread.good()) {
|
||||||
|
try {
|
||||||
// skip first three lines
|
// skip first three lines
|
||||||
for (int i = 0; i < 3; i++) diskread.ignore(numeric_limits<streamsize>::max(), '\n');
|
for (int i = 0; i < 3; i++) diskread.ignore(numeric_limits<streamsize>::max(), '\n');
|
||||||
// skip characters until '4' is reached, indicating data type 4, next value will be out target
|
// skip characters until '4' is reached, indicating data type 4, next value will be out target
|
||||||
@ -1210,6 +1211,12 @@ namespace Mem {
|
|||||||
diskread.ignore(numeric_limits<streamsize>::max(), '4');
|
diskread.ignore(numeric_limits<streamsize>::max(), '4');
|
||||||
diskread >> bytes_read;
|
diskread >> bytes_read;
|
||||||
bytes_read_total += bytes_read;
|
bytes_read_total += bytes_read;
|
||||||
|
} catch (const std::exception& e) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// increment read objects counter if no errors were encountered
|
||||||
|
objects_read++;
|
||||||
} else {
|
} else {
|
||||||
Logger::warning("Could not read file: " + file.path().string());
|
Logger::warning("Could not read file: " + file.path().string());
|
||||||
}
|
}
|
||||||
@ -1217,6 +1224,9 @@ namespace Mem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if for some reason no objects were read
|
||||||
|
if (objects_read == 0) return false;
|
||||||
|
|
||||||
if (disk.io_write.empty())
|
if (disk.io_write.empty())
|
||||||
disk.io_write.push_back(0);
|
disk.io_write.push_back(0);
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user