brainframe-sys-tools 0.4.post38__py3-none-any.whl
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.
- brainframe_sys_tools/__init__.py +5 -0
- brainframe_sys_tools/bf_info.py +155 -0
- brainframe_sys_tools/bf_service_monitor.py +343 -0
- brainframe_sys_tools/bf_ssh_tunnel.py +104 -0
- brainframe_sys_tools/brainframe_monitor/benchmarker.py +534 -0
- brainframe_sys_tools/brainframe_monitor/brainframe_monitor.py +105 -0
- brainframe_sys_tools/brainframe_monitor/curses_utils.py +119 -0
- brainframe_sys_tools/brainframe_monitor/fake_screen.py +30 -0
- brainframe_sys_tools/brainframe_monitor/report.py +33 -0
- brainframe_sys_tools/brainframe_monitor/requirements.txt +2 -0
- brainframe_sys_tools/check_memory.py +213 -0
- brainframe_sys_tools/cli.py +59 -0
- brainframe_sys_tools/command_utils.py +25 -0
- brainframe_sys_tools/print_utils.py +34 -0
- brainframe_sys_tools/translations/portal.en.yml +20 -0
- brainframe_sys_tools-0.4.post38.dist-info/COPYING +26 -0
- brainframe_sys_tools-0.4.post38.dist-info/METADATA +26 -0
- brainframe_sys_tools-0.4.post38.dist-info/RECORD +20 -0
- brainframe_sys_tools-0.4.post38.dist-info/WHEEL +4 -0
- brainframe_sys_tools-0.4.post38.dist-info/entry_points.txt +3 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (c) 2021 Dilili Labs, Inc. All rights reserved. Contains Dilili Labs Proprietary Information. RESTRICTED
|
|
3
|
+
# COMPUTER SOFTWARE. LIMITED RIGHTS DATA.
|
|
4
|
+
#
|
|
5
|
+
|
|
6
|
+
from math import ceil, floor
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def plot(fps_data, fps_min=None, fps_max=None, cfg={}):
|
|
10
|
+
fps_data_len = fps_data.qsize()
|
|
11
|
+
if fps_data_len == 0:
|
|
12
|
+
return (
|
|
13
|
+
"[INVALID PLOT, NO DATA]",
|
|
14
|
+
1,
|
|
15
|
+
"",
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
padding = cfg["padding"] if "padding" in cfg else " "
|
|
19
|
+
placeholder = cfg["format"] if "format" in cfg else "{:4.0f} "
|
|
20
|
+
fps_hist_buf_len = cfg["fps_hist_buf_len"] if "fps_hist_buf_len" in cfg else 60
|
|
21
|
+
plt_height_limit = cfg["plt_height_limit"] if "plt_height_limit" in cfg else 60
|
|
22
|
+
plt_width = cfg["plt_width"] if "plt_width" in cfg else 60
|
|
23
|
+
# 1st col for label, 2nd col for Y-axis symbol
|
|
24
|
+
canvas_plt_offset = cfg["canvas_plt_offset"] if "canvas_plt_offset" in cfg else 2
|
|
25
|
+
|
|
26
|
+
fps_range = fps_max - fps_min + 1
|
|
27
|
+
if fps_range == 0:
|
|
28
|
+
fps_min = fps_max - 1
|
|
29
|
+
fps_range = 1
|
|
30
|
+
fps_row_range = fps_range
|
|
31
|
+
row2fps_ratio = fps_row_range / fps_range
|
|
32
|
+
|
|
33
|
+
fps_row_min = int(floor(float(fps_min) * row2fps_ratio) - 1)
|
|
34
|
+
fps_row_ceil = int(ceil(float(fps_max) * row2fps_ratio) + 1)
|
|
35
|
+
plt_height = int(min(plt_height_limit, fps_row_ceil - fps_row_min))
|
|
36
|
+
fps_row_floor = fps_row_ceil - plt_height
|
|
37
|
+
|
|
38
|
+
fps_measures_per_col = int(fps_hist_buf_len / plt_width)
|
|
39
|
+
canvas_col_width = int(plt_width + canvas_plt_offset + 1)
|
|
40
|
+
canvas_row_height = plt_height + 1
|
|
41
|
+
|
|
42
|
+
canvas_buf = [[" "] * canvas_col_width for i in range(canvas_row_height)]
|
|
43
|
+
|
|
44
|
+
# axis and labels
|
|
45
|
+
canvas_buf[plt_height] = ["─"] * (plt_width + canvas_plt_offset)
|
|
46
|
+
for fps_row_n in range(fps_row_floor, fps_row_ceil + 1):
|
|
47
|
+
canvas_row_n = plt_height - (fps_row_n - fps_row_floor)
|
|
48
|
+
label = placeholder.format(fps_row_ceil - canvas_row_n)
|
|
49
|
+
canvas_buf[canvas_row_n][max(canvas_plt_offset - len(label), 0)] = label
|
|
50
|
+
if canvas_row_n == fps_row_ceil:
|
|
51
|
+
canvas_buf[canvas_row_n][canvas_plt_offset - 1] = "┴"
|
|
52
|
+
elif canvas_row_n == plt_height:
|
|
53
|
+
canvas_buf[canvas_row_n][canvas_plt_offset - 1] = "┼"
|
|
54
|
+
else:
|
|
55
|
+
canvas_buf[canvas_row_n][canvas_plt_offset - 1] = "┤"
|
|
56
|
+
|
|
57
|
+
fps_0, i_fps_data = 0, 0
|
|
58
|
+
for n in range(i_fps_data, i_fps_data + fps_measures_per_col):
|
|
59
|
+
# Average measures per col
|
|
60
|
+
fps_0 += fps_data.queue[n] / fps_measures_per_col
|
|
61
|
+
|
|
62
|
+
canvas_row_0 = int(plt_height - (round(fps_0 * row2fps_ratio) - fps_row_floor))
|
|
63
|
+
if canvas_row_0 > plt_height:
|
|
64
|
+
canvas_row_0 = plt_height
|
|
65
|
+
|
|
66
|
+
canvas_buf[canvas_row_0][canvas_plt_offset - 1] = (
|
|
67
|
+
"┴" if canvas_row_0 == 0 else "┼"
|
|
68
|
+
) # first value
|
|
69
|
+
|
|
70
|
+
fps_data_available_cols = int(len(fps_data.queue) / fps_measures_per_col)
|
|
71
|
+
|
|
72
|
+
if fps_data_available_cols >= 2:
|
|
73
|
+
for plt_col_n in range(
|
|
74
|
+
0, min(plt_width - 1, fps_data_available_cols - 1)
|
|
75
|
+
): # plot the line
|
|
76
|
+
i_fps_data = plt_col_n * fps_measures_per_col
|
|
77
|
+
fps_1, fps_2 = 0, 0
|
|
78
|
+
for n in range(i_fps_data, i_fps_data + fps_measures_per_col):
|
|
79
|
+
# Average measures per col
|
|
80
|
+
fps_1 += fps_data.queue[n] / fps_measures_per_col
|
|
81
|
+
fps_2 += fps_data.queue[n + fps_measures_per_col] / fps_measures_per_col
|
|
82
|
+
|
|
83
|
+
canvas_row_1 = int(
|
|
84
|
+
plt_height - (round(fps_1 * row2fps_ratio) - fps_row_floor)
|
|
85
|
+
)
|
|
86
|
+
canvas_row_2 = int(
|
|
87
|
+
plt_height - (round(fps_2 * row2fps_ratio) - fps_row_floor)
|
|
88
|
+
)
|
|
89
|
+
if canvas_row_2 > plt_height:
|
|
90
|
+
canvas_row_2 = plt_height
|
|
91
|
+
if canvas_row_1 > plt_height:
|
|
92
|
+
canvas_row_1 = plt_height
|
|
93
|
+
|
|
94
|
+
canvas_col = plt_col_n + canvas_plt_offset
|
|
95
|
+
if canvas_row_1 == canvas_row_2:
|
|
96
|
+
canvas_buf[canvas_row_1][canvas_col] = "─"
|
|
97
|
+
else:
|
|
98
|
+
canvas_buf[canvas_row_1][canvas_col] = (
|
|
99
|
+
"╮" if canvas_row_1 < canvas_row_2 else "╯"
|
|
100
|
+
)
|
|
101
|
+
canvas_row_1to2_start, canvas_row_1to2_end = (
|
|
102
|
+
min(canvas_row_1, canvas_row_2) + 1,
|
|
103
|
+
max(canvas_row_1, canvas_row_2),
|
|
104
|
+
)
|
|
105
|
+
if canvas_row_1to2_start > plt_height:
|
|
106
|
+
canvas_row_1to2_start = plt_height
|
|
107
|
+
for canvas_row_n in range(canvas_row_1to2_start, canvas_row_1to2_end):
|
|
108
|
+
canvas_buf[canvas_row_n][canvas_col] = "│"
|
|
109
|
+
canvas_buf[canvas_row_2][canvas_col] = (
|
|
110
|
+
"╰" if canvas_row_1 < canvas_row_2 else "╭"
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
plot_n_rows = len(canvas_buf) - 1
|
|
114
|
+
debug_print = ""
|
|
115
|
+
return (
|
|
116
|
+
"\n".join(["".join(row) for row in canvas_buf]),
|
|
117
|
+
plot_n_rows,
|
|
118
|
+
debug_print,
|
|
119
|
+
)
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (c) 2021 Dilili Labs, Inc. All rights reserved. Contains Dilili Labs Proprietary Information. RESTRICTED
|
|
3
|
+
# COMPUTER SOFTWARE. LIMITED RIGHTS DATA.
|
|
4
|
+
#
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class FakeScreen:
|
|
8
|
+
@staticmethod
|
|
9
|
+
def clear():
|
|
10
|
+
pass
|
|
11
|
+
|
|
12
|
+
@staticmethod
|
|
13
|
+
def addstr(row, col, message):
|
|
14
|
+
print(message)
|
|
15
|
+
pass
|
|
16
|
+
|
|
17
|
+
@staticmethod
|
|
18
|
+
def refresh():
|
|
19
|
+
pass
|
|
20
|
+
|
|
21
|
+
def nodelay(self):
|
|
22
|
+
pass
|
|
23
|
+
|
|
24
|
+
@staticmethod
|
|
25
|
+
def getch():
|
|
26
|
+
pass
|
|
27
|
+
|
|
28
|
+
@staticmethod
|
|
29
|
+
def getmaxyx():
|
|
30
|
+
return 80, 80
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (c) 2021 Dilili Labs, Inc. All rights reserved. Contains Dilili Labs Proprietary Information. RESTRICTED
|
|
3
|
+
# COMPUTER SOFTWARE. LIMITED RIGHTS DATA.
|
|
4
|
+
#
|
|
5
|
+
|
|
6
|
+
from typing import Dict, List
|
|
7
|
+
|
|
8
|
+
from brainframe.api.stubs.zone_statuses import ZONE_STATUS_TYPE
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class Report:
|
|
12
|
+
def __init__(self, times_hist_len):
|
|
13
|
+
"""
|
|
14
|
+
:param samples: The number of samples for the throughput measurement
|
|
15
|
+
"""
|
|
16
|
+
self.times_hist_len = times_hist_len
|
|
17
|
+
|
|
18
|
+
self.times_hist: Dict[tuple, List[float]] = {}
|
|
19
|
+
"""{stream_id: [zs_tstamp, ...]"""
|
|
20
|
+
|
|
21
|
+
@property
|
|
22
|
+
def num_samples_collected(self):
|
|
23
|
+
"""A helper for returning the number of samples currently collected
|
|
24
|
+
|
|
25
|
+
Don't use this for any algorithms in the report. Only use it for getting
|
|
26
|
+
an idea of how many samples have yet been collected."""
|
|
27
|
+
times = list(self.times_hist.values())
|
|
28
|
+
if len(times) == 0:
|
|
29
|
+
return 0
|
|
30
|
+
|
|
31
|
+
slowest_stream_n_samples = min(len(ts) for ts in times)
|
|
32
|
+
if slowest_stream_n_samples > 0:
|
|
33
|
+
return slowest_stream_n_samples
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import resource
|
|
3
|
+
import random
|
|
4
|
+
import psutil
|
|
5
|
+
import argparse
|
|
6
|
+
from datetime import datetime
|
|
7
|
+
import time
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def read_file(file_path):
|
|
11
|
+
with open(file_path, "r") as f:
|
|
12
|
+
return f.read().strip()
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def bytes_to_mib(bytes):
|
|
16
|
+
return int(bytes) / 1024 / 1024
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def cgroup_usage(uid):
|
|
20
|
+
limit_in_bytes = read_file(
|
|
21
|
+
f"/sys/fs/cgroup/memory/user.slice/user-{uid}.slice/memory.limit_in_bytes"
|
|
22
|
+
)
|
|
23
|
+
max_usage_in_bytes = read_file(
|
|
24
|
+
f"/sys/fs/cgroup/memory/user.slice/user-{uid}.slice/memory.max_usage_in_bytes"
|
|
25
|
+
)
|
|
26
|
+
usage_in_bytes = read_file(
|
|
27
|
+
f"/sys/fs/cgroup/memory/user.slice/user-{uid}.slice/memory.usage_in_bytes"
|
|
28
|
+
)
|
|
29
|
+
return limit_in_bytes, max_usage_in_bytes, usage_in_bytes
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def print_cgroup_usage(uid):
|
|
33
|
+
limit_in_bytes, max_usage_in_bytes, usage_in_bytes = cgroup_usage(uid)
|
|
34
|
+
print(f"/sys/fs/cgroup/memory/user.slice/user-{uid}.slice/")
|
|
35
|
+
print(f" Limit in bytes: {bytes_to_mib(limit_in_bytes)} MiB")
|
|
36
|
+
print(f" Max usage in bytes: {bytes_to_mib(max_usage_in_bytes)} MiB")
|
|
37
|
+
print(f" Usage in bytes: {bytes_to_mib(usage_in_bytes)} MiB")
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def print_resource_usage():
|
|
41
|
+
# Print memory usage
|
|
42
|
+
usage = resource.getrusage(resource.RUSAGE_SELF)
|
|
43
|
+
print(f"resource.getrusage()")
|
|
44
|
+
print(f" Memory Usage: {usage.ru_maxrss / 1024} MiB bytes")
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def process_memory_info(pid):
|
|
48
|
+
try:
|
|
49
|
+
process = psutil.Process(pid)
|
|
50
|
+
process_mem_info = process.memory_info()
|
|
51
|
+
rss_in_bytes = process_mem_info.rss # in bytes
|
|
52
|
+
return rss_in_bytes
|
|
53
|
+
except psutil.NoSuchProcess:
|
|
54
|
+
return 0
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def print_process_memory_info(pid):
|
|
58
|
+
rss_in_bytes = process_memory_info(pid)
|
|
59
|
+
print(f"psutil.Process({pid}).memory_info()")
|
|
60
|
+
if rss_in_bytes is not None:
|
|
61
|
+
print(f" RSS: {bytes_to_mib(rss_in_bytes)} MiB") # convert bytes to MiB
|
|
62
|
+
else:
|
|
63
|
+
print(f" No such process")
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def system_memory_usage():
|
|
67
|
+
# Get the system memory usage
|
|
68
|
+
mem_info = psutil.virtual_memory()
|
|
69
|
+
|
|
70
|
+
# Total physical memory
|
|
71
|
+
total = mem_info.total # in bytes
|
|
72
|
+
|
|
73
|
+
# Available physical memory
|
|
74
|
+
available = mem_info.available # in bytes
|
|
75
|
+
|
|
76
|
+
# Used physical memory
|
|
77
|
+
used = mem_info.used # in bytes
|
|
78
|
+
|
|
79
|
+
# Memory used for buffering
|
|
80
|
+
buffers = mem_info.buffers if hasattr(mem_info, "buffers") else 0 # in bytes
|
|
81
|
+
|
|
82
|
+
# Memory used for caching
|
|
83
|
+
cached = mem_info.cached if hasattr(mem_info, "cached") else 0 # in bytes
|
|
84
|
+
return total, available, used, buffers, cached
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def print_system_memory_usage():
|
|
88
|
+
total, available, used, buffers, cached = system_memory_usage()
|
|
89
|
+
print(f"psutil.virtual_memory()")
|
|
90
|
+
print(f" Total physical memory: {bytes_to_mib(total)} MiB")
|
|
91
|
+
print(f" Available physical memory: {bytes_to_mib(available)} MiB")
|
|
92
|
+
print(f" Used physical memory: {bytes_to_mib(used)} MiB")
|
|
93
|
+
print(f" Buffered memory: {bytes_to_mib(buffers)} MiB")
|
|
94
|
+
print(f" Cached memory: {bytes_to_mib(cached)} MiB")
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def draw_bar_chart(data, graph_max):
|
|
98
|
+
colors = ["\033[91m", "\033[92m", "\033[93m", "\033[94m", "\033[95m", "\033[0m"]
|
|
99
|
+
for i in range(len(data)):
|
|
100
|
+
label, min_val, value, max_val = data[i]
|
|
101
|
+
value = max(min_val, min(value, max_val))
|
|
102
|
+
|
|
103
|
+
# Normalize the value to the range of the graph
|
|
104
|
+
normalized_value = (
|
|
105
|
+
int((value - min_val) / (max_val - min_val) * graph_max)
|
|
106
|
+
if max_val != min_val
|
|
107
|
+
else 0
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
# Draw the label, min, max, and value with color
|
|
111
|
+
color = colors[i % len(colors)]
|
|
112
|
+
pct = value * 100 / max_val
|
|
113
|
+
print(
|
|
114
|
+
f"{label:<10} {min_val:<2}[{color}{'|' * normalized_value}\033[0m {value:<5} {' ' * (graph_max - normalized_value)}{pct:.2f}%] {max_val:<5}"
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def monitor_memory(uid, pid):
|
|
119
|
+
total, available, used, buffers, cached = system_memory_usage()
|
|
120
|
+
limit_in_bytes, max_usage_in_bytes, usage_in_bytes = cgroup_usage(uid)
|
|
121
|
+
rss_in_bytes = process_memory_info(pid)
|
|
122
|
+
data = [
|
|
123
|
+
(
|
|
124
|
+
" system used / system total",
|
|
125
|
+
0,
|
|
126
|
+
int(bytes_to_mib(used)),
|
|
127
|
+
int(bytes_to_mib(total)),
|
|
128
|
+
),
|
|
129
|
+
(
|
|
130
|
+
"cgroup usage / system used",
|
|
131
|
+
0,
|
|
132
|
+
int(bytes_to_mib(usage_in_bytes)),
|
|
133
|
+
int(bytes_to_mib(used)),
|
|
134
|
+
),
|
|
135
|
+
(
|
|
136
|
+
" process rss / cgroup usage",
|
|
137
|
+
0,
|
|
138
|
+
int(bytes_to_mib(rss_in_bytes)),
|
|
139
|
+
int(bytes_to_mib(usage_in_bytes)),
|
|
140
|
+
),
|
|
141
|
+
]
|
|
142
|
+
draw_bar_chart(data, 50)
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def main():
|
|
146
|
+
parser = argparse.ArgumentParser(description="Get memory usage for a process.")
|
|
147
|
+
parser.add_argument(
|
|
148
|
+
"-u",
|
|
149
|
+
"--uid",
|
|
150
|
+
type=int,
|
|
151
|
+
default=os.getuid(),
|
|
152
|
+
help="The process ID to get memory usage for.",
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
parser.add_argument(
|
|
156
|
+
"-p",
|
|
157
|
+
"--pid",
|
|
158
|
+
type=int,
|
|
159
|
+
default=os.getpid(),
|
|
160
|
+
help="The process ID to get memory usage for.",
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
parser.add_argument(
|
|
164
|
+
"-i",
|
|
165
|
+
"--interval",
|
|
166
|
+
type=int,
|
|
167
|
+
default=60,
|
|
168
|
+
help="Interval for the memory usage monitor.",
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
parser.add_argument(
|
|
172
|
+
"-k",
|
|
173
|
+
"--key",
|
|
174
|
+
action="store_true",
|
|
175
|
+
help="Wait for a key to monitor the memory usage.",
|
|
176
|
+
)
|
|
177
|
+
|
|
178
|
+
args = parser.parse_args()
|
|
179
|
+
|
|
180
|
+
print(f"User ID: {args.uid}")
|
|
181
|
+
print(f"Process ID: {args.pid}")
|
|
182
|
+
|
|
183
|
+
print_system_memory_usage()
|
|
184
|
+
# No way to specify pid
|
|
185
|
+
# print_resource_usage()
|
|
186
|
+
print_cgroup_usage(args.uid)
|
|
187
|
+
print_process_memory_info(args.pid)
|
|
188
|
+
|
|
189
|
+
if args.key:
|
|
190
|
+
print("Enter to continue, Q to quit: ")
|
|
191
|
+
|
|
192
|
+
while True:
|
|
193
|
+
# Current date and time
|
|
194
|
+
now = datetime.now()
|
|
195
|
+
|
|
196
|
+
# Format timestamp
|
|
197
|
+
timestamp = now.strftime("%d-%m-%Y %H:%M:%S")
|
|
198
|
+
|
|
199
|
+
print(timestamp)
|
|
200
|
+
|
|
201
|
+
monitor_memory(args.uid, args.pid)
|
|
202
|
+
|
|
203
|
+
if args.key:
|
|
204
|
+
# wait for a key press
|
|
205
|
+
key = input()
|
|
206
|
+
if key == "q" or key == "Q":
|
|
207
|
+
break
|
|
208
|
+
else:
|
|
209
|
+
time.sleep(args.interval)
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
if __name__ == "__main__":
|
|
213
|
+
main()
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
os.environ["BF_LOG_PRINT"] = "TRUE"
|
|
4
|
+
|
|
5
|
+
import signal
|
|
6
|
+
import sys
|
|
7
|
+
from argparse import ArgumentParser
|
|
8
|
+
|
|
9
|
+
import i18n
|
|
10
|
+
import yaml
|
|
11
|
+
from brainframe_sys_tools import command_utils, print_utils
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def add_translations(translations, prefix=""):
|
|
15
|
+
for key, value in translations.items():
|
|
16
|
+
full_key = f"{prefix}.{key}" if prefix else key
|
|
17
|
+
if isinstance(value, dict):
|
|
18
|
+
add_translations(value, full_key)
|
|
19
|
+
else:
|
|
20
|
+
i18n.add_translation(full_key, value)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def cli_main():
|
|
24
|
+
i18n.load_path.append(_TRANSLATIONS_PATH)
|
|
25
|
+
|
|
26
|
+
# Load translations manually
|
|
27
|
+
translation_file = os.path.join(_TRANSLATIONS_PATH, "portal.en.yml")
|
|
28
|
+
if os.path.exists(translation_file):
|
|
29
|
+
with open(translation_file, "r") as file:
|
|
30
|
+
translations = yaml.safe_load(file)
|
|
31
|
+
add_translations(translations)
|
|
32
|
+
|
|
33
|
+
parser = ArgumentParser(
|
|
34
|
+
description=i18n.t("en.portal.description"), usage=i18n.t("en.portal.usage")
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
parser.add_argument(
|
|
38
|
+
"command", default=None, nargs="?", help=i18n.t("en.portal.command-help")
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
args = parser.parse_args(sys.argv[1:2])
|
|
42
|
+
|
|
43
|
+
if args.command is None:
|
|
44
|
+
parser.print_help()
|
|
45
|
+
elif args.command in command_utils.by_name:
|
|
46
|
+
command = command_utils.by_name[args.command]
|
|
47
|
+
command()
|
|
48
|
+
else:
|
|
49
|
+
error_message = i18n.t("portal.unknown-command")
|
|
50
|
+
error_message = error_message.format(command=args.command)
|
|
51
|
+
print_utils.print_color(
|
|
52
|
+
error_message, color=print_utils.Color.RED, file=sys.stderr
|
|
53
|
+
)
|
|
54
|
+
parser.print_help()
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
_TRANSLATIONS_PATH = os.path.join(os.path.dirname(__file__), "translations")
|
|
58
|
+
if __name__ == "__main__":
|
|
59
|
+
cli_main()
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
from argparse import ArgumentParser
|
|
3
|
+
|
|
4
|
+
by_name = {}
|
|
5
|
+
"""A dict that maps command names to their corresponding function"""
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def command(name):
|
|
9
|
+
"""A decorator that associates command functions to their command name."""
|
|
10
|
+
|
|
11
|
+
def wrapper(function):
|
|
12
|
+
by_name[name] = function
|
|
13
|
+
|
|
14
|
+
return wrapper
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def subcommand_parse_args(parser: ArgumentParser):
|
|
18
|
+
arg_list = sys.argv[2:]
|
|
19
|
+
args = parser.parse_args(arg_list)
|
|
20
|
+
|
|
21
|
+
# Run in non-interactive mode if any flags were provided
|
|
22
|
+
if len(arg_list) > 0:
|
|
23
|
+
args.noninteractive = True
|
|
24
|
+
|
|
25
|
+
return args
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import readline
|
|
3
|
+
import sys
|
|
4
|
+
from enum import Enum
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
import i18n
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Color(Enum):
|
|
11
|
+
"""ANSI escape codes representing colors in the terminal theme."""
|
|
12
|
+
|
|
13
|
+
MAGENTA = "\033[95m"
|
|
14
|
+
BLUE = "\033[94m"
|
|
15
|
+
GREEN = "\033[92m"
|
|
16
|
+
YELLOW = "\033[93m"
|
|
17
|
+
RED = "\033[91m"
|
|
18
|
+
END = "\033[0m"
|
|
19
|
+
BOLD = "\033[1m"
|
|
20
|
+
UNDERLINE = "\033[4m"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def print_color(message, color: Color, **kwargs) -> None:
|
|
24
|
+
color = _check_no_color(color)
|
|
25
|
+
print(f"{color.value}{message}{Color.END.value}", **kwargs)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _check_no_color(color: Color) -> Color:
|
|
29
|
+
"""Turns off color if the user wants.
|
|
30
|
+
See: https://no-color.org/
|
|
31
|
+
"""
|
|
32
|
+
if "NO_COLOR" in os.environ:
|
|
33
|
+
return Color.END
|
|
34
|
+
return color
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
en:
|
|
2
|
+
portal:
|
|
3
|
+
description: "brainframe-sys-tools is a group of commands written in Python. They
|
|
4
|
+
help to monitor brainframe system and debug the system deployment related issues.
|
|
5
|
+
To see options of each command, run \"brainframe-sys-tools {command} --help\"."
|
|
6
|
+
usage: >-
|
|
7
|
+
brainframe-sys-tools <command> [<args>]
|
|
8
|
+
|
|
9
|
+
commands:
|
|
10
|
+
fps_monitor
|
|
11
|
+
service_monitor
|
|
12
|
+
sys_info
|
|
13
|
+
ssh_tunnel
|
|
14
|
+
|
|
15
|
+
Examples:
|
|
16
|
+
brainframe-sys-tools fps_monitor
|
|
17
|
+
|
|
18
|
+
command-help: "The brainframe-sys-tools command to run"
|
|
19
|
+
unknown-command: "Unknown command: {command}"
|
|
20
|
+
interrupted: "The operation was interrupted"
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
Copyright (C) 2020, Dilili Labs INC, all rights reserved.
|
|
2
|
+
|
|
3
|
+
Redistribution and use in source and binary forms, with or without
|
|
4
|
+
modification, are permitted provided that the following conditions are met:
|
|
5
|
+
|
|
6
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
7
|
+
list of conditions and the following disclaimer.
|
|
8
|
+
|
|
9
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
10
|
+
this list of conditions and the following disclaimer in the documentation
|
|
11
|
+
and/or other materials provided with the distribution.
|
|
12
|
+
|
|
13
|
+
3. Neither the name of the copyright holder nor the names of its contributors
|
|
14
|
+
may be used to endorse or promote products derived from this software without
|
|
15
|
+
specific prior written permission.
|
|
16
|
+
|
|
17
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
18
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
19
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
20
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
21
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
22
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
23
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
24
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
25
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
26
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: brainframe-sys-tools
|
|
3
|
+
Version: 0.4.post38
|
|
4
|
+
Summary: This is the package including tools for BrainFrame developers to monitor and debug the system.
|
|
5
|
+
License: BSD License
|
|
6
|
+
Author: Stephen Li
|
|
7
|
+
Author-email: stephen@aotu.ai
|
|
8
|
+
Requires-Python: >=3.8,<4.0
|
|
9
|
+
Classifier: License :: OSI Approved :: BSD License
|
|
10
|
+
Classifier: License :: Other/Proprietary License
|
|
11
|
+
Classifier: Programming Language :: Python
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Requires-Dist: PyYAML (>=6.0.2,<7.0.0)
|
|
20
|
+
Requires-Dist: apscheduler (>=3.10.4,<4.0.0)
|
|
21
|
+
Requires-Dist: brainframe-api (>=0.29.1,<0.30.0)
|
|
22
|
+
Requires-Dist: brainframe_apps (>=0.4.3.5,<0.5.0.0)
|
|
23
|
+
Requires-Dist: psutil (>=5.8.0,<6.0.0)
|
|
24
|
+
Requires-Dist: python_i18n (>=0.3.9,<0.4.0)
|
|
25
|
+
Requires-Dist: requests (>=2.32.3,<3.0.0)
|
|
26
|
+
Requires-Dist: tabulate (>=0.8.9,<0.9.0)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
brainframe_sys_tools/__init__.py,sha256=lLVPQBRvy_0XOL_qrRCyif4TPJKFZ4z7bk6Gibcqgag,205
|
|
2
|
+
brainframe_sys_tools/bf_info.py,sha256=6-j_XUr24SAyCuf8nFjZETQpTzMPkHzOWaOnYlA45h0,3987
|
|
3
|
+
brainframe_sys_tools/bf_service_monitor.py,sha256=rxSBFOFIu_PIT1wZcxJ8d9hbfvZsITZqJB8BPZNaTgc,12704
|
|
4
|
+
brainframe_sys_tools/bf_ssh_tunnel.py,sha256=z23EDkAcmyrZHm70aoAQ7Cuj2V_qG1vW5pHho1wlzi8,3141
|
|
5
|
+
brainframe_sys_tools/brainframe_monitor/benchmarker.py,sha256=ivfGoI3tGJrVWcJN1AKsT_1pZVCjXvgaPPw8pblpdGc,16780
|
|
6
|
+
brainframe_sys_tools/brainframe_monitor/brainframe_monitor.py,sha256=kMLFPJ3l6e0SlPCMMWzFIfnK-CXt1Afkwd2Vwb4RAog,3097
|
|
7
|
+
brainframe_sys_tools/brainframe_monitor/curses_utils.py,sha256=HUacFarlx7eE2qFc0nFxJO4MMiuM9QOXBxxHyDzG00Q,4841
|
|
8
|
+
brainframe_sys_tools/brainframe_monitor/fake_screen.py,sha256=N8jt00FdyuTFq-FFbiF5Vd3jVGhRREnESIkSAKBHbfw,521
|
|
9
|
+
brainframe_sys_tools/brainframe_monitor/report.py,sha256=CyPKfrY0eIq0Wm4Dbw4YOQl4uL9WO8Pj5tQKnrp13hY,1082
|
|
10
|
+
brainframe_sys_tools/brainframe_monitor/requirements.txt,sha256=fkcslgJLmcbsaFuCWQNuJ2ngiViRl0HtlWOc67ypvrM,39
|
|
11
|
+
brainframe_sys_tools/check_memory.py,sha256=IinKUX1ITltilx5V2xxm1yNre57zW4GL0ytdZpDd3Xw,6028
|
|
12
|
+
brainframe_sys_tools/cli.py,sha256=wgS4frBKkfEisjK0Ns5qZk9fXmWh-3ifCtiOOTkN_Nc,1698
|
|
13
|
+
brainframe_sys_tools/command_utils.py,sha256=8vmBRhFWsn642U74MeW4Hvgv8P5Fn_HJ6rf8xrkLPfk,571
|
|
14
|
+
brainframe_sys_tools/print_utils.py,sha256=Q8iyHQ9ZHIt3AfUjv3mUOWjhAo2xkPAI4hAxck-Hl2s,733
|
|
15
|
+
brainframe_sys_tools/translations/portal.en.yml,sha256=G8k2eAfMPNAGYTZ5w4v4urTuX6DUvXIHT0pxCZ-yZ24,646
|
|
16
|
+
brainframe_sys_tools-0.4.post38.dist-info/COPYING,sha256=gUdx8BDkY31TjlE3BXyajv8oSs-1hxBD4NUn-hUZi6w,1502
|
|
17
|
+
brainframe_sys_tools-0.4.post38.dist-info/METADATA,sha256=Nckt6fbLPeuCD96PoUuVTIko-eVQWm0TC3fv0KNA2Ws,1117
|
|
18
|
+
brainframe_sys_tools-0.4.post38.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
|
19
|
+
brainframe_sys_tools-0.4.post38.dist-info/entry_points.txt,sha256=1A6zW8peN6VPJPX3OwppCy2lmMBC2WyzLB_aRzetwH8,74
|
|
20
|
+
brainframe_sys_tools-0.4.post38.dist-info/RECORD,,
|