-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats_reader.h
81 lines (66 loc) · 2.14 KB
/
stats_reader.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
76
77
78
79
80
81
/*
* Copyright (C) 2015 Mountassir El Hafi, ([email protected])
*
* Reader.h: Part of gmonitor
*
* gmonitor is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* gmonitor is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with gmonitor. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef STATS_READER_H_
#define STATS_READER_H_
#include <iostream>
#include <vector>
#include <stdio.h>
#include "constants.h"
using namespace std;
namespace
{
const int NUMBER_OF_SUPPORTED_STATES = 7;
enum StateIndex
{
GRAPHICS_USAGE_INDEX = 0,
VRAM_BANDWIDTH_INDEX = 1,
VIDEO_USAGE_INDEX = 2,
PCIE_BADWIDTH_INDEX = 3,
CORE_TEMP_INDEX = 4,
TOTAL_VRAM_INDEX = 5,
USED_VRAM_INDEX = 6,
};
}
/*
* StatsReader class: probes Nvidia drivers and get the appropriate
* gpu states; gpu usage, memory usage ...
*/
class StatsReader
{
private:
//execute a bash command and return the output as an array doubles
bool getDoubleFromSystemCall(string &command, std::vector<double> *values);
//functions returning bash commands to be executed
//these commands will call Nvidia drivers with the
//corresponding arguments, these commands may even
//perform some sort of stream processing (grep, sed...)
void gpuListCommand(string *gpuList);
void getAllGpuStatesCommand(const string &gpuId, string *command);
string checkIfSshCommand(string &command);
bool _overSsh;
bool _optirun;
public:
//get the list of available gpus on this machine
bool getGpuList(vector<string> *gpuList);
//get the current states of a particular gpu
void getGpuStates(GpuStates *gpuStates,
const string &gpuId);
void useOptirun(const bool withOptirun);
StatsReader(bool overSsh, bool withOptirun = false) :
_overSsh(overSsh), _optirun(withOptirun) {};
};
#endif