Skip to content

Commit ffd5f26

Browse files
committed
docs(getting-started): Fix archive compatibility with version<3.10
pylint and flake8 OK + remove formula verbose
1 parent e7fadff commit ffd5f26

File tree

2 files changed

+66
-47
lines changed

2 files changed

+66
-47
lines changed

docs/script/getting_started/formula/smartwatts-mongodb-csv.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"verbose": true,
2+
"verbose": false,
33
"stream": true,
44
"input": {
55
"puller_mongodb": {

docs/script/getting_started/start.py

Lines changed: 65 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,89 @@
1+
2+
3+
import sys
14
from subprocess import call
25
import subprocess
36
import json
4-
import sys
5-
from time import sleep
67

7-
# List of available processor architectures
8-
# Template: "n - Arch name"
9-
# If an arch is added, the case statement in the start_demo function should be updated accordingly with the proper core events
10-
# https://powerapi.org/reference/sensors/hwpc-sensor/#system-and-container-groups-parameters
11-
list_arch = ["0 - Intel Sandy Bridge, Comet Lake", "1 - Intel Skylake, Whiskey Lake, Coffee Lake", "2 - AMD Zen 2",
8+
# List of available processor architectures Template: "n - Arch name"
9+
# If an arch is added, the case statement in the
10+
# start_demo function should be updated accordingly with the proper core events
11+
# https://powerapi.org/reference/sensors/hwpc-sensor/
12+
list_arch = ["0 - Intel Sandy Bridge, Comet Lake",
13+
"1 - Intel Skylake, Whiskey Lake, Coffee Lake",
14+
"2 - AMD Zen 2",
1215
"3 - AMD Zen 3"]
1316

1417

1518
def start_demo():
16-
print("Enter the number associated with your processor architecture, please note that the sensor isn't available "
17-
"for Intel Tiger Lake and newer: \n" + list_arch[0] + "\n" + list_arch[1] + "\n" + list_arch[2] + "\n" +
18-
list_arch[3] + "\n")
19+
"""
20+
Start the demo by selecting the processor architecture
21+
this will update the sensor configuration file
22+
"""
23+
print("Enter the number associated with your processor architecture, "
24+
"please note that the sensor isn't available "
25+
"for Intel Tiger Lake and newer: \n" + list_arch[0] +
26+
"\n" + list_arch[1] +
27+
"\n" + list_arch[2] +
28+
"\n" + list_arch[3] +
29+
"\n")
30+
1931
choice = True
2032
while choice:
2133
try:
2234
val = input()
2335
val = int(val)
2436
if val < 0 or val >= len(list_arch):
25-
print("Invalid input, please enter a valid number or exit to quit")
37+
print("Invalid input, please enter a valid number or exit")
2638
else:
2739
choice = False
2840
except ValueError:
2941
if val == "exit":
3042
print("Exiting...")
31-
exit(0)
43+
sys.exit()
3244
else:
33-
print("Invalid input, please enter a valid number or exit to quit")
45+
print("Invalid input, please enter a valid number or exit")
3446

3547
print("You have selected: " + list_arch[val] + "\n")
3648

37-
# Update core events in the sensor configuration file based on the selected processor architecture
38-
with open('sensor/hwpc-mongodb.json') as f:
49+
# Update core events in the sensor configuration
50+
# file based on the selected processor architecture
51+
with open('sensor/hwpc-mongodb.json', encoding='UTF-8') as f:
3952
data = json.load(f)
4053

41-
match val:
42-
case 0:
43-
data['container']['core']['events'] = [
44-
"CPU_CLK_UNHALTED:REF_P",
45-
"CPU_CLK_UNHALTED:THREAD_P",
46-
"LLC_MISSES",
47-
"INSTRUCTIONS_RETIRED"
48-
]
49-
case 1:
50-
data['container']['core']['events'] = [
51-
"CPU_CLK_THREAD_UNHALTED:REF_P",
52-
"CPU_CLK_THREAD_UNHALTED:THREAD_P",
53-
"LLC_MISSES",
54-
"INSTRUCTIONS_RETIRED"
55-
]
56-
case 2:
57-
data['container']['core']['events'] = [
58-
"CYCLES_NOT_IN_HALT",
59-
"RETIRED_INSTRUCTIONS",
60-
"RETIRED_UOPS"
61-
]
62-
case 3:
63-
data['container']['core']['events'] = [
64-
"CYCLES_NOT_IN_HALT",
65-
"RETIRED_INSTRUCTIONS",
66-
"RETIRED_OPS"
67-
]
54+
if val == 0:
55+
data['container']['core']['events'] = [
56+
"CPU_CLK_UNHALTED:REF_P",
57+
"CPU_CLK_UNHALTED:THREAD_P",
58+
"LLC_MISSES",
59+
"INSTRUCTIONS_RETIRED"
60+
]
61+
elif val == 1:
62+
data['container']['core']['events'] = [
63+
"CPU_CLK_THREAD_UNHALTED:REF_P",
64+
"CPU_CLK_THREAD_UNHALTED:THREAD_P",
65+
"LLC_MISSES",
66+
"INSTRUCTIONS_RETIRED"
67+
]
68+
elif val == 2:
69+
data['container']['core']['events'] = [
70+
"CYCLES_NOT_IN_HALT",
71+
"RETIRED_INSTRUCTIONS",
72+
"RETIRED_UOPS"
73+
]
74+
elif val == 3:
75+
data['container']['core']['events'] = [
76+
"CYCLES_NOT_IN_HALT",
77+
"RETIRED_INSTRUCTIONS",
78+
"RETIRED_OPS"
79+
]
6880

6981
print("Core events updated")
7082

71-
# Check for the cgroup version and update the sensor configuration file accordingly
72-
cgroup = subprocess.run(["stat", "-fc", "%T", "/sys/fs/cgroup/"], text=True, capture_output=True)
83+
# Check for the cgroup version and update
84+
# the sensor configuration file accordingly
85+
cgroup = subprocess.run(["stat", "-fc", "%T", "/sys/fs/cgroup/"],
86+
text=True, capture_output=True, check=True)
7387
print(cgroup.stdout)
7488
if cgroup.stdout == "cgroup2fs\n":
7589
data["cgroup_basepath"] = "/sys/fs/cgroup/"
@@ -78,12 +92,17 @@ def start_demo():
7892

7993
print("Cgroup version updated")
8094

81-
with open('sensor/hwpc-mongodb.json', 'w') as f:
95+
with open('sensor/hwpc-mongodb.json', 'w', encoding='UTF-8') as f:
8296
json.dump(data, f, indent=4)
8397

8498
print("Starting the demo...")
8599

86-
rc = call("./start.sh")
100+
call("./start.sh")
101+
102+
print("The demo has ended, "
103+
"you can see the result under the /csv directory"
104+
" or use 'python pretty_print.py' "
105+
"to get a quick summary of the result in the terminal")
87106

88107

89108
if __name__ == '__main__':

0 commit comments

Comments
 (0)