Skip to content

Commit 707e727

Browse files
committed
docs(getting-started): Removed start.sh a,d stop.sh
Removed start.sh and stop.sh and adapte start.py
1 parent 99ecc97 commit 707e727

File tree

3 files changed

+49
-30
lines changed

3 files changed

+49
-30
lines changed

docs/script/getting_started/start.py

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2727
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2828
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29-
import re
3029

30+
import re
3131
import csv
3232
import os
3333
import sys
@@ -51,6 +51,20 @@ def signal_handler(sig, frame):
5151
call("./stop.sh")
5252

5353

54+
def docker_start(time):
55+
os.system("docker-compose up -d")
56+
os.system("docker compose logs sensor -f &")
57+
os.system("docker compose logs formula -f &")
58+
os.system("sleep " + str(time))
59+
docker_stop()
60+
61+
62+
def docker_stop():
63+
os.system("set -ueo pipefail")
64+
os.system("set +x")
65+
os.system("docker-compose down")
66+
67+
5468
def load_data():
5569
"""
5670
Load CSV files from the specified directory and return the data as a list of dictionaries.
@@ -68,21 +82,20 @@ def find_cpu(data):
6882
option = []
6983
line = "cat /proc/cpuinfo | grep 'model name'"
7084
result = subprocess.check_output(line, shell=True, text=True).split("\n")
71-
print(result[0])
85+
print("The CPU found is" + result[0].split(":")[1] )
7286
parse = parse_processor_name(result[0])
73-
print(parse)
7487
for row in data :
75-
if parse[0] in row["Name"]:
88+
if parse[0] in row["Name"] and row["Manufacturer"] == parse[1]:
7689
option.append(row)
7790

7891
if len(option) == 0:
79-
print("It looks like you cpu is not supported by power API")
92+
print("It looks like you cpu is not supported by PowerAPI")
8093
sys.exit()
8194
elif len(option) == 1:
82-
print("Your cpu is supported by power API")
95+
print("Your CPU should be supported by PowerAPI")
8396
cpu = option[0]
8497
else:
85-
print("Please select your cpu from this list")
98+
print("Please select your CPU from this list")
8699
for i in range(len(option)):
87100
print(str(i) + " - " + option[i]["Name"])
88101
choice = int(input())
@@ -96,7 +109,7 @@ def parse_processor_name(name):
96109
brand = "Intel"
97110
elif "AMD" in name:
98111
brand = "AMD"
99-
else :
112+
else:
100113
brand = "Unknown"
101114
id_pattern = r"\b\d{3,4}[A-Z0-9]*\b"
102115

@@ -110,9 +123,12 @@ def start_demo():
110123
Start the demo by selecting the processor architecture
111124
this will update the sensor configuration file
112125
"""
126+
print("PowerAPI demo")
127+
print("=" * 80)
113128
cpu = find_cpu(load_data())
114-
print(cpu)
115129

130+
print("\nSetting up configuration files...")
131+
print("-" * 80)
116132
# Update core events in the sensor configuration
117133
# file based on the selected processor architecture
118134
with open('sensor/hwpc-mongodb.json', encoding='UTF-8') as f:
@@ -151,7 +167,6 @@ def start_demo():
151167
# the sensor configuration file accordingly
152168
cgroup = subprocess.run(["stat", "-fc", "%T", "/sys/fs/cgroup/"],
153169
text=True, capture_output=True, check=True)
154-
print(cgroup.stdout)
155170
if cgroup.stdout == "cgroup2fs\n":
156171
data["cgroup_basepath"] = "/sys/fs/cgroup/"
157172
else:
@@ -168,17 +183,37 @@ def start_demo():
168183

169184
if cpu["Base frequency"] != '':
170185
formula_config["cpu-base-freq"] = int(float(cpu["Base frequency"])*1000)
186+
print("Base frequency updated")
171187

172188
if cpu["TDP"] != '':
173189
formula_config["cpu-tdp"] = int(cpu["TDP"][:-1])
190+
print("TDP updated\n")
174191

175192
with open('formula/smartwatts-mongodb-csv.json', 'w', encoding='UTF-8') as f:
176193
json.dump(formula_config, f, indent=4)
177194

178-
print("Starting the demo...")
179-
print("The demo will run for approximately 2 minutes\n")
180-
181-
call("./start.sh")
195+
print("Please enter the number of second you want the demo to run for (minimum 30) or exit to quit:")
196+
waiting = True
197+
while waiting:
198+
try:
199+
val = input()
200+
val = int(val)
201+
if val < 30:
202+
print("Invalid input, please enter a valid number or exit to quit")
203+
else:
204+
waiting = False
205+
except ValueError:
206+
if val == "exit":
207+
print("Exiting...")
208+
sys.exit()
209+
else:
210+
print("Invalid input, please enter a valid number or exit to quit")
211+
212+
print("\nStarting the demo...")
213+
print("-" * 80)
214+
print("The demo will run for " + val + "\n")
215+
216+
docker_start(val)
182217

183218
verification = 0
184219

docs/script/getting_started/start.sh

Lines changed: 0 additions & 11 deletions
This file was deleted.

docs/script/getting_started/stop.sh

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)