Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/my implementaion #35

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.PHONY: all
all: format test build
all: format clean build

.PHONY: format
format:
Expand Down
4 changes: 2 additions & 2 deletions 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
}; // namespace Format
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
36 changes: 28 additions & 8 deletions include/process.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,36 @@ 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
10 changes: 8 additions & 2 deletions include/processor.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
#ifndef PROCESSOR_H
#define PROCESSOR_H
#include <string>
#include <vector>

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
34 changes: 24 additions & 10 deletions include/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,33 @@

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