cpu-loader 0.0.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cpu_loader-0.0.2/LICENSE +21 -0
- cpu_loader-0.0.2/MANIFEST.in +5 -0
- cpu_loader-0.0.2/PKG-INFO +269 -0
- cpu_loader-0.0.2/README.md +232 -0
- cpu_loader-0.0.2/pyproject.toml +53 -0
- cpu_loader-0.0.2/setup.cfg +4 -0
- cpu_loader-0.0.2/setup.py +20 -0
- cpu_loader-0.0.2/src/cpu_loader.egg-info/PKG-INFO +269 -0
- cpu_loader-0.0.2/src/cpu_loader.egg-info/SOURCES.txt +15 -0
- cpu_loader-0.0.2/src/cpu_loader.egg-info/dependency_links.txt +1 -0
- cpu_loader-0.0.2/src/cpu_loader.egg-info/entry_points.txt +2 -0
- cpu_loader-0.0.2/src/cpu_loader.egg-info/requires.txt +6 -0
- cpu_loader-0.0.2/src/cpu_loader.egg-info/top_level.txt +4 -0
- cpu_loader-0.0.2/src/cpu_loader.py +106 -0
- cpu_loader-0.0.2/src/cpu_loader_core.c +265 -0
- cpu_loader-0.0.2/src/example.py +86 -0
- cpu_loader-0.0.2/src/main.py +658 -0
cpu_loader-0.0.2/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 the78mole
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cpu-loader
|
|
3
|
+
Version: 0.0.2
|
|
4
|
+
Summary: A tool to generate CPU load on a system with runtime configuration through a WebUI and REST API
|
|
5
|
+
Author-email: the78mole <the78mole@users.noreply.github.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/the78mole/cpu-loader
|
|
8
|
+
Project-URL: Repository, https://github.com/the78mole/cpu-loader
|
|
9
|
+
Project-URL: Issues, https://github.com/the78mole/cpu-loader/issues
|
|
10
|
+
Project-URL: Changelog, https://github.com/the78mole/cpu-loader/releases
|
|
11
|
+
Keywords: cpu,load,testing,stress-test,performance,benchmark
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Intended Audience :: System Administrators
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
17
|
+
Classifier: Operating System :: MacOS
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
24
|
+
Classifier: Programming Language :: C
|
|
25
|
+
Classifier: Topic :: System :: Benchmark
|
|
26
|
+
Classifier: Topic :: System :: Monitoring
|
|
27
|
+
Requires-Python: >=3.8
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
License-File: LICENSE
|
|
30
|
+
Requires-Dist: fastapi==0.115.0
|
|
31
|
+
Requires-Dist: uvicorn[standard]==0.32.0
|
|
32
|
+
Requires-Dist: pydantic==2.10.0
|
|
33
|
+
Requires-Dist: requests==2.32.3
|
|
34
|
+
Requires-Dist: psutil>=5.9.0
|
|
35
|
+
Requires-Dist: websockets>=12.0
|
|
36
|
+
Dynamic: license-file
|
|
37
|
+
|
|
38
|
+
# CPU Loader
|
|
39
|
+
|
|
40
|
+
[](https://github.com/the78mole/cpu-loader/actions/workflows/ci.yml)
|
|
41
|
+
[](https://github.com/the78mole/cpu-loader/actions/workflows/build-wheels.yml)
|
|
42
|
+
[](https://pypi.org/project/cpu-loader/)
|
|
43
|
+
[](https://github.com/the78mole/cpu-loader/blob/main/LICENSE)
|
|
44
|
+
|
|
45
|
+
A tool to generate CPU load on a system with runtime configuration through a WebUI and REST API.
|
|
46
|
+
|
|
47
|
+
## Features
|
|
48
|
+
|
|
49
|
+
- 🔥 **Controllable CPU Load**: Generate precise CPU load per thread
|
|
50
|
+
- 🎛️ **Per-Thread Control**: Individual sliders for each CPU thread
|
|
51
|
+
- 🚀 **REST API**: Full programmatic control via HTTP endpoints
|
|
52
|
+
- 🌐 **Modern WebUI**: Beautiful, responsive interface for real-time control
|
|
53
|
+
- ⚡ **Instant Response**: Changes take effect immediately
|
|
54
|
+
- 📊 **Live Monitoring**: View active threads and average load in real-time
|
|
55
|
+
|
|
56
|
+
## Screenshots
|
|
57
|
+
|
|
58
|
+
### WebUI Interface
|
|
59
|
+

|
|
60
|
+
*Individual thread control with sliders and preset buttons*
|
|
61
|
+
|
|
62
|
+

|
|
63
|
+
*Setting all threads to 50% load*
|
|
64
|
+
|
|
65
|
+

|
|
66
|
+
*Maximum load across all threads*
|
|
67
|
+
|
|
68
|
+
## Installation
|
|
69
|
+
|
|
70
|
+
### From Pre-built Wheels (Recommended)
|
|
71
|
+
|
|
72
|
+
Pre-compiled wheels are available for Linux (x86_64, ARM64) and macOS (x86_64, ARM64):
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
pip install cpu-loader
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### From Source
|
|
79
|
+
|
|
80
|
+
1. Clone the repository:
|
|
81
|
+
```bash
|
|
82
|
+
git clone https://github.com/the78mole/cpu-loader.git
|
|
83
|
+
cd cpu-loader
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
2. Install dependencies and build C extension:
|
|
87
|
+
```bash
|
|
88
|
+
uv pip install -e .
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
This will compile the high-performance C extension for efficient CPU load generation.
|
|
92
|
+
|
|
93
|
+
3. (Optional) Set up pre-commit hooks for development:
|
|
94
|
+
```bash
|
|
95
|
+
pre-commit install
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
4. (Optional) Set up commit message template for semantic versioning:
|
|
99
|
+
```bash
|
|
100
|
+
git config commit.template .gitmessage
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
See [COMMIT_MESSAGE_FORMAT.md](COMMIT_MESSAGE_FORMAT.md) for commit message guidelines.
|
|
104
|
+
|
|
105
|
+
## Usage
|
|
106
|
+
|
|
107
|
+
### Starting the Server
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
uv run src/main.py
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
The server will start on `http://localhost:8000`
|
|
114
|
+
|
|
115
|
+
### WebUI
|
|
116
|
+
|
|
117
|
+
Open your browser and navigate to `http://localhost:8000`
|
|
118
|
+
|
|
119
|
+
**Features:**
|
|
120
|
+
- **Individual Thread Control**: Use sliders to set load for each thread (0-100%)
|
|
121
|
+
- **Preset Buttons**: Quick-set all threads to 0%, 10%, 25%, 50%, 80%, 90%, or 100%
|
|
122
|
+
- **Live Stats**: View active thread count and average load
|
|
123
|
+
- **Real-time Updates**: Changes are applied instantly with visual feedback
|
|
124
|
+
|
|
125
|
+
### REST API
|
|
126
|
+
|
|
127
|
+
#### Get Thread Status
|
|
128
|
+
```bash
|
|
129
|
+
curl http://localhost:8000/api/threads
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Response:
|
|
133
|
+
```json
|
|
134
|
+
{
|
|
135
|
+
"num_threads": 4,
|
|
136
|
+
"loads": {
|
|
137
|
+
"0": 0.0,
|
|
138
|
+
"1": 0.0,
|
|
139
|
+
"2": 0.0,
|
|
140
|
+
"3": 0.0
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
#### Set Load for Specific Thread
|
|
146
|
+
```bash
|
|
147
|
+
curl -X PUT http://localhost:8000/api/threads/0/load \
|
|
148
|
+
-H "Content-Type: application/json" \
|
|
149
|
+
-d '{"load_percent": 50.0}'
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
#### Set Load for All Threads
|
|
153
|
+
```bash
|
|
154
|
+
curl -X POST http://localhost:8000/api/threads/load/all \
|
|
155
|
+
-H "Content-Type: application/json" \
|
|
156
|
+
-d '{"load_percent": 75.0}'
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
#### Change Number of Threads
|
|
160
|
+
```bash
|
|
161
|
+
curl -X POST http://localhost:8000/api/threads \
|
|
162
|
+
-H "Content-Type: application/json" \
|
|
163
|
+
-d '{"num_threads": 8}'
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## API Documentation
|
|
167
|
+
|
|
168
|
+
Once the server is running, visit `http://localhost:8000/docs` for interactive API documentation powered by Swagger UI.
|
|
169
|
+
|
|
170
|
+
## Example Script
|
|
171
|
+
|
|
172
|
+
An example script (`src/example.py`) is provided to demonstrate programmatic control:
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
# Start the server first
|
|
176
|
+
uv run src/main.py
|
|
177
|
+
|
|
178
|
+
# In another terminal, run the example
|
|
179
|
+
uv run src/example.py
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
The example demonstrates:
|
|
183
|
+
- Getting current status
|
|
184
|
+
- Setting all threads to a specific load
|
|
185
|
+
- Gradually increasing load
|
|
186
|
+
- Individual thread control
|
|
187
|
+
- Resetting to idle
|
|
188
|
+
|
|
189
|
+
## Architecture
|
|
190
|
+
|
|
191
|
+
- **src/cpu_loader_core.c**: High-performance C implementation using pthreads for CPU load generation
|
|
192
|
+
- **src/cpu_loader.py**: Python wrapper providing a clean API to the C extension
|
|
193
|
+
- **src/main.py**: FastAPI application with REST API and embedded WebUI
|
|
194
|
+
- **Threading Model**: Native pthreads for maximum efficiency and precise timing
|
|
195
|
+
- **Load Algorithm**: High-resolution busy-wait loops with nanosecond precision
|
|
196
|
+
|
|
197
|
+
## Requirements
|
|
198
|
+
|
|
199
|
+
- Python 3.8+
|
|
200
|
+
- FastAPI 0.115.0+
|
|
201
|
+
- Uvicorn 0.32.0+
|
|
202
|
+
- Pydantic 2.10.0+
|
|
203
|
+
- C compiler (gcc or clang) for building the extension
|
|
204
|
+
|
|
205
|
+
## Use Cases
|
|
206
|
+
|
|
207
|
+
- **Performance Testing**: Test application behavior under various CPU loads
|
|
208
|
+
- **Stress Testing**: Validate system stability under high CPU utilization
|
|
209
|
+
- **Thermal Testing**: Check cooling system effectiveness
|
|
210
|
+
- **Power Consumption Analysis**: Measure power usage at different load levels
|
|
211
|
+
- **Benchmarking**: Create reproducible load scenarios
|
|
212
|
+
|
|
213
|
+
## Development
|
|
214
|
+
|
|
215
|
+
### Pre-commit Hooks
|
|
216
|
+
|
|
217
|
+
This project uses pre-commit hooks to ensure code quality. The hooks include:
|
|
218
|
+
|
|
219
|
+
- **Code Formatting**: Black and isort for consistent Python formatting
|
|
220
|
+
- **Linting**: Flake8 for code quality checks
|
|
221
|
+
- **Type Checking**: Mypy for static type analysis
|
|
222
|
+
- **General Checks**: Trailing whitespace, end-of-file fixes, YAML/JSON/TOML validation
|
|
223
|
+
|
|
224
|
+
To run pre-commit manually on all files:
|
|
225
|
+
```bash
|
|
226
|
+
pre-commit run --all-files
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
The hooks will run automatically on `git commit` after installation.
|
|
230
|
+
|
|
231
|
+
### Building and Publishing Releases
|
|
232
|
+
|
|
233
|
+
The project uses **automatic semantic versioning** with GitHub Actions:
|
|
234
|
+
|
|
235
|
+
#### Versioning Rules
|
|
236
|
+
|
|
237
|
+
Versions are automatically determined based on commit messages:
|
|
238
|
+
|
|
239
|
+
- **Patch bump** (0.0.X): Every commit to main
|
|
240
|
+
- **Minor bump** (0.X.0): Commits prefixed with `feat:`
|
|
241
|
+
```bash
|
|
242
|
+
git commit -m "feat: add new CPU monitoring feature"
|
|
243
|
+
```
|
|
244
|
+
- **Major bump** (X.0.0): Commits with `major:`, `breaking:`, or `BREAKING CHANGE:`
|
|
245
|
+
```bash
|
|
246
|
+
git commit -m "major: redesign API interface"
|
|
247
|
+
git commit -m "breaking: remove deprecated endpoints"
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
#### Release Process
|
|
251
|
+
|
|
252
|
+
1. **Commit and push to main**:
|
|
253
|
+
```bash
|
|
254
|
+
git add .
|
|
255
|
+
git commit -m "feat: add WebSocket support"
|
|
256
|
+
git push origin main
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
2. **Automated workflow**:
|
|
260
|
+
- Version is automatically calculated using semantic versioning
|
|
261
|
+
- Wheels are built for Linux (x86_64, ARM64) and macOS (x86_64, ARM64)
|
|
262
|
+
- Python versions: 3.8, 3.9, 3.10, 3.11, 3.12
|
|
263
|
+
- Source distribution (sdist) is created
|
|
264
|
+
- All artifacts are published to PyPI
|
|
265
|
+
- A GitHub Release is created with version tag and artifacts
|
|
266
|
+
|
|
267
|
+
## License
|
|
268
|
+
|
|
269
|
+
MIT License - see [LICENSE](LICENSE) file for details.
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
# CPU Loader
|
|
2
|
+
|
|
3
|
+
[](https://github.com/the78mole/cpu-loader/actions/workflows/ci.yml)
|
|
4
|
+
[](https://github.com/the78mole/cpu-loader/actions/workflows/build-wheels.yml)
|
|
5
|
+
[](https://pypi.org/project/cpu-loader/)
|
|
6
|
+
[](https://github.com/the78mole/cpu-loader/blob/main/LICENSE)
|
|
7
|
+
|
|
8
|
+
A tool to generate CPU load on a system with runtime configuration through a WebUI and REST API.
|
|
9
|
+
|
|
10
|
+
## Features
|
|
11
|
+
|
|
12
|
+
- 🔥 **Controllable CPU Load**: Generate precise CPU load per thread
|
|
13
|
+
- 🎛️ **Per-Thread Control**: Individual sliders for each CPU thread
|
|
14
|
+
- 🚀 **REST API**: Full programmatic control via HTTP endpoints
|
|
15
|
+
- 🌐 **Modern WebUI**: Beautiful, responsive interface for real-time control
|
|
16
|
+
- ⚡ **Instant Response**: Changes take effect immediately
|
|
17
|
+
- 📊 **Live Monitoring**: View active threads and average load in real-time
|
|
18
|
+
|
|
19
|
+
## Screenshots
|
|
20
|
+
|
|
21
|
+
### WebUI Interface
|
|
22
|
+

|
|
23
|
+
*Individual thread control with sliders and preset buttons*
|
|
24
|
+
|
|
25
|
+

|
|
26
|
+
*Setting all threads to 50% load*
|
|
27
|
+
|
|
28
|
+

|
|
29
|
+
*Maximum load across all threads*
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
|
|
33
|
+
### From Pre-built Wheels (Recommended)
|
|
34
|
+
|
|
35
|
+
Pre-compiled wheels are available for Linux (x86_64, ARM64) and macOS (x86_64, ARM64):
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pip install cpu-loader
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### From Source
|
|
42
|
+
|
|
43
|
+
1. Clone the repository:
|
|
44
|
+
```bash
|
|
45
|
+
git clone https://github.com/the78mole/cpu-loader.git
|
|
46
|
+
cd cpu-loader
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
2. Install dependencies and build C extension:
|
|
50
|
+
```bash
|
|
51
|
+
uv pip install -e .
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
This will compile the high-performance C extension for efficient CPU load generation.
|
|
55
|
+
|
|
56
|
+
3. (Optional) Set up pre-commit hooks for development:
|
|
57
|
+
```bash
|
|
58
|
+
pre-commit install
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
4. (Optional) Set up commit message template for semantic versioning:
|
|
62
|
+
```bash
|
|
63
|
+
git config commit.template .gitmessage
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
See [COMMIT_MESSAGE_FORMAT.md](COMMIT_MESSAGE_FORMAT.md) for commit message guidelines.
|
|
67
|
+
|
|
68
|
+
## Usage
|
|
69
|
+
|
|
70
|
+
### Starting the Server
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
uv run src/main.py
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
The server will start on `http://localhost:8000`
|
|
77
|
+
|
|
78
|
+
### WebUI
|
|
79
|
+
|
|
80
|
+
Open your browser and navigate to `http://localhost:8000`
|
|
81
|
+
|
|
82
|
+
**Features:**
|
|
83
|
+
- **Individual Thread Control**: Use sliders to set load for each thread (0-100%)
|
|
84
|
+
- **Preset Buttons**: Quick-set all threads to 0%, 10%, 25%, 50%, 80%, 90%, or 100%
|
|
85
|
+
- **Live Stats**: View active thread count and average load
|
|
86
|
+
- **Real-time Updates**: Changes are applied instantly with visual feedback
|
|
87
|
+
|
|
88
|
+
### REST API
|
|
89
|
+
|
|
90
|
+
#### Get Thread Status
|
|
91
|
+
```bash
|
|
92
|
+
curl http://localhost:8000/api/threads
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Response:
|
|
96
|
+
```json
|
|
97
|
+
{
|
|
98
|
+
"num_threads": 4,
|
|
99
|
+
"loads": {
|
|
100
|
+
"0": 0.0,
|
|
101
|
+
"1": 0.0,
|
|
102
|
+
"2": 0.0,
|
|
103
|
+
"3": 0.0
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
#### Set Load for Specific Thread
|
|
109
|
+
```bash
|
|
110
|
+
curl -X PUT http://localhost:8000/api/threads/0/load \
|
|
111
|
+
-H "Content-Type: application/json" \
|
|
112
|
+
-d '{"load_percent": 50.0}'
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
#### Set Load for All Threads
|
|
116
|
+
```bash
|
|
117
|
+
curl -X POST http://localhost:8000/api/threads/load/all \
|
|
118
|
+
-H "Content-Type: application/json" \
|
|
119
|
+
-d '{"load_percent": 75.0}'
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
#### Change Number of Threads
|
|
123
|
+
```bash
|
|
124
|
+
curl -X POST http://localhost:8000/api/threads \
|
|
125
|
+
-H "Content-Type: application/json" \
|
|
126
|
+
-d '{"num_threads": 8}'
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## API Documentation
|
|
130
|
+
|
|
131
|
+
Once the server is running, visit `http://localhost:8000/docs` for interactive API documentation powered by Swagger UI.
|
|
132
|
+
|
|
133
|
+
## Example Script
|
|
134
|
+
|
|
135
|
+
An example script (`src/example.py`) is provided to demonstrate programmatic control:
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
# Start the server first
|
|
139
|
+
uv run src/main.py
|
|
140
|
+
|
|
141
|
+
# In another terminal, run the example
|
|
142
|
+
uv run src/example.py
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
The example demonstrates:
|
|
146
|
+
- Getting current status
|
|
147
|
+
- Setting all threads to a specific load
|
|
148
|
+
- Gradually increasing load
|
|
149
|
+
- Individual thread control
|
|
150
|
+
- Resetting to idle
|
|
151
|
+
|
|
152
|
+
## Architecture
|
|
153
|
+
|
|
154
|
+
- **src/cpu_loader_core.c**: High-performance C implementation using pthreads for CPU load generation
|
|
155
|
+
- **src/cpu_loader.py**: Python wrapper providing a clean API to the C extension
|
|
156
|
+
- **src/main.py**: FastAPI application with REST API and embedded WebUI
|
|
157
|
+
- **Threading Model**: Native pthreads for maximum efficiency and precise timing
|
|
158
|
+
- **Load Algorithm**: High-resolution busy-wait loops with nanosecond precision
|
|
159
|
+
|
|
160
|
+
## Requirements
|
|
161
|
+
|
|
162
|
+
- Python 3.8+
|
|
163
|
+
- FastAPI 0.115.0+
|
|
164
|
+
- Uvicorn 0.32.0+
|
|
165
|
+
- Pydantic 2.10.0+
|
|
166
|
+
- C compiler (gcc or clang) for building the extension
|
|
167
|
+
|
|
168
|
+
## Use Cases
|
|
169
|
+
|
|
170
|
+
- **Performance Testing**: Test application behavior under various CPU loads
|
|
171
|
+
- **Stress Testing**: Validate system stability under high CPU utilization
|
|
172
|
+
- **Thermal Testing**: Check cooling system effectiveness
|
|
173
|
+
- **Power Consumption Analysis**: Measure power usage at different load levels
|
|
174
|
+
- **Benchmarking**: Create reproducible load scenarios
|
|
175
|
+
|
|
176
|
+
## Development
|
|
177
|
+
|
|
178
|
+
### Pre-commit Hooks
|
|
179
|
+
|
|
180
|
+
This project uses pre-commit hooks to ensure code quality. The hooks include:
|
|
181
|
+
|
|
182
|
+
- **Code Formatting**: Black and isort for consistent Python formatting
|
|
183
|
+
- **Linting**: Flake8 for code quality checks
|
|
184
|
+
- **Type Checking**: Mypy for static type analysis
|
|
185
|
+
- **General Checks**: Trailing whitespace, end-of-file fixes, YAML/JSON/TOML validation
|
|
186
|
+
|
|
187
|
+
To run pre-commit manually on all files:
|
|
188
|
+
```bash
|
|
189
|
+
pre-commit run --all-files
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
The hooks will run automatically on `git commit` after installation.
|
|
193
|
+
|
|
194
|
+
### Building and Publishing Releases
|
|
195
|
+
|
|
196
|
+
The project uses **automatic semantic versioning** with GitHub Actions:
|
|
197
|
+
|
|
198
|
+
#### Versioning Rules
|
|
199
|
+
|
|
200
|
+
Versions are automatically determined based on commit messages:
|
|
201
|
+
|
|
202
|
+
- **Patch bump** (0.0.X): Every commit to main
|
|
203
|
+
- **Minor bump** (0.X.0): Commits prefixed with `feat:`
|
|
204
|
+
```bash
|
|
205
|
+
git commit -m "feat: add new CPU monitoring feature"
|
|
206
|
+
```
|
|
207
|
+
- **Major bump** (X.0.0): Commits with `major:`, `breaking:`, or `BREAKING CHANGE:`
|
|
208
|
+
```bash
|
|
209
|
+
git commit -m "major: redesign API interface"
|
|
210
|
+
git commit -m "breaking: remove deprecated endpoints"
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
#### Release Process
|
|
214
|
+
|
|
215
|
+
1. **Commit and push to main**:
|
|
216
|
+
```bash
|
|
217
|
+
git add .
|
|
218
|
+
git commit -m "feat: add WebSocket support"
|
|
219
|
+
git push origin main
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
2. **Automated workflow**:
|
|
223
|
+
- Version is automatically calculated using semantic versioning
|
|
224
|
+
- Wheels are built for Linux (x86_64, ARM64) and macOS (x86_64, ARM64)
|
|
225
|
+
- Python versions: 3.8, 3.9, 3.10, 3.11, 3.12
|
|
226
|
+
- Source distribution (sdist) is created
|
|
227
|
+
- All artifacts are published to PyPI
|
|
228
|
+
- A GitHub Release is created with version tag and artifacts
|
|
229
|
+
|
|
230
|
+
## License
|
|
231
|
+
|
|
232
|
+
MIT License - see [LICENSE](LICENSE) file for details.
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "cpu-loader"
|
|
3
|
+
version = "0.0.2"
|
|
4
|
+
description = "A tool to generate CPU load on a system with runtime configuration through a WebUI and REST API"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.8"
|
|
7
|
+
license = {text = "MIT"}
|
|
8
|
+
authors = [
|
|
9
|
+
{name = "the78mole", email = "the78mole@users.noreply.github.com"}
|
|
10
|
+
]
|
|
11
|
+
keywords = ["cpu", "load", "testing", "stress-test", "performance", "benchmark"]
|
|
12
|
+
classifiers = [
|
|
13
|
+
"Development Status :: 4 - Beta",
|
|
14
|
+
"Intended Audience :: Developers",
|
|
15
|
+
"Intended Audience :: System Administrators",
|
|
16
|
+
"License :: OSI Approved :: MIT License",
|
|
17
|
+
"Operating System :: POSIX :: Linux",
|
|
18
|
+
"Operating System :: MacOS",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3.8",
|
|
21
|
+
"Programming Language :: Python :: 3.9",
|
|
22
|
+
"Programming Language :: Python :: 3.10",
|
|
23
|
+
"Programming Language :: Python :: 3.11",
|
|
24
|
+
"Programming Language :: Python :: 3.12",
|
|
25
|
+
"Programming Language :: C",
|
|
26
|
+
"Topic :: System :: Benchmark",
|
|
27
|
+
"Topic :: System :: Monitoring",
|
|
28
|
+
]
|
|
29
|
+
dependencies = [
|
|
30
|
+
"fastapi==0.115.0",
|
|
31
|
+
"uvicorn[standard]==0.32.0",
|
|
32
|
+
"pydantic==2.10.0",
|
|
33
|
+
"requests==2.32.3",
|
|
34
|
+
"psutil>=5.9.0",
|
|
35
|
+
"websockets>=12.0",
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
[project.scripts]
|
|
39
|
+
cpu-loader = "main:run"
|
|
40
|
+
|
|
41
|
+
[project.urls]
|
|
42
|
+
Homepage = "https://github.com/the78mole/cpu-loader"
|
|
43
|
+
Repository = "https://github.com/the78mole/cpu-loader"
|
|
44
|
+
Issues = "https://github.com/the78mole/cpu-loader/issues"
|
|
45
|
+
Changelog = "https://github.com/the78mole/cpu-loader/releases"
|
|
46
|
+
|
|
47
|
+
[build-system]
|
|
48
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
49
|
+
build-backend = "setuptools.build_meta"
|
|
50
|
+
|
|
51
|
+
[tool.setuptools]
|
|
52
|
+
package-dir = {"" = "src"}
|
|
53
|
+
py-modules = ["cpu_loader", "main", "example"]
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
from setuptools import setup, Extension
|
|
2
|
+
import platform
|
|
3
|
+
|
|
4
|
+
extra_compile_args = []
|
|
5
|
+
extra_link_args = []
|
|
6
|
+
|
|
7
|
+
if platform.system() != 'Windows':
|
|
8
|
+
extra_compile_args = ['-pthread', '-O3']
|
|
9
|
+
extra_link_args = ['-pthread']
|
|
10
|
+
|
|
11
|
+
module = Extension(
|
|
12
|
+
'cpu_loader_core',
|
|
13
|
+
sources=['src/cpu_loader_core.c'],
|
|
14
|
+
extra_compile_args=extra_compile_args,
|
|
15
|
+
extra_link_args=extra_link_args,
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
setup(
|
|
19
|
+
ext_modules=[module],
|
|
20
|
+
)
|