Skip to content

Commit b61d409

Browse files
Rename script to snake_case, update Dockerfile/README, slim .gitignore
- CPULoadGenerator.py -> cpu_load_generator.py (PEP 8 module name) - Dockerfile: python:3.13, LABEL maintainer, MAINTAINER removed - README: cpu_load_generator.py in all examples - .gitignore: project-focused (Python, IDE, generated PNG), drop C#/C++/Java template Made-with: Cursor
1 parent e1f8d52 commit b61d409

4 files changed

Lines changed: 41 additions & 228 deletions

File tree

.gitignore

Lines changed: 28 additions & 216 deletions
Original file line numberDiff line numberDiff line change
@@ -1,219 +1,31 @@
1-
*.jpg
2-
*.png
3-
4-
.idea/**/workspace.xml
5-
.idea/**/tasks.xml
6-
.idea/**/dictionaries
7-
.idea/**/shelf
8-
.idea/**/dataSources/
9-
.idea/**/dataSources.ids
10-
.idea/**/dataSources.local.xml
11-
.idea/**/sqlDataSources.xml
12-
.idea/**/dynamic.xml
13-
.idea/**/uiDesigner.xml
14-
.idea/**/dbnavigator.xml
15-
.idea/**/gradle.xml
16-
.idea/**/libraries
17-
cmake-build-debug/
18-
cmake-build-release/
19-
.idea/**/mongoSettings.xml
20-
*.iws
21-
out/
22-
.idea_modules/
23-
atlassian-ide-plugin.xml
24-
.idea/replstate.xml
25-
com_crashlytics_export_strings.xml
26-
crashlytics.properties
27-
crashlytics-build.properties
28-
fabric.properties
29-
.idea/httpRequests
30-
*.suo
31-
*.user
32-
*.userosscache
33-
*.sln.docstates
34-
*.userprefs
35-
[Dd]ebug/
36-
[Dd]ebugPublic/
37-
[Rr]elease/
38-
[Rr]eleases/
39-
x64/
40-
x86/
41-
bld/
42-
[Bb]in/
43-
[Oo]bj/
44-
[Ll]og/
45-
.vs/
46-
Generated\ Files/
47-
[Tt]est[Rr]esult*/
48-
[Bb]uild[Ll]og.*
49-
*.VisualState.xml
50-
TestResult.xml
51-
[Dd]ebugPS/
52-
[Rr]eleasePS/
53-
dlldata.c
54-
BenchmarkDotNet.Artifacts/
55-
project.lock.json
56-
project.fragment.lock.json
57-
artifacts/
58-
StyleCopReport.xml
59-
*_i.c
60-
*_p.c
61-
*_i.h
62-
*.ilk
63-
*.meta
64-
*.obj
65-
*.iobj
66-
*.pch
67-
*.pdb
68-
*.ipdb
69-
*.pgc
70-
*.pgd
71-
*.rsp
72-
*.sbr
73-
*.tlb
74-
*.tli
75-
*.tlh
76-
*.tmp
77-
*.tmp_proj
78-
*.log
79-
*.vspscc
80-
*.vssscc
81-
.builds
82-
*.pidb
83-
*.svclog
84-
*.scc
85-
_Chutzpah*
86-
ipch/
87-
*.aps
88-
*.ncb
89-
*.opendb
90-
*.opensdf
91-
*.sdf
92-
*.cachefile
93-
*.VC.db
94-
*.VC.VC.opendb
95-
*.psess
96-
*.vsp
97-
*.vspx
98-
*.sap
99-
*.e2e
100-
$tf/
101-
*.gpState
102-
_ReSharper*/
103-
*.[Rr]e[Ss]harper
104-
*.DotSettings.user
105-
.JustCode
106-
_TeamCity*
107-
*.dotCover
108-
.axoCover/*
109-
!.axoCover/settings.json
110-
*.coverage
111-
*.coveragexml
112-
_NCrunch_*
113-
.*crunch*.local.xml
114-
nCrunchTemp_*
115-
*.mm.*
116-
AutoTest.Net/
117-
.sass-cache/
118-
[Ee]xpress/
119-
DocProject/buildhelp/
120-
DocProject/Help/*.HxT
121-
DocProject/Help/*.HxC
122-
DocProject/Help/*.hhc
123-
DocProject/Help/*.hhk
124-
DocProject/Help/*.hhp
125-
DocProject/Help/Html2
126-
DocProject/Help/html
127-
publish/
128-
*.[Pp]ublish.xml
129-
*.azurePubxml
130-
*.pubxml
131-
*.publishproj
132-
PublishScripts/
133-
*.nupkg
134-
**/[Pp]ackages/*
135-
!**/[Pp]ackages/build/
136-
*.nuget.props
137-
*.nuget.targets
138-
csx/
139-
*.build.csdef
140-
ecf/
141-
rcf/
142-
AppPackages/
143-
BundleArtifacts/
144-
Package.StoreAssociation.xml
145-
_pkginfo.txt
146-
*.appx
147-
*.[Cc]ache
148-
!*.[Cc]ache/
149-
ClientBin/
150-
~$*
151-
*~
152-
*.dbmdl
153-
*.dbproj.schemaview
154-
*.jfm
155-
*.pfx
156-
*.publishsettings
157-
orleans.codegen.cs
158-
Generated_Code/
159-
_UpgradeReport_Files/
160-
Backup*/
161-
UpgradeLog*.XML
162-
UpgradeLog*.htm
163-
ServiceFabricBackup/
164-
*.rptproj.bak
165-
*.mdf
166-
*.ldf
167-
*.ndf
168-
*.rdl.data
169-
*.bim.layout
170-
*.bim_*.settings
171-
*.rptproj.rsuser
172-
FakesAssemblies/
173-
*.GhostDoc.xml
174-
.ntvs_analysis.dat
175-
node_modules/
176-
*.plg
177-
*.opt
178-
*.vbw
179-
**/*.HTMLClient/GeneratedArtifacts
180-
**/*.DesktopClient/GeneratedArtifacts
181-
**/*.DesktopClient/ModelManifest.xml
182-
**/*.Server/GeneratedArtifacts
183-
**/*.Server/ModelManifest.xml
184-
_Pvt_Extensions
185-
.paket/paket.exe
186-
paket-files/
187-
.fake/
188-
.idea/
189-
*.sln.iml
190-
.cr/
1+
# Python
1912
__pycache__/
192-
*.pyc
193-
*.tss
194-
*.jmconfig
195-
*.btp.cs
196-
*.btm.cs
197-
*.odx.cs
198-
*.xsd.cs
199-
OpenCover/
200-
ASALocalRun/
201-
*.binlog
202-
*.nvuser
203-
.mfractor/
204-
.vscode/*
205-
!.vscode/settings.json
206-
!.vscode/tasks.json
207-
!.vscode/launch.json
208-
!.vscode/extensions.json
3+
*.py[cod]
4+
*$py.class
5+
*.so
2096
.Python
210-
[Bb]in
211-
[Ii]nclude
212-
[Ll]ib
213-
[Ll]ib64
214-
[Ll]ocal
215-
[Ss]cripts
216-
pyvenv.cfg
217-
.venv
218-
pip-selfcheck.json
2197
venv/
8+
.venv/
9+
.env
10+
*.egg-info/
11+
.eggs/
12+
dist/
13+
build/
14+
15+
# Generated plot outputs (script saves PNG with --plot)
16+
*.png
17+
*.jpg
18+
19+
# IDE
20+
.idea/
21+
.vscode/
22+
*.swp
23+
*~
24+
25+
# OS
26+
.DS_Store
27+
Thumbs.db
28+
29+
# Jekyll / GitHub Pages (optional: if you build locally)
30+
_site/
31+
.jekyll-cache/

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
FROM python:3.6
2-
MAINTAINER GaetanoCarlucci <gaetano.carlucci@gmail.com>
1+
FROM python:3.13
2+
LABEL maintainer="GaetanoCarlucci <gaetano.carlucci@gmail.com>"
33

44
RUN apt-get update -q && apt-get install git && apt-get clean
55
RUN cd / && git clone https://github.com/GaetanoCarlucci/CPULoadGenerator.git /CPULoadGenerator
66
RUN pip install -r /CPULoadGenerator/requirements.txt
77

88
WORKDIR /CPULoadGenerator
9-
ENTRYPOINT ["./CPULoadGenerator.py"]
9+
ENTRYPOINT ["./cpu_load_generator.py"]
1010
CMD ["--help"]

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ pip install -r requirements.txt
3434
Run the script (e.g. 20% load on core 0 for 10 seconds):
3535

3636
```bash
37-
python CPULoadGenerator.py -l 0.2 -d 10 -c 0
37+
python cpu_load_generator.py -l 0.2 -d 10 -c 0
3838
```
3939

40-
Or make the script executable and run: `chmod +x CPULoadGenerator.py` then `./CPULoadGenerator.py -l 0.2 -d 10 -c 0`.
40+
Or make the script executable and run: `chmod +x cpu_load_generator.py` then `./cpu_load_generator.py -l 0.2 -d 10 -c 0`.
4141

4242
**System-wide install (Debian/Ubuntu):** `sudo apt install python3-matplotlib python3-psutil python3-click`
4343

@@ -48,25 +48,25 @@ Or make the script executable and run: `chmod +x CPULoadGenerator.py` then `./CP
4848
1. **20% load on core 0 for 20 seconds:**
4949

5050
```bash
51-
./CPULoadGenerator.py -l 0.2 -d 20 -c 0
51+
./cpu_load_generator.py -l 0.2 -d 20 -c 0
5252
```
5353

5454
2. **65% load on cores 0, 1 and 5, until interrupted (Ctrl-C):**
5555

5656
```bash
57-
./CPULoadGenerator.py -l 0.65 -c 0 -c 1 -c 5
57+
./cpu_load_generator.py -l 0.65 -c 0 -c 1 -c 5
5858
```
5959

6060
3. **55% load on core 0, 12% on core 3, until interrupted:**
6161

6262
```bash
63-
./CPULoadGenerator.py -c 0 -c 3 -l 0.55 -l 0.12
63+
./cpu_load_generator.py -c 0 -c 3 -l 0.55 -l 0.12
6464
```
6565

6666
4. **12% load on cores 0 and 1 for 20.5 seconds, then plot the load:**
6767

6868
```bash
69-
./CPULoadGenerator.py -l 0.12 -c 0 -c 1 -d 20.5 --plot
69+
./cpu_load_generator.py -l 0.12 -c 0 -c 1 -d 20.5 --plot
7070
```
7171

7272
5. **Example graph of CPU load (50% target on core 0):**
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env python
2+
"""Generate a fixed CPU load on one or more cores using a PI controller."""
23

34
# Authors: Gaetano Carlucci
45
# Giuseppe Cofano
@@ -37,7 +38,7 @@ def _set_cpu_affinity(core_id):
3738

3839

3940
class ShutdownException(Exception):
40-
pass
41+
"""Raised on SIGINT/SIGTERM to trigger graceful shutdown of load generation."""
4142

4243

4344
def __sig_handler(*args):
@@ -47,6 +48,7 @@ def __sig_handler(*args):
4748
def load_core(target_core, target_load,
4849
duration_seconds=-1, plot=False,
4950
sampling_interval=0.1):
51+
"""Run the PI-controlled load generator on a single CPU core."""
5052
if duration_seconds >= 0:
5153
print(f'Loading core {target_core} ({target_load * 100.0:0>5.2f}%) for '
5254
f'{duration_seconds} seconds.')
@@ -55,8 +57,7 @@ def load_core(target_core, target_load,
5557
f'until interrupted.')
5658

5759
if sampling_interval <= 0:
58-
raise Exception('Negative sampling interval!')
59-
60+
raise ValueError('Negative sampling interval!')
6061
# Lock this process to the target core (no-op on macOS; load still applied)
6162
_set_cpu_affinity(target_core)
6263

0 commit comments

Comments
 (0)