Write a C program that will report different metrics of the utilization of a given system as described below.
The program will present this information in real-time in graphical form by displaying at each instant of time how the quantities are changing.
You should target this program to work in a Linux type OS, e.g. the workstations from the IA-3170 lab.
I.e. if your code does not compile and/or run in the lab machines will receive a zero.
See instructions in how to connect remotely to the computer in the labs here Download here.
The program should accept several command line arguments:
--memory
to indicate that only the memory usage should be generated
--cpu
to indicate that only the CPU usage should be generated
--cores
to indicate that only the cores information should be generated
--samples=N
if used the value N will indicate how many times the statistics are going to be collected and results will be average and reported based on the N number of repetitions.
If not value is indicated the default value will be 20.
--tdelay=T
to indicate how frequently to sample in micro-seconds (1 microsec = 10 -6 sec.)
If not value is indicated the default value will be 0.5 sec = 500 milisec = 500000 microsec.
These last two arguments can also be specified as positional arguments if not flag is indicated, in the corresponding order: samples tdelay.
In this case, these argument should be the first ones to be passed to the program.
CLA Syntax:
./myMonitoringTool [samples [tdelay]] [--memory] [--cpu] [--cores] [--samples=N] [--tdelay=T]
Default Behavior
· If no arguments are passed the program should present all the information about memory utilization, CPU utilization and cores
· Default values for samples=20 , tdelay=500000 microsec.
Expected Output
The information presented by the monitoring tool should be directed to STDOUT and should include:
· running parameters:
o number of samples
o samples frequency
o memory self-utilization (ie. how much memory the monitoring tool is actually using)
· memory usage
o plot memory utilization per sample in GB
o display axes with memory limits scale
· cpu usage
o report how much utilization of the CPU is being done in percentage
o plot CPU utilization per sample in %
o display corresponding axes
· cores
o report number of cores and max. frequency
o diagram matching the number of detected cores
· flagged arguments can be passed to the tool in any order but the positional arguments indicating samples and tdelay must always be the first ones
· independently of the order in which the flagged arguments are passed the order of display will always be (depending on which information is requested by the corresponding argument):
o "Memory Utilization",
o "CPU Utilization",
o "Cores & Frequency"
General remarks:
· write proper modular code, i.e. with functions that have clearly specified goals and tasks using proper arguments and parameters
· do not use global variables
· do not hardcode any values, like "32 GB" or "X number of cores" or "Y GHz"
· include comments and documentation
· It is NOT allowed to use any shell command to be run through your C program.
No credits will be given for functionalities implemented using shell commands.
Instead implement the required functionalities using C coding and the references mentioned below.
Some useful resources:
While working on the assignment, you may want to complement the material presented in class with more details on:
o command line arguments parsing
o files and strings manipulation
o depending on how end up doing the actual implementation, "ESCape codes" (see below) for managing different elements to output to screen, e.g. positioning, refreshing, cleaning, etc.
o auxiliary standard C-libraries to consider using/investigating (see the corresponding refs or the man pages):
sys/resource.h -- https://man7.org/linux/man-pages/man0/sys_resource.h.0p.html
sys/utsname.h -- https://man7.org/linux/man-pages/man2/uname.2.html
sys/sysinfo.h -- https://man7.org/linux/man-pages/man2/sysinfo.2.html
sys/types.h -- https://man7.org/linux/man-pages/man0/sys_types.h.0p.html
unistd.h -- https://man7.org/linux/man-pages/man0/unistd.h.0p.html
o recall that in Linux EVERYTHING is a FILE, and some useful ones for this assignment are:
/proc/cpuinfo -- https://man7.org/linux/man-pages/man5/proc_cpuinfo.5.htmlLinks to an external site.
/sys/devices/system/cpu/cpu0/cpufreq/ -- https://docs.kernel.org/cpu-freq/cpufreq-stats.htmlLinks to an external site.
o ON ESCAPE CODES
Depending on the approach you decide to take, some of the following ones can be useful "Escape codes" to consider:
"\033[2J" /* clear the screen */
"\033[H" /* position cursor at top-left corner */
printf("\x1b[%d;%df", row, col); /* move to position col,row */
· More details on Escape Codes and extensive list is available at https://en.wikipedia.org/wiki/ANSI_escape_codeLinks to an external site.
· Notice that in the standard ANSI representation, the upper left-corner of the terminal is represented by (1,1) --i.e. NOT (0,0)--.
Examples of a possible implementation for different ways of running our monitoring tool:
$ ./myMonitoringTool
In this assignment we will continue working in the program you developed for Assignment #1.
We will implement a version of it which allows the program to run the different queries of the system concurrently.
For doing this, the following elements are critical to be implemented as follow:
1.
1. you should fix any issues raised in your A1.
2. your implementation for A1 should be modular, meaning that you should have at least one function for each of the reported analysis: memory utilization, CPU utilization and cores count and maximum frequency..
3. your implementation should have at least three modules.
2.
3. Additionally,
1.
1. The new version of the code will intercept signals coming from Ctrl-Z and Ctrl-C.
For the former, it will just ignore it as the program should not be run in the background while running interactively.
For the latter, the program will ask the user whether it wants to quit or not the program and proceed according to the user response.
2. The code will include error-checking for any possible circumstance where resources to be requested from the system may not be available and report them to standard error.
Important details:
· The goal is to have one process launched per each function reporting memory utilization, CPU utilization, cores count and cores maximum frequency; running concurrently.
There are different ways in which this can be achieved, but full marks will be given to implementations employing pipes to communicate the results to the main process.
· Similarly, it is critical that the order of the output is exactly as show in the examples presented in A1, no variations around this will be accepted.
Ie. you must guarantee that the output of your implementation consistently (ie. for every iteration) looks like
![]()
· You will need to fix the points raised in your review of A1 to make sure everything is working as expected.
· In particular, for CPU utilization calculations, in A1 we accepted different approaches and interpretations but now is time to make it right, so please follow this approach:
o you will need to take two samples of the CPU usage, e.g. at times t1 and t2, per each sample in the program
o use the /proc/stat file to read the data from the CPU times.
The following documents will be helpful to understand the format of the file and the meaning of the different times reported in the file:
https://www.idnt.net/en-US/kb/941772Links to an external site.
https://docs.kernel.org/filesystems/proc.htmlLinks to an external site. -- look for "1.7 Miscellaneous kernel statistics in /proc/stat"
o after you read these documents, then calculate the following quantities
§ total cpu utilization time: Ti = useri + nicei + sysi + idlei + IOwaiti + irqi + softirqi
§ idle time: Ii = idlei
where i represents a sampling time; hence the CPU utilization at time i is given by Ui=Ti−Ii
o Then, the CPU utilization will be given by, U2−U1T2−T1×100
o You should be careful with the order in which you implement these operations and the type of the variables employed, check the actual values and see what conclusions you can draw from them.
· Also, related to CPU utilization I'd recommend to use the tdelay to wait between the samples taken at i=1 and i=2.
Of course this needs to be consistent with the overall behavior of the tool, i.e. the tool still should work as expected in terms of samples and delay if only memory utilization is indicated.
· We will compare the total runtime of your program using the time command, and it should not exceed for more than 1% the one given by tdelay × samples
General Remarks
· You should target this program to work in the Linux type OS available in the workstations from the IA-3170 lab.
I.e. if your code does not compile and/or run in the lab machines will receive a zero.
· Write proper modular code, i.e. with functions that have clearly specified goals and tasks using proper arguments and parameters
· Do not use global variables
· Include error-checking mechanism and report any errors or problems to standard error.
· Include comments and documentation as detailed in Piazza Post https://piazza.com/class/m5j5smmmxyx2s0/post/197Links to an external site.
· Do not use any shell command to be run through your C program.
Instead implement the required functionalities using C coding and the references mentioned below.
· Processes leading to "pathological" states will be penalized.