-
Notifications
You must be signed in to change notification settings - Fork 0
/
manager.h
106 lines (85 loc) · 3.04 KB
/
manager.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
* Copyright (C) 2015 Mountassir El Hafi, ([email protected])
*
* Manager.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 MANAGER_H_
#define MANAGER_H_
#include <vector>
#include "stats_reader.h"
#include "console_writer.h"
#include "constants.h"
#include "gpu.h"
using namespace std;
/*
* Manager class: set up list of gpus, probe Nvidia drivers
* for state updates and print results for the user
*/
class Manager
{
private:
StatsReader statsReader; //get gpu states
ConsoleWriter consoleWriter; //print gpu states on screen
vector<Gpu> allGpus; //list of all gpus available on the system
DisplayMode displayMode; //what to print on screen for each gpu
int refreshRate; //monitoring refresh rate
//get all available gpus on the system
void buildGpus();
//update gpu states manually
void updateGpuStates(Gpu *gpu, const GpuStates &states);
//get gpu identifier and name from Nvidia output;
//[0] mountassir-workstation:0[gpu:0] (GeForce GTX 770)
//to gpuId = [gpu:0] and gpuName = GeForce GTX 770
void decomposeGpuIdentifier(const string &gpuIdentifier,
string *gpuId,
string *gpuName);
//generate random gpu state
//(used for testing when no gpu available)
void generateState(GpuStates *state);
//print all available gpus
void dumpAllGpus();
//check if their is no gpu to monitor
bool noGpusToMonitor();
public:
Manager(DisplayMode mode,
int refresh,
bool overSsh,
bool optirun = false) :
statsReader(overSsh, optirun),
displayMode(mode),
refreshRate(refresh) {};
Manager() :
statsReader(false, false),
displayMode(CURRENT_NEXT_TO_HISTORY),
refreshRate(DEFAULT_REFRESH_RATE) {};
//start monitoring the given gpus
void startMonitoring(const vector<int> &gpusToMonitor);
//probe Nvidia drivers for current gpu states
void refreshGpus();
//monitor and display; current state only,
//history only or both for each gpu
void monitorCurrentAndPreviousStates();
void monitorCurrentAndPreviousStates(const vector<int> &gpusToMonitor);
//monitor and display; current state for all gpus
//then all of their previous states
void monitorCurrentThenPreviousStates();
void monitorCurrentThenPreviousStates(const vector<int> &gpusToMonitor);
//print the most recent state this gpu was at
void printCurrentGpuState(const Gpu &gpu);
//print all previous gpu states
void printHistoryGpuState(const Gpu &gpu);
//change the monitoring refresh rate
void setRefreshRate(int refresh) { refreshRate = refresh;};
};
#endif