This repository has been archived by the owner on Sep 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
metrics-display.cpp
86 lines (69 loc) · 4.59 KB
/
metrics-display.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
//
// metrics-display.cpp - file with definitions of functions related to displaying the metrics
//
// 2022-2023 Damian Strojek @damianStrojek
// Piotr Garbowski @dideek
// Jakub Wasniewski @wisnia01
//
// External libraries
#include <iostream> // cin, cout
#include <string> // string, to_string
#include <chrono> // system_clock, put_time, now
#include <iomanip> // setw, setprecision
// Internal headers
#include "metrics.h"
#include "metrics-display.h"
void printMetricPair(std::string metricName, int metricValue, std::string metricUnit,
std::string metricNameTwo, int metricValueTwo, std::string metricUnitTwo){
std::string value = std::to_string(metricValue), value2 = std::to_string(metricValueTwo);
std::cout << metricName << std::right << std::setfill('.') <<
std::setw(30 - metricName.length()) << value << " " << metricUnit;
for(int i = 0; i < 20 - metricUnit.length(); i++) std::cout << ' ';
std::cout << std::left << metricNameTwo << std::right << std::setfill('.') <<
std::setw(30 - metricNameTwo.length()) << value2 << " " << metricUnitTwo << std::endl;
};
// This function prints the second metric as float value
void printMetricPairFloat(std::string metricName, int metricValue, std::string metricUnit,
std::string metricNameTwo, float metricValueTwo, std::string metricUnitTwo){
std::string value = std::to_string(metricValue), value2 = std::to_string(metricValueTwo);
std::cout << metricName << std::right << std::setfill('.') <<
std::setw(30 - metricName.length()) << value << " " << metricUnit;
for(int i = 0; i < 20 - metricUnit.length(); i++) std::cout << ' ';
std::cout << std::left << metricNameTwo << std::right << std::setfill('.') <<
std::setw(30 - metricNameTwo.length()) << std::setprecision(2) << value2 << " " << metricUnitTwo << std::endl;
};
void printMetrics(SystemMetrics* systemMetrics, ProcessorMetrics* processorMetrics,
InputOutputMetrics* inputOutputMetrics, MemoryMetrics* memoryMetrics,
NetworkMetrics* networkMetrics, PowerMetrics* powerMetrics){
auto now = std::chrono::system_clock::now();
std::time_t now_c = std::chrono::system_clock::to_time_t(now);
std::cout << std::put_time(std::localtime(&now_c), "%Y-%m-%d %X") << std::endl;
std::cout << "System:";
for(int i = 0; i < 43; i++) std::cout << ' ';
std::cout << "Network:\n";
printMetricPair("Running Processes", systemMetrics->processesRunning, "", "Received Packets", networkMetrics->receivedData,"");
printMetricPair("All Processes", systemMetrics->processesAll, "", "Received Packets Rate", networkMetrics->receivePacketRate,"KB/s");
printMetricPair("Context Switch Rate", systemMetrics->contextSwitchRate, "/s", "Sent Packets", networkMetrics->sentData,"");
printMetricPair("Interrupt Rate", systemMetrics->interruptRate, "/s", "Sent Packets Rate", networkMetrics->sendPacketsRate,"KB/s");
std::cout << '\n';
std::cout << "Memory:";
for(int i = 0; i < 43; i++) std::cout << ' ';
std::cout << "Processor:\n";
printMetricPair("Memory Used", memoryMetrics->memoryUsed, "MB", "Time User", processorMetrics->timeUser, "USER_HZ");
printMetricPair("Memory Cached", memoryMetrics->memoryCached, "MB", "Time System", processorMetrics->timeSystem, "USER_HZ");
printMetricPair("Swap Used", memoryMetrics->swapUsed, "MB", "Time Idle", processorMetrics->timeIdle, "USER_HZ");
printMetricPair("Swap Cached", memoryMetrics->swapCached, "MB", "Time I/O Wait", processorMetrics->timeIoWait, "USER_HZ");
printMetricPair("Memory Active", memoryMetrics->memoryActive, "MB", "Time IRQ", processorMetrics->timeIRQ, "USER_HZ");
printMetricPair("Memory Inactive", memoryMetrics->memoryInactive, "MB", "Time Steal", processorMetrics->timeSteal, "USER_HZ");
printMetricPairFloat("Pages Read", memoryMetrics->pageInRate, "pages/s", "LLC Store Misses", processorMetrics->cacheLLCStoreMissRate, "%");
printMetricPairFloat("Pages Saved", memoryMetrics->pageOutRate, "pages/s", "LLC Load Misses", processorMetrics->cacheLLCLoadMissRate, "%");
std::cout << std::endl;
std::cout << "I/O for PID 1:";
for(int i = 0; i < 36; i++) std::cout << ' ';
std::cout << "Power:\n";
printMetricPairFloat("Data Read ", inputOutputMetrics->dataRead, "MB", "Processor Power", powerMetrics->processorPower, "W");
printMetricPairFloat("Data Written ", inputOutputMetrics->dataWritten, "MB", "System Power", powerMetrics->systemPower, "W");
printMetricPairFloat("Read Operations ", inputOutputMetrics->readOperationsRate, "/s", "Memory Power", powerMetrics->memoryPower, "W");
printMetricPairFloat("Write Operations ", inputOutputMetrics->writeOperationsRate, "/s", "GPU Power", powerMetrics->gpuPower, "W");
std::cout << std::endl;
};