Skip to content

CPU Load Generator allows you to generate a fixed configurable CPU load for a finite time by means of PID regulator.

License

Notifications You must be signed in to change notification settings

GaetanoCarlucci/CPULoadGenerator

Repository files navigation

CPU Load Generator

github-actions-badge mit-badge made-with-python

This script allows to generate a fixed CPU load for a finite or indefinite time period, for one or more CPU cores. A PI controller is employed for this purpose. The script takes in input the desired CPU load and the CPU core on which the load has to be generated. The controller and the CPU monitor are implemented in two different threads.

Theoretical insight on this tool

On my blog is available a theoretical explanation of this tool.

Dependencies

This script uses Python 3.6 and requires the following additional libraries:

  • matplotlib
  • psutil
  • click

To get started, first install Virtualenv, then create and activate a Python virtualenv in the project root directory:

$ cd CPULoadGenerator/
$ sudo apt install virtualenv
$ virtualenv --python=python3.6 ./venv
$ . venv/bin/activate
(venv) $

Finally, install the dependencies listed in requirements.txt:

(venv) $ pip install -r requirements.txt

Alternatively, install dependencies system-wide using apt:

$ sudo apt install python3-matplotlib python3-psutil python3-click

Examples

  1. Generate 20% of load on core 0 for 20 seconds:

    ./CPULoadGenerator.py -l 0.2 -d 20 -c 0
    
  2. Generate 65% load on cores 0, 1 and 5, until the program is interrupted through Ctrl-C:

    ./CPULoadGenerator.py -l 0.65 -c 0 -c 1 -c 5
    
  3. Generate 55% load on core 0, 12% on core 3, until the program is interrupted through Ctrl-C:

    ./CPULoadGenerator.py -c 0 -c 3 -l 0.55 -l 0.12
    
  4. Generate 12% load on cores 0 and 1, for 20.5 seconds, and then plot the load for each of the cores:

    ./CPULoadGenerator.py -l 0.12 -c 0 -c 1 -d 20.5 --plot
    
  5. Example graph of CPU load:

Example - 50% load on CPU core 0

About

CPU Load Generator allows you to generate a fixed configurable CPU load for a finite time by means of PID regulator.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •