diff --git a/CMakeLists.txt b/CMakeLists.txt index a63c8bc..b1a501e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 2.6) +cmake_minimum_required(VERSION 3.5) project(monitor) find_package(Curses REQUIRED) diff --git a/include/all_processes.h b/include/all_processes.h index 7a5e670..eb91b0f 100644 --- a/include/all_processes.h +++ b/include/all_processes.h @@ -1,11 +1,11 @@ #ifndef ALL_PROCESSES_H #define ALL_PROCESSES_H -#include "process.h" - #include #include +#include "process.h" + using std::string; using std::vector; diff --git a/include/system.h b/include/system.h index 12b0289..96db28f 100644 --- a/include/system.h +++ b/include/system.h @@ -4,20 +4,20 @@ #include #include +#include "all_processes.h" #include "process.h" #include "processor.h" -#include "all_processes.h" class System { public: - Processor& Cpu(); - All_Processes& Processes(); - float MemoryUtilization(); - long UpTime(); - int TotalProcesses(); - int RunningProcesses(); - std::string Kernel(); - std::string OperatingSystem(); + Processor& Cpu(); + All_Processes& Processes(); + float MemoryUtilization(); + long UpTime(); + int TotalProcesses(); + int RunningProcesses(); + std::string Kernel(); + std::string OperatingSystem(); // TODO: Define any necessary private members private: diff --git a/src/all_processes.cpp b/src/all_processes.cpp index 7453788..1a8a082 100644 --- a/src/all_processes.cpp +++ b/src/all_processes.cpp @@ -1,7 +1,10 @@ #include "all_processes.h" + #include + #include #include + #include "linux_parser.h" #include "process.h" @@ -65,4 +68,3 @@ void All_Processes::RemoveFinishedProcesses(bool& changed) { } } } - diff --git a/src/format.cpp b/src/format.cpp index 117ac81..90e27a0 100644 --- a/src/format.cpp +++ b/src/format.cpp @@ -1,4 +1,5 @@ #include "format.h" + #include #include #include diff --git a/src/linux_parser.cpp b/src/linux_parser.cpp index d1be0fb..21a98fa 100644 --- a/src/linux_parser.cpp +++ b/src/linux_parser.cpp @@ -1,9 +1,11 @@ +#include "linux_parser.h" + #include + #include #include #include -#include "linux_parser.h" #include "parser_consts.h" #include "parser_helper.h" @@ -69,7 +71,6 @@ vector LinuxParser::Pids() { return pids; } - // Read and return the system memory utilization float LinuxParser::MemoryUtilization() { float memTotal = ParserHelper::GetValueByKey( @@ -82,7 +83,6 @@ float LinuxParser::MemoryUtilization() { return memory; } - // Read and return the system uptime long LinuxParser::UpTime() { string line; @@ -90,21 +90,18 @@ long LinuxParser::UpTime() { return upTime; } - // Read and return the total number of processes int LinuxParser::TotalProcesses() { return ParserHelper::GetValueByKey(ParserConsts::filterProcesses, ParserConsts::kStatFilename); } - // Read and return the number of running processes int LinuxParser::RunningProcesses() { return ParserHelper::GetValueByKey(ParserConsts::filterRunningProcesses, ParserConsts::kStatFilename); } - // Read and return the user associated with a process string LinuxParser::UserByUID(int UID) { string line, user, x; diff --git a/src/main.cpp b/src/main.cpp index 0f21dc0..292bcae 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,9 +1,8 @@ #include + #include "ncurses_display.h" -#include "system.h" #include "process.h" - - +#include "system.h" int main() { System system; diff --git a/src/ncurses_display.cpp b/src/ncurses_display.cpp index 619cddf..a780915 100644 --- a/src/ncurses_display.cpp +++ b/src/ncurses_display.cpp @@ -1,11 +1,13 @@ +#include "ncurses_display.h" + #include + #include #include #include #include #include "format.h" -#include "ncurses_display.h" #include "system.h" using std::string; @@ -78,7 +80,7 @@ void NCursesDisplay::DisplayProcesses(std::vector processes, mvwprintw(window, row, time_column, Format::ElapsedTime(processes[i].UpTime()).c_str()); mvwprintw(window, row, command_column, - processes[i].Command().substr(0, window->_maxx - 46).c_str()); + processes[i].Command().substr(0, getmaxx(window) - 46).c_str()); } } @@ -91,7 +93,7 @@ void NCursesDisplay::Display(System& system, int n) { int x_max{getmaxx(stdscr)}; WINDOW* system_window = newwin(9, x_max - 1, 0, 0); WINDOW* process_window = - newwin(3 + n, x_max - 1, system_window->_maxy + 1, 0); + newwin(3 + n, x_max - 1, getmaxy(system_window) + 1, 0); while (1) { init_pair(1, COLOR_BLUE, COLOR_BLACK); @@ -106,4 +108,4 @@ void NCursesDisplay::Display(System& system, int n) { std::this_thread::sleep_for(std::chrono::seconds(1)); } endwin(); -} \ No newline at end of file +} diff --git a/src/process.cpp b/src/process.cpp index 6aceed2..64a10bc 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -1,4 +1,7 @@ +#include "process.h" + #include + #include #include #include @@ -10,7 +13,6 @@ #include "linux_parser.h" #include "parser_consts.h" #include "parser_helper.h" -#include "process.h" using namespace std; @@ -24,11 +26,9 @@ Process::Process(int pid, long Hertz) : pid_(pid), Hertz_(Hertz) { starttime_ = stof(cpuNumbers[21]); } - // Return this process's ID int Process::Pid() { return pid_; } - // Return this process's CPU utilization double Process::CpuUtilization() { long uptime = LinuxParser::UpTime(); @@ -40,16 +40,15 @@ double Process::CpuUtilization() { return cpu_usage; } - // Return the command that generated this process string Process::Command() { string cmd = ParserHelper::GetValue(to_string(pid_) + ParserConsts::kCmdlineFilename); size_t maxSize = 50; - if(cmd.size() > maxSize) { + if (cmd.size() > maxSize) { cmd.resize(maxSize - 3); cmd = cmd + "..."; - } + } return cmd; } @@ -60,14 +59,12 @@ float Process::RawRam() { return memInKB; } - // Return this process's memory utilization string Process::Ram() { float memInKB = RawRam(); return Format::KBisMB(memInKB); } - // Return the user (name) that generated this process string Process::User() { int UID = ParserHelper::GetValueByKey( @@ -77,7 +74,6 @@ string Process::User() { return user; } - // Return the age of this process (in seconds) long int Process::UpTime() { long uptime = LinuxParser::UpTime(); diff --git a/src/processor.cpp b/src/processor.cpp index 625ecf6..5cdc18c 100644 --- a/src/processor.cpp +++ b/src/processor.cpp @@ -1,4 +1,5 @@ #include "processor.h" + #include #include #include diff --git a/src/system.cpp b/src/system.cpp index 26c7381..e0d9419 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -1,12 +1,13 @@ +#include "system.h" + #include #include +#include "all_processes.h" +#include "format.h" #include "linux_parser.h" #include "process.h" #include "processor.h" -#include "all_processes.h" -#include "system.h" -#include "format.h" using std::string; using std::vector; @@ -14,7 +15,7 @@ using std::vector; // Return the system's CPU Processor& System::Cpu() { return cpu_; } -//Return a container composed of the system's processes +// Return a container composed of the system's processes All_Processes& System::Processes() { return processes_; } // Return the system's kernel identifier (string) @@ -32,5 +33,5 @@ int System::RunningProcesses() { return LinuxParser::RunningProcesses(); } // Return the total number of processes on the system int System::TotalProcesses() { return LinuxParser::TotalProcesses(); } -//Return the number of seconds since the system started running +// Return the number of seconds since the system started running long int System::UpTime() { return LinuxParser::UpTime(); } \ No newline at end of file