Add I/O stats
Using /proc/self/io 'read_bytes' and 'write_bytes' fields which count only reads/writes that hit the storage (i.e no cached reads).pull/58/head
parent
534ca9416d
commit
f8398c3e7a
@ -0,0 +1,27 @@
|
||||
#include "iostats.h"
|
||||
#include "string_utils.h"
|
||||
#include <fstream>
|
||||
|
||||
pthread_t ioThread;
|
||||
void *getIoStats(void *args) {
|
||||
iostats *io = reinterpret_cast<iostats *>(args);
|
||||
if (io) {
|
||||
io->prev.read_bytes = io->curr.read_bytes;
|
||||
io->prev.write_bytes = io->curr.write_bytes;
|
||||
|
||||
std::string line;
|
||||
std::ifstream f("/proc/self/io");
|
||||
while (std::getline(f, line)) {
|
||||
if (starts_with(line, "read_bytes:")) {
|
||||
try_stoull(io->curr.read_bytes, line.substr(12));
|
||||
}
|
||||
else if (starts_with(line, "write_bytes:")) {
|
||||
try_stoull(io->curr.write_bytes, line.substr(13));
|
||||
}
|
||||
}
|
||||
io->diff.read = (io->curr.read_bytes - io->prev.read_bytes) / (1024.f * 1024.f);
|
||||
io->diff.write = (io->curr.write_bytes - io->prev.write_bytes) / (1024.f * 1024.f);
|
||||
}
|
||||
pthread_detach(ioThread);
|
||||
return NULL;
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
#include <pthread.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
extern pthread_t ioThread;
|
||||
|
||||
struct iostats {
|
||||
struct {
|
||||
unsigned long long read_bytes;
|
||||
unsigned long long write_bytes;
|
||||
} curr;
|
||||
struct {
|
||||
unsigned long long read_bytes;
|
||||
unsigned long long write_bytes;
|
||||
} prev;
|
||||
struct {
|
||||
float read;
|
||||
float write;
|
||||
} diff;
|
||||
};
|
||||
|
||||
void *getIoStats(void *args);
|
Loading…
Reference in New Issue