środa, 2 stycznia 2019

System statistic (class C++ (g++))

#include <iostream>
#include <stdio.h>
#include <unistd.h>
#include <sys/utsname.h>
#include <sys/sysinfo.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <linux/kernel.h>
using namespace std;

class system_Statistic
{
    private:
    struct utsname uname_Info;
    struct sysinfo sys_Info;
    struct rusage cpu_Times;
   
    char *sysname;
    char *version;
    char *machine;
    float free_RAM;
    int process;
    float total_RAM;
    int time_Process1;
    int time_Process2;
    public:
    system_Statistic()
    {
        uname(&uname_Info);
        sysinfo(&sys_Info);
        getrusage(RUSAGE_SELF,&cpu_Times);
        sysname=uname_Info.sysname;
        version=uname_Info.version;
        machine=uname_Info.machine;
        process=sys_Info.procs;
        free_RAM=sys_Info.freeram/(1024.0*1024.0);
        total_RAM=sys_Info.totalram/(1024.0*1024.0);
        time_Process1=cpu_Times.ru_utime.tv_sec;
        time_Process2=cpu_Times.ru_utime.tv_usec;
    }
    void Report()
    {
        cout<<"Sysname: "<<sysname<<endl;
        cout<<"Version: "<<version<<endl;
        cout<<"Machine: "<<machine<<endl;
        cout<<"Number of processes: "<<process<<endl;
        cout<<"Total RAM: "<<total_RAM<<endl;
        cout<<"Free RAM: "<<free_RAM<<endl;
        cout<<"Time of the process1: "<<time_Process1<<endl;
        cout<<"Time of the process2: "<<time_Process2<<endl;
       
    }
   
};

int main(int argc, char **argv)
{
    system_Statistic Info;
    Info.Report();
    return 0;
}

Brak komentarzy:

Prześlij komentarz