Skip to content

Ace-Krypton/CUT

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CUT (CPU Usage Tracker)

CUT is a multi-threaded C++ application designed to track and analyze CPU usage on a system. It reads data from the "/proc/stat" file, processes the information, and displays the CPU usage for each CPU core.

Prerequisites

Before running the application, ensure that you have the following dependencies installed:

  • C++ compiler supporting C++20
  • CMake version 3.25 or higher
  • ncurses library

Usage

To use it, follow these steps:

  1. Create a build directory:
  2. mkdir build
    cd build

  3. Generate the build files using CMake:
  4. cmake ..

  5. Build the application:
  6. make

  7. Run the compiled executable:
  8. ./CUT

Code Overview

The application consists of several classes:

  • Reader: Reads data from the /proc/stat file and pushes it into a buffer for analysis.
  • Logger: Receives messages from all threads and writes them into a log file.
  • Printer: Prints the CPU usage information to the console.
  • Analyzer: Analyzes CPU data received from the reader and calculates the CPU usage.

The main() function creates instances of these classes, starts the corresponding threads, and manages the termination process. It also registers a signal handler to handle the SIGINT signal (generated when the user interrupts the program).

Each class has its own implementation file (Reader.cpp, Logger.cpp, Printer.cpp, and Analyzer.cpp) that defines the member functions and implements the necessary logic.

Thread Communication

The communication between threads is achieved using lock-free SPSC (Single Producer Single Consumer) queues. These queues act as buffers for passing data between the reader, logger, analyzer, and printer threads.

  • The Reader thread reads data from the /proc/stat file and pushes it into the logger and analyzer buffers.
  • The Logger thread receives messages from all threads and writes them into a log file.
  • The Analyzer thread analyzes the CPU data received from the reader and calculates the CPU usage, pushing it into the printer buffer.
  • The Printer thread prints the CPU usage information to the console.

Termination

The termination of the application is controlled by a termination flag (terminate). When the SIGINT signal is received (e.g., by pressing CTRL+C), the signal handler sets the termination flag to true, and the main thread stops all the worker threads. This ensures a graceful shutdown of the application.

Contributing

Contributions to the project are welcome. If you find any issues or have suggestions for improvements, please create a GitHub issue or submit a pull request.

License

The code is open source and available under the MIT License. Feel free to modify and distribute it as needed.

About

MultiThreaded CPU Usage Tracker

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published