How to Stress Test Your CPU in Linux
A key matrix for determining the vitality of a Linux distro, or the hardware that it runs on, is system performance. Depending on your purpose, you can choose from a variety of dedicated tools to monitor the different components such as CPU frequency, temperature and memory usage. But if you favor the CLI, like us, you’ll rather enjoy working with S-TUI.
With S-TUI, which is an acronym for Stress-Terminal UI, you can simultaneously monitor CPU temperature, frequency, power and usage. The utility presents all the information graphically and can even be used to export the data into CSV files. Better still, you can configure S-TUI to automatically launch scripts when the values of any of the components being monitored breaches the defined threshold values. When coupled with stress, another command-line utility, S-TUI can also be used to stress-test your system.
Although S-TUI isn’t available in the software repositories of most popular desktop distributions, installing the tool is fairly straightforward, and the project’s GitHub page describes various installation techniques. For our install we shall use Ubuntu 21.04.
1. In the terminal, Update the available software repositories and install the Python 3 packaging tool.
$ sudo apt update $ sudo apt install python3-pip
2. Install S-TUI using pip3.
$ sudo pip install s-tui
3. Run S-TUI.
Unlike many other command-line utilities, S-TUI requires no configuration and you can begin using it immediately after installation.
At the top of the sidebar on the left are the details about your CPU. Our Lenovo test machine was correctly identified as running an Intel Core i3-5005U CPU @ 2.00GHz processor. This is because S-TUI uses various other native tools and utilities to gather the relevant information. For instance, the same information and far more details can be ascertained from running the cat / proc / cpuinfo command.
When you first launch S-TUI, it displays all four parameters – Frequency, Utilization, Temperature and Power – and refreshes the data for each every two seconds.
To change the refresh rate from two seconds to 0.1, change the value of Refresh[s]: 2.0 on the sidebar to 0.1, note that this will put extra strain on your Pi.
Use the up and down arrow keys to navigate the sidebar, but S-TUI also supports the use of H and J to scroll, much like you would in Vim. S-TUI will also work with mouse input.
Using S-TUI to Stress Test Your Machine
By default, S-TUI is configured to only monitor your system. To push our machine to its limits we installed “stress” a stress testing terminal tool. Stress works with all types of CPUs, we use it to stress test Raspberry Pis as part of the stressberry Python benchmarking tool.
1. To install stress, open a terminal and enter the following.
$ sudo apt install stress
2. Open S-TUI.
3. Using the arrow keys, navigate to Stress and press the spacebar. Alternatively you can also use the mouse to select. You will see the CPU graphs rapidly update, showing the current processor temperature, frequency and utilization. The stress test will run indefinitely.
4. Turn off the stress test by navigating to Monitor and pressing the spacebar, or by clicking with your mouse.
5. To set a time limited stress test, navigate / click on Stress Options and change the Time out to your desired time (in seconds). Set the Sqrt () worker count to match the number of cores for your CPU. Click Save when done.
6. Click on / navigate to Stress and press spacebar to run the timed test. Here we set the duration to be 30 seconds, and left the worker count at 4.
Saving Your Test Results
The collected data is lost as soon as you exit S-TUI, because the tool doesn’t save it by default.
To automatically save the collected information to a timestamped CSV file when you exit S-TUI, invoke the command as so.
$ s-tui -c
To specify your own file name, invoke the command with a “–csv-file” provide a filename.
$ s-tui --csv-file
If you prefer your data in a JSON format, then we can output the data in JSON format, but only the current status, not a running log.
$ s-tui -j