-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathmain.cpp
84 lines (71 loc) · 2.09 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
/*
* cpu-stat - a simple program to get CPU stats on Linux
*
* by Davide Coppola - http://www.davidecoppola.com
*
* 0.00.01 19-Dec-2016 First basic version.
* 0.00.02 21-Dec-2016 New code design.
* 0.00.03 22-Dec-2016 Introduced options.
* 0.01.00 25-Dec-2016 Implemented all basic features.
* 0.01.01 25-Dec-2016 Introduced OptionsParser and code polishing.
* 0.01.02 27-Dec-2016 Added scons build system.
*
*/
#include "CPUSnapshot.h"
#include "CPUStatsPrinter.h"
#include "OptionsParser.h"
#include <chrono>
#include <thread>
// -- PROGRAM DATA --
const char * STR_APP_NAME = "cpu-stat";
const char * STR_APP_VERSION = "0.01.02";
int main(int argc, char * argv[])
{
// -- PARSE OPTIONS --
OptionsParser options(argc, argv, STR_APP_NAME, STR_APP_VERSION);
// exit after error
if(options.HasError())
return options.GetErrorCode();
// exit after printing help or version
if(options.ExitRequested())
return 0;
// -- GET SNAPSHOTS --
// snapshot 1
CPUSnapshot s1;
// pause
std::this_thread::sleep_for(std::chrono::milliseconds(options.GetOptionDelay()) );
// snapshot 2
CPUSnapshot s2;
// -- PRINT STATS --
CPUStatsPrinter printer(s1, s2);
printer.SetPrecision(options.GetOptionPrecision());
printer.SetVerbose(options.GetOptionVerbose());
if(options.GetOptionPrintAll())
{
if(options.GetOptionFull())
printer.PrintFullStatePercentageAll();
else if(options.GetOptionState() >= 0)
printer.PrintStatePercentageAll(options.GetOptionState());
else
printer.PrintActivePercentageAll();
}
else if(options.GetOptionCPU() >= 0)
{
if(options.GetOptionFull())
printer.PrintFullStatePercentageCPU(options.GetOptionCPU());
else if(options.GetOptionState() >= 0)
printer.PrintStatePercentageCPU(options.GetOptionState(), options.GetOptionCPU());
else
printer.PrintActivePercentageCPU(options.GetOptionCPU());
}
else
{
if(options.GetOptionFull())
printer.PrintFullStatePercentageTotal();
else if(options.GetOptionState() >= 0)
printer.PrintStatePercentageTotal(options.GetOptionState());
else
printer.PrintActivePercentageTotal();
}
return 0;
}