forked from microsoft/diskspd-for-linux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsys_info.h
75 lines (57 loc) · 2 KB
/
sys_info.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
65
66
67
68
69
70
71
72
73
74
75
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#include <cstdint>
#include <vector>
#include <set>
#include <map>
#include <sys/stat.h>
#ifndef DISKSPD_SYS_INFO_H
#define DISKSPD_SYS_INFO_H
namespace diskspd {
struct SysInfo {
unsigned int cpulo = 0; // lowest id
unsigned int cpuhi = 0; // highest id
std::set<unsigned int> online_cpus = {0}; // all online cpus
std::set<unsigned int> affinity_cpus = {0}; // cpuset specified by user
// comma separated list of system-wide caching options
std::string caching_options;
/**
* Populate the struct with initial information about cpus, devices, caching etc
* Optionally, provide a string which describes a set of cpus for the affinity_cpus set
*/
void init_sys_info(const char * affinity_set);
/**
* Parse the contents of /proc/stat
* Returned keys are the cpu ids
* Returned values are 4 element vectors pertaining to time that cpu has spent in:
* user mode, user mode with low priority (nice), system (kernel), idle
*/
std::map<unsigned int, std::vector<double> > get_cpu_stats();
/**
* Uses sysfs to determine the device name given a device id.
* Gets the underlying device name
*/
std::string device_from_id(dev_t device_id);
/**
* Uses sysfs to get the scheduler the kernel is using for a given device
*/
std::string scheduler_from_device(std::string device);
/**
* Uses sysfs to get the size of a block device or partition given a device id
*/
off_t partition_size(dev_t device_id);
// for debugging
std::string print_sys_info();
private:
/**
* parse the string to figure out which cpus are online
* the format is like 0-7,9,12,32-36 i.e ranges of numbers separated by commas
*/
static std::set<unsigned int> str_to_cpu_set(const char * s);
/**
* device id's mapped to their device or parition name, initialized by init_sys_info
*/
std::map<dev_t, std::string> id_to_device;
};
}
#endif // DISKSPD_SYS_INFO_H