-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
112 lines (91 loc) · 2.48 KB
/
main.cpp
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
107
108
109
110
111
112
#include <QCoreApplication>
#include <iostream>
#include <stdio.h>
#include <unistd.h>
#include <ctype.h>
#include <stdlib.h>
#include <cstring>
#include "manager.h"
#include "utils.h"
#include "constants.h"
using namespace std;
int main(int argc, char **argv)
{
char *dFlag = NULL; //display mode flag
char *gFlag = NULL; //gpus to monitor flag
char *rFlag = NULL; //refresh rate flag
int oFlag = 0; //optirun flag
int sFlag = 0; //overSsh flag
int hFlag = 0; //help flag
int flag;
opterr = 0;
//parse arguments
while ((flag = getopt(argc, argv, "d:g:r:hos")) != -1)
{
switch (flag)
{
case 'd': { dFlag = optarg; break;}
case 'g': { gFlag = optarg; break;}
case 'r': { rFlag = optarg; break;}
case 'o': { oFlag = 1; break;}
case 's': { sFlag = 1; break;}
case 'h': { hFlag = 1; break;}
case '?':
{
if ((optopt == 'd') || (optopt == 'g') || (optopt == 'r'))
{
fprintf (stderr, "Option -%c requires an argument.\n", optopt);
}
else if (isprint (optopt))
{
fprintf (stderr, "Unknown option `-%c'.\n", optopt);
}
else
{
fprintf (stderr, "Unknown option character `\\x%x'.\n", optopt);
}
return 1;
}
default: abort ();
}
}
//display the help menu
if(hFlag)
{
displayHelpMenu();
return 0;
}
DisplayMode mode = DEFAULT_DISPLAY_MODE;
//set the mode (specified by the user)
if(dFlag)
{
mode = modeSpecifiedByUser(string(dFlag));
}
int refreshRate = DEFAULT_REFRESH_RATE;
//set the refresh rate (specified by the user)
if(rFlag)
{
refreshRate = refreshRateSpecifiedByUser(string(rFlag));
}
vector<int> gpusToMonitor;
//set the gpus to monitor (specified by the user)
if(gFlag)
{
gpusToMoniterSpecifiedByUser(&gpusToMonitor, string(gFlag));
}
bool optirun = false;
//enable optirun support
if(oFlag)
{
optirun = oFlag;
}
bool overSsh = false;
//enable overSsh command
if(sFlag)
{
overSsh = sFlag;
}
Manager manager(mode, refreshRate, overSsh, optirun);
manager.startMonitoring(gpusToMonitor);
return 0;
}