Skip to content

updates from Mac #4

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Binary file added .DS_Store
Binary file not shown.
11 changes: 8 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
cmake_minimum_required(VERSION 2.8.12)
project(monitor)

set(CURSES_NEED_NCURSES TRUE)
find_package(Curses REQUIRED)
include_directories(${CURSES_INCLUDE_DIRS})
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W -Wextra -Wall -Werror -ansi -pedantic -pthread --std=c++11")
include_directories(includes libs/c++ /opt/homebrew/opt/ncurses/include)
link_directories(/opt/homebrew/opt/ncurses/lib)
link_libraries(ncurses)

# set(CURSES_NEED_NCURSES TRUE)
# find_package(ncurses REQUIRED)
# include_directories(${CURSES_INCLUDE_DIRS})

include_directories(include)
file(GLOB SOURCES "src/*.cpp")
Expand Down
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
CXXFLAGS += -W -Wextra -Wall -Werror -ansi -pedantic
CXXFLAGS += -pthread --std=c++11 -Iincludes -Ilibs/c++ -I/usr/local/opt/ncurses/include
LDFLAGS += -lncurses -L/usr/local/opt/ncurses/lib

# existing Makefile targets go here

.PHONY: all
all: format test build
all: format build

.PHONY: format
format:
Expand All @@ -22,3 +28,4 @@ debug:
.PHONY: clean
clean:
rm -rf build

14 changes: 7 additions & 7 deletions include/process.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ It contains relevant attributes as shown below
*/
class Process {
public:
Process(int pid): pid_(pid) {};
Process(int pid) : pid_(pid){};
int Pid(); // TODO: See src/process.cpp
std::string User(); // TODO: See src/process.cpp
std::string Command(); // TODO: See src/process.cpp
Expand All @@ -19,12 +19,12 @@ class Process {

// TODO: Declare any necessary private members
private:
int pid_;
std::string user_;
std::string command_;
float cpuUtilization_;
std::string ram_;
long int upTime_;
int pid_;
std::string user_;
std::string command_;
float cpuUtilization_;
std::string ram_;
long int upTime_;
};

#endif
2 changes: 1 addition & 1 deletion include/processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class Processor {
public:
Processor() : prevTotal_(0), prevIdle_(0) {};
Processor() : prevTotal_(0), prevIdle_(0){};
float Utilization(); // TODO: See src/processor.cpp

// TODO: Declare any necessary private members
Expand Down
5 changes: 3 additions & 2 deletions src/format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ string Format::ElapsedTime(long seconds) {
int hours = seconds / 3600;
int minutes = (seconds % 3600) / 60;
int sec = seconds % 60;
timeFormat = std::to_string(hours) + ":" + std::to_string(minutes) + ":" + std::to_string(sec);

timeFormat = std::to_string(hours) + ":" + std::to_string(minutes) + ":" +
std::to_string(sec);

return timeFormat;
}
16 changes: 8 additions & 8 deletions src/linux_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>

using std::stof;
using std::string;
using std::to_string;
Expand Down Expand Up @@ -60,13 +60,12 @@ vector<int> LinuxParser::Pids() {
// Is every character of the name a digit?
string filename(file->d_name);
if (std::all_of(filename.begin(), filename.end(), isdigit)) {
//int pid = stoi(filename);
long long int pid0;
try {
long long int pid = stoi(filename);
pid0 = stoi(filename);
} catch (std::out_of_range& e) {
std::cerr << "Number is out of range: " << e.what() << '\n';
}
long long int pid0 = stoi(filename);
pids.push_back(pid0);
}
}
Expand Down Expand Up @@ -120,11 +119,12 @@ float LinuxParser::MemoryUtilization() {
long LinuxParser::UpTime() {
std::ifstream filestream(kProcDirectory + kUptimeFilename);
std::string line;
long uptime = 0;
if (!filestream.is_open()) {
std::cerr << "Failed to open file UpTime: "
<< kProcDirectory + kUptimeFilename << std::endl;
}
long uptime;
} else {

while (getline(filestream, line)) {
std::istringstream iss(line);
// read info
Expand All @@ -138,6 +138,7 @@ long LinuxParser::UpTime() {
}
break;
}
filestream.close();}
return uptime;
}

Expand Down Expand Up @@ -218,7 +219,7 @@ int LinuxParser::TotalProcesses() {
}
std::string currentKey;
std::string currentValue;
long long int totalProcesses;
long long int totalProcesses = 0;
while (getline(filestream, line)) {
std::istringstream iss(line);
// read info
Expand All @@ -232,7 +233,6 @@ int LinuxParser::TotalProcesses() {
}
break;
}

}

return totalProcesses;
Expand Down
4 changes: 3 additions & 1 deletion src/ncurses_display.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#include "ncurses_display.h"

#include <curses.h>
#include <ncurses.h>
#include <chrono>
#include <string>
#include <thread>
#include <vector>

#include "format.h"
#include "ncurses_display.h"
#include "system.h"

using std::string;
Expand Down
12 changes: 9 additions & 3 deletions src/process.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#include "process.h"

#include <unistd.h>

#include <cctype>
#include <sstream>
#include <string>
#include <vector>

#include "process.h"
#include "linux_parser.h"

using std::string;
Expand All @@ -15,7 +17,9 @@ using std::vector;
int Process::Pid() { return pid_; }

// TODO: Return this process's CPU utilization
float Process::CpuUtilization() { return cpuUtilization_ = LinuxParser::cpuProcessUtilization(pid_); }
float Process::CpuUtilization() {
return cpuUtilization_ = LinuxParser::cpuProcessUtilization(pid_);
}

// TODO: Return the command that generated this process
string Process::Command() { return command_ = LinuxParser::Command(pid_); }
Expand All @@ -31,4 +35,6 @@ long int Process::UpTime() { return upTime_ = LinuxParser::UpTime(pid_); }

// TODO: Overload the "less than" comparison operator for Process objects
// REMOVE: [[maybe_unused]] once you define the function
bool Process::operator<(Process const& a[[maybe_unused]]) const { return true; }
bool Process::operator<(Process const& a [[maybe_unused]]) const {
return true;
}
2 changes: 1 addition & 1 deletion src/processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ float Processor::Utilization() {
float nice = std::stoi(currentUtilization[1]);
float system = std::stoi(currentUtilization[2]);
float idle = std::stoi(currentUtilization[3]);
float iowait = 0.0; //std::stoi(currentUtilization[4]);
float iowait = 0.0; // std::stoi(currentUtilization[4]);
float irq = std::stoi(currentUtilization[5]);
float softirq = std::stoi(currentUtilization[6]);
float steal = std::stoi(currentUtilization[7]);
Expand Down
2 changes: 2 additions & 0 deletions src/system.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "system.h"

#include <unistd.h>

#include <cstddef>
#include <set>
#include <string>
Expand Down