CPU expandability and MDs
This commit is contained in:
@@ -43,6 +43,4 @@ add_executable(${Build}
|
||||
${PlatformDepSource}
|
||||
)
|
||||
|
||||
target_link_libraries(${Build} ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries(${Build} pthread)
|
||||
target_link_libraries(${Build} Threads::Threads)
|
||||
|
||||
55
CODE_OF_CONDUCT.md
Normal file
55
CODE_OF_CONDUCT.md
Normal file
@@ -0,0 +1,55 @@
|
||||
# "No Ideologies" Code of Conduct
|
||||
|
||||
The following are the guidelines we expect our community members and maintainers to follow.
|
||||
|
||||
* * *
|
||||
|
||||
## Terminology and Scope
|
||||
|
||||
**What defines a "maintainer"?**
|
||||
|
||||
* A maintainer is anyone that interacts with the community on behalf of this project. Amount of code written is not a qualifier. A maintainer may include those who solely help in support roles such as in resolving issues, improving documentation, running or participating in forums/chatrooms, or any other non-coding specific roles. Maintainers also include those that are responsible for the building and upkeep of the project.
|
||||
|
||||
**What defines a "community member"?**
|
||||
|
||||
* Anyone interacting with this project directly, including maintainers.
|
||||
|
||||
**What is the scope of these guidelines?**
|
||||
|
||||
* These guidelines apply only to this project and forms of communication directly related to it, such as issue trackers, forums, chatrooms, and in person events specific to this project. If a member is violating these guidelines outside of this project or on other platforms, that is beyond our scope and any grievances should be handled on those platforms.
|
||||
|
||||
**Discussing the guidelines:**
|
||||
|
||||
* Discussions around these guidelines, improving, updating, or altering them, is permitted so long as the discussions do not violate any existing guidelines.
|
||||
|
||||
* * *
|
||||
|
||||
## Guidelines
|
||||
|
||||
### Guidelines for community members
|
||||
|
||||
This project is technical in nature and not based around any particular non-technical ideology. As such, communication that is based primarily around ideologies unrelated to the technologies used by this repository are not permitted.
|
||||
|
||||
Any discussion or communication that is primarily focused around an ideology, be it about race, gender, politics, religion, or anything else non-technical, is not allowed. Everyone has their own ideological preferences, beliefs, and opinions. We do not seek to marginalize, exclude, or judge anyone for their ideologies. To prevent conflict between those with differing or opposing ideologies, all communication on these subjects are prohibited. Some discussions around these topics may be important, however this project is not the proper channel for these discussions.
|
||||
|
||||
### Guidelines for maintainers
|
||||
|
||||
* Maintainers must abide by the same rules as all other community members mentioned above. However, in addition, maintainers are held to a higher standard, explained below.
|
||||
* Maintainers should answer all questions politely.
|
||||
* If someone is upset or angry about something, it's probably because it's difficult to use, so thank them for bringing it to your attention and address ways to solve the problem. Maintainers should focus on the content of the message, and not on how it was delivered.
|
||||
* A maintainer should seek to update members when an issue they brought up is resolved.
|
||||
|
||||
* * *
|
||||
|
||||
## Appropriate response to violations
|
||||
|
||||
How to respond to a community member or maintainer violating a guideline.
|
||||
|
||||
1. If an issue is created that violates a guideline a maintainer should close and lock the issue, explaining "This issue is in violation of our code of conduct. Please review it before posting again." with a link to this document.
|
||||
1. If a member repeatedly violates the guidelines established in this document, they should be politely warned that continuing to violate the rules may result in being banned from the community. This means revoking access and support to interactions relating directly to the project (issue trackers, chatrooms, forums, in person events, etc.). However, they may continue to use the technology in accordance with its license.
|
||||
1. If a maintainer is in violation of a guideline, they should be informed of such with a link to this document. If additional actions are required of the maintainer but not taken, then other maintainers should be informed of these inactions.
|
||||
1. If a maintainer repeatedly violates the guidelines established in this document, they should be politely warned that continuing to violate the rules may result in being banned from the community. This means revoking access and support to interactions relating directly to the project (issue trackers, chatrooms, forums, in person events, etc.). However, they may continue to use the technology in accordance with its license. In addition, future contributions to this project may be ignored as well.
|
||||
|
||||
* * *
|
||||
|
||||
Based on version 1.0.2 from https://github.com/CodifiedConduct/coc-no-ideologies
|
||||
23
CONTRIBUTING.md
Normal file
23
CONTRIBUTING.md
Normal file
@@ -0,0 +1,23 @@
|
||||
# Contributing
|
||||
First off, we thank you for taking the time to contribute to the universal resource monitor project.
|
||||
|
||||
When contributing or submitting pull requests follow these guidelines or your contribution will not be taken seriously.
|
||||
|
||||
If you want to contribute but don't know what to do, see TODO.txt for a list of tasks that need to be complete, but make sure when you complete one you mark it as such, do not remove it from the list.
|
||||
|
||||
## Make sure your code is
|
||||
- Functional
|
||||
- Maintainable and Scalable
|
||||
- Readable
|
||||
|
||||
## Linting
|
||||
- Tabs - 4 spaces
|
||||
- Same line bracing
|
||||
- Honestly just look around the code base and imitate the style
|
||||
- Keep code well commented
|
||||
|
||||
## Guidelines
|
||||
- See CODE_OF_CONDUCT.md
|
||||
|
||||
## Pull requests we reject
|
||||
Anything from b_boy_ww
|
||||
Binary file not shown.
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <vector>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
|
||||
@@ -9,18 +9,21 @@ public:
|
||||
CPU();
|
||||
|
||||
std::mutex CPU_Mutex;
|
||||
int CPU_PREVIOUS_IDLE;
|
||||
int CPU_PREVIOUS_WORK;
|
||||
int CPU_PREVIOUS_TOTAL;
|
||||
int CPU_IDLE;
|
||||
int CPU_WORK;
|
||||
int CPU_TOTAL;
|
||||
|
||||
int UPDATE_INTERVAL; // s
|
||||
|
||||
std::vector<std::vector<int>> CPU_CORES_WORK_AND_TOTAL;
|
||||
|
||||
void START_CPU_POLLING();
|
||||
static void CPU_POLL(CPU* cpu);
|
||||
void END_CPU_POLLING();
|
||||
|
||||
double CPU_PERCENT();
|
||||
std::vector<double> CPU_CORE_PERCENT();
|
||||
|
||||
virtual ~CPU();
|
||||
private:
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
#include <cpu.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <math.h>
|
||||
|
||||
CPU::CPU() {
|
||||
this->UPDATE_INTERVAL = 1000;
|
||||
this->m_isPolling = false;
|
||||
std::cout << "CPU Class Instantated" << std::endl;
|
||||
}
|
||||
|
||||
void CPU::START_CPU_POLLING() {
|
||||
@@ -17,23 +15,38 @@ void CPU::START_CPU_POLLING() {
|
||||
return;
|
||||
}
|
||||
this->m_isPolling = true;
|
||||
std::cout << "Starting CPU worker thread" << std::endl;
|
||||
std::thread* t = new std::thread(&CPU::CPU_POLL, this);
|
||||
this->m_pollThread = t;
|
||||
std::cout << "Worker CPU thread started" << std::endl;
|
||||
}
|
||||
|
||||
void CPU::CPU_POLL(CPU* cpu) {
|
||||
std::cout << "From CPU Thread Start" << std::endl;
|
||||
std::cout << "New CPU worker thread" << std::endl;
|
||||
|
||||
while (true) {
|
||||
cpu->CPU_Mutex.lock();
|
||||
if (!cpu->m_isPolling) {
|
||||
cpu->CPU_Mutex.unlock();
|
||||
return;
|
||||
}
|
||||
cpu->CPU_PREVIOUS_IDLE++;
|
||||
cpu->CPU_PREVIOUS_TOTAL++;
|
||||
cpu->CPU_IDLE++;
|
||||
cpu->CPU_TOTAL++;
|
||||
cpu->CPU_Mutex.unlock();
|
||||
|
||||
// READ TOTAL CPU
|
||||
unsigned long long luser, nice, system, idle, iowait,
|
||||
irq, softirq;
|
||||
FILE* file = fopen("/proc/stat", "r");
|
||||
fscanf(file, "cpu %llu %llu %llu %llu %llu %llu %llu", &luser,
|
||||
&nice, &system, &idle, &iowait, &irq, &softirq);
|
||||
fclose(file);
|
||||
|
||||
cpu->CPU_Mutex.lock();
|
||||
|
||||
// CALCULATE TOTAL CPU
|
||||
cpu->CPU_PREVIOUS_TOTAL = cpu->CPU_TOTAL;
|
||||
cpu->CPU_PREVIOUS_WORK = cpu->CPU_WORK;
|
||||
cpu->CPU_TOTAL = luser + nice + system + idle + iowait + irq + softirq;
|
||||
cpu->CPU_WORK = luser + nice + system;
|
||||
|
||||
cpu->CPU_Mutex.unlock();
|
||||
sleep(1);
|
||||
}
|
||||
@@ -50,9 +63,18 @@ void CPU::END_CPU_POLLING() {
|
||||
|
||||
double CPU::CPU_PERCENT() {
|
||||
this->CPU_Mutex.lock();
|
||||
|
||||
long double workOverTime = this->CPU_PREVIOUS_WORK - this->CPU_WORK;
|
||||
long double totalOverTime = this->CPU_PREVIOUS_TOTAL - this->CPU_TOTAL;
|
||||
this->CPU_Mutex.unlock();
|
||||
return (double)this->CPU_TOTAL;
|
||||
|
||||
double percent = (workOverTime / totalOverTime) * 100;
|
||||
if (isnan(percent)) percent = -1;
|
||||
return (double)percent;
|
||||
}
|
||||
|
||||
std::vector<double> CPU::CPU_CORE_PERCENT() {
|
||||
std::vector<double> output;
|
||||
return output;
|
||||
}
|
||||
|
||||
CPU::~CPU() {
|
||||
|
||||
@@ -8,10 +8,8 @@ int main(int argc, char** argv) {
|
||||
|
||||
cpu->START_CPU_POLLING();
|
||||
|
||||
usleep(1000000);
|
||||
while(1) {
|
||||
std::cout << cpu->CPU_PERCENT() << std::endl;
|
||||
|
||||
std::cout << "TOTAL CPU USAGE: " << cpu->CPU_PERCENT() << std::endl;
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user