Skip to content

Commit

Permalink
[RH] Add my implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
rhassan-rgb committed Oct 7, 2023
1 parent 9f0948e commit a1f51b4
Show file tree
Hide file tree
Showing 12 changed files with 620 additions and 121 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ add_executable(monitor ${SOURCES})

set_property(TARGET monitor PROPERTY CXX_STANDARD 17)
target_link_libraries(monitor ${CURSES_LIBRARIES})
# TODO: Run -Werror in CI.
target_compile_options(monitor PRIVATE -Wall -Wextra)

target_compile_options(monitor PRIVATE -Wall -Wextra -Werror)
2 changes: 1 addition & 1 deletion include/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <string>

namespace Format {
std::string ElapsedTime(long times); // TODO: See src/format.cpp
std::string ElapsedTime(long times);
}; // namespace Format

#endif
1 change: 1 addition & 0 deletions include/linux_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ std::string Ram(int pid);
std::string Uid(int pid);
std::string User(int pid);
long int UpTime(int pid);
std::vector<std::string> CpuUtilization(int pid);
}; // namespace LinuxParser

#endif
37 changes: 29 additions & 8 deletions include/process.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,37 @@ It contains relevant attributes as shown below
*/
class Process {
public:
int Pid(); // TODO: See src/process.cpp
std::string User(); // TODO: See src/process.cpp
std::string Command(); // TODO: See src/process.cpp
float CpuUtilization(); // TODO: See src/process.cpp
std::string Ram(); // TODO: See src/process.cpp
long int UpTime(); // TODO: See src/process.cpp
bool operator<(Process const& a) const; // TODO: See src/process.cpp
Process(int pid);
int Pid();
std::string User();
std::string Command();
float CpuUtilization();
std::string Ram();
long int UpTime();
bool operator<(Process const& a) const;
bool operator==(Process const& a) const;
bool KeepAlive();
void KeepAlive(bool);
void UpdateProcess();

// TODO: Declare any necessary private members
// DONE: Declare any necessary private members
private:
int pid_;
bool keepAlive_;
std::string memUsage_;
float cpuUsage_;
float currentActiveJiffies_;
float currentTotalJiffies_;
std::string username_;
std::string command_;
bool userInitialized_;
bool commandInitialized_;
long upTime_;

void updateUpTime();
void updateCpuUsage(void);
void updateMemUsage(void);

};

#endif
11 changes: 9 additions & 2 deletions include/processor.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
#ifndef PROCESSOR_H
#define PROCESSOR_H
#include <vector>
#include <string>


class Processor {
public:
float Utilization(); // TODO: See src/processor.cpp
float Utilization();
Processor();

// TODO: Declare any necessary private members
// DONE: Declare any necessary private members
private:
static bool IsInitializied_;
float CurrentRunTime_;
float CurrentTotalTime_;
};

#endif
36 changes: 25 additions & 11 deletions include/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,39 @@

#include <string>
#include <vector>

#include "process.h"
#include "processor.h"

class System {
public:
Processor& Cpu(); // TODO: See src/system.cpp
std::vector<Process>& Processes(); // TODO: See src/system.cpp
float MemoryUtilization(); // TODO: See src/system.cpp
long UpTime(); // TODO: See src/system.cpp
int TotalProcesses(); // TODO: See src/system.cpp
int RunningProcesses(); // TODO: See src/system.cpp
std::string Kernel(); // TODO: See src/system.cpp
std::string OperatingSystem(); // TODO: See src/system.cpp
Processor& Cpu();
std::vector<Process>& Processes();
float MemoryUtilization();
long UpTime();
int TotalProcesses();
int RunningProcesses();
std::string Kernel();
std::string OperatingSystem();

// TODO: Define any necessary private members
// DONE: Define any necessary private members
private:
Processor cpu_ = {};
Processor cpu_;
std::vector<Process> processes_ = {};
std::string systemOS_;
bool osRead_{false};
std::string systemKernel_;
bool kernelRead_{false};
float memoryUtilization_;
long upTime_;
int totalProcesses_;
int runningProcesses_;

void updateMemoryUtilization();
void updateUpTime();
void updateTotalProcesses();
void updateRunningProcesses();
void updateSystemReadings();

};

#endif
16 changes: 12 additions & 4 deletions src/format.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
#include <string>

#include "format.h"

#include <string>

using std::string;

// TODO: Complete this helper function
// DONE: Complete this helper function
// INPUT: Long int measuring seconds
// OUTPUT: HH:MM:SS
// REMOVE: [[maybe_unused]] once you define the function
string Format::ElapsedTime(long seconds[[maybe_unused]]) { return string(); }
string Format::ElapsedTime(long seconds) {
string elapsedTime;

elapsedTime = std::to_string(seconds / (60 * 60)) + ":" +
std::to_string((seconds % (60 * 60)) / 60) + ":" +
std::to_string(seconds % 60);

return elapsedTime;
}
Loading

0 comments on commit a1f51b4

Please sign in to comment.