-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMetrics.h
64 lines (57 loc) · 2.15 KB
/
Metrics.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# pragma once
#include "params.h"
#include "Buffer.h"
#include <tuple>
using std::tuple;
using std::string;
using std::to_string;
/*
StorageMetrics: the metrics of a storage system (SSD / HDD)
dataTransferCost: the time spent on data transfer
accessCost: the fixed latency of the storage system,
equal to (number of access) * (latency per access)
*/
struct StorageMetrics {
double dataTransferCost;
double accessCost;
u_int64_t numBytesRead;
u_int64_t numBytesWritten;
u_int64_t numAccessesRead;
u_int64_t numAccessesWritten;
u_int64_t storageUsed;
StorageMetrics() :
dataTransferCost(0.0), accessCost(0.0),
numBytesRead (0), numBytesWritten (0),
numAccessesRead (0), numAccessesWritten (0),
storageUsed (0) {}
};
/*
StorageParams: the parameters of a storage system (SSD / HDD)
latency: the latency of each access, in seconds
bandwidth: the bandwidth of the storage system, in bytes per second
*/
struct StorageParams {
double latency;
double bandwidth;
u_int64_t capacity;
u_int32_t pageSize; // max. 500 KB = 2 ^ 19
StorageParams(double _latency = 0.0, double _bandwidth = 0.0, u_int64_t _capacity = 0, u_int32_t _pageSize = 0) :
latency(_latency), bandwidth(_bandwidth), capacity (_capacity), pageSize (_pageSize) {}
};
class Metrics
{
public:
static void read(const int device_type, const u_int64_t num_bytes, bool readAhead); // expect filename to contain the device type
static int write(const int device_type, const u_int64_t num_bytes);
static void erase(const int device_type, const u_int64_t num_bytes);
static int getAvailableStorage(); // return the device type that has enough space for predefined page size
static int getAvailableStorage(const u_int64_t num_bytes); // return the device type that has enough space for a given number of bytes
static StorageMetrics getMetrics(const int device_type);
static StorageParams getParams(const int device_type);
static void Init();
Metrics();
private:
StorageMetrics metrics[NUM_STORAGE_TYPES];
StorageParams params[NUM_STORAGE_TYPES];
static Metrics * instance;
};