fix a bug which do not show summed vmen in process section and some slight modifications
This commit is contained in:
parent
5f57991308
commit
8ae743e166
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,6 +4,7 @@ __pycache__/
|
|||||||
*.py[cod]
|
*.py[cod]
|
||||||
*$py.class
|
*$py.class
|
||||||
try.py
|
try.py
|
||||||
|
.vscode/
|
||||||
|
|
||||||
# C extensions
|
# C extensions
|
||||||
*.so
|
*.so
|
||||||
|
|||||||
@ -28,6 +28,8 @@ def save_config(config):
|
|||||||
|
|
||||||
# style format: |c|l:15|r|c:14rl:13|
|
# style format: |c|l:15|r|c:14rl:13|
|
||||||
def parse_style(style):
|
def parse_style(style):
|
||||||
|
if style is None:
|
||||||
|
return None, None
|
||||||
components = []
|
components = []
|
||||||
limits = []
|
limits = []
|
||||||
while len(style) > 0:
|
while len(style) > 0:
|
||||||
@ -60,14 +62,16 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('--profile', '-p', default=None, type=str, help='profile keyword, corresponding configuration are saved in ~/.gpuutil.conf')
|
parser.add_argument('--profile', '-p', default=None, type=str, help='profile keyword, corresponding configuration are saved in ~/.gpuutil.conf')
|
||||||
parser.add_argument('--cols', '-c', type=csv2list, help='colums to show')
|
parser.add_argument('--cols', '-c', type=csv2list, help='colums to show.(Availabel cols: {0}'.format(avaliable_cols))
|
||||||
parser.add_argument('--style', '-sty', type=parse_style, help='column style')
|
parser.add_argument('--style', '-sty', type=str, default=None, help='column style, format: |c|l:15|r|c:14rl:13|, c,l,r are align methods, | is line and :(int) are width limit.')
|
||||||
parser.add_argument('--show-process', '-sp', default=True, type=str2bool, help='whether show process or not')
|
parser.add_argument('--show-process', '-sp', default=True, type=str2bool, help='whether show process or not')
|
||||||
|
parser.add_argument('--vertical', '-v', default=False, type=str2bool, help='whether show each user in different lines. (show user vertically)')
|
||||||
parser.add_argument('--save', default=False, action="store_true", help='save config to profile')
|
parser.add_argument('--save', default=False, action="store_true", help='save config to profile')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
cols = args.cols if args.cols is not None else recommended_cols
|
cols = args.cols if args.cols is not None else recommended_cols
|
||||||
show_process = args.show_process
|
show_process = args.show_process
|
||||||
style, limit = args.style
|
style, limit = parse_style(args.style)
|
||||||
|
vertical = args.vertical
|
||||||
unexpected_cols = []
|
unexpected_cols = []
|
||||||
for col in cols:
|
for col in cols:
|
||||||
if col not in avaliable_cols:
|
if col not in avaliable_cols:
|
||||||
@ -78,9 +82,10 @@ if __name__ == '__main__':
|
|||||||
if args.save:
|
if args.save:
|
||||||
params = {
|
params = {
|
||||||
"cols": cols,
|
"cols": cols,
|
||||||
"show-process": show_process,
|
|
||||||
"style": style,
|
"style": style,
|
||||||
"limit": limit
|
"limit": limit,
|
||||||
|
"show-process": show_process,
|
||||||
|
"vertical": vertical
|
||||||
}
|
}
|
||||||
profile = args.profile if args.profile is not None else input('Please input your profile name:\n>>> ')
|
profile = args.profile if args.profile is not None else input('Please input your profile name:\n>>> ')
|
||||||
config = load_config()
|
config = load_config()
|
||||||
@ -94,11 +99,14 @@ if __name__ == '__main__':
|
|||||||
show_process = params["show-process"]
|
show_process = params["show-process"]
|
||||||
style = None
|
style = None
|
||||||
limit = None
|
limit = None
|
||||||
|
vertical = False
|
||||||
if "style" in params:
|
if "style" in params:
|
||||||
style = params["style"]
|
style = params["style"]
|
||||||
if "limit" in params:
|
if "limit" in params:
|
||||||
limit = params["limit"]
|
limit = params["limit"]
|
||||||
|
if "vertical" in params:
|
||||||
|
vertical = params["vertical"]
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise ValueError('Profile do not exist.\nAvaliable Profiles:{0}'.format(','.join(list(config.keys()))))
|
raise ValueError('Profile do not exist.\nAvaliable Profiles:{0}'.format(','.join(list(config.keys()))))
|
||||||
stat.show(enabled_cols = cols, colsty=style, colsz=limit, show_command=show_process)
|
stat.show(enabled_cols = cols, colsty=style, colsz=limit, vertical=vertical, show_command=show_process)
|
||||||
@ -195,7 +195,7 @@ def draw_table(table, rowsty=None, colsty=None, colsz = None):
|
|||||||
for row in table:
|
for row in table:
|
||||||
for i, col in enumerate(row):
|
for i, col in enumerate(row):
|
||||||
col = str(col)
|
col = str(col)
|
||||||
width = len(col)
|
width = max([len(c) for c in col.split('\n')])
|
||||||
if colsz[i] is not None and colsz[i] < width:
|
if colsz[i] is not None and colsz[i] < width:
|
||||||
width = colsz[i]
|
width = colsz[i]
|
||||||
if width > col_width[i]:
|
if width > col_width[i]:
|
||||||
@ -204,7 +204,8 @@ def draw_table(table, rowsty=None, colsty=None, colsz = None):
|
|||||||
vline = []
|
vline = []
|
||||||
colaligns = []
|
colaligns = []
|
||||||
col_pos = 0
|
col_pos = 0
|
||||||
delemeter = ' '
|
line_delemeter = '-'
|
||||||
|
content_delemeter = ' '
|
||||||
for ch in colsty:
|
for ch in colsty:
|
||||||
if ch == '|':
|
if ch == '|':
|
||||||
vline.append('+')
|
vline.append('+')
|
||||||
@ -212,7 +213,7 @@ def draw_table(table, rowsty=None, colsty=None, colsz = None):
|
|||||||
colaligns.append(ch)
|
colaligns.append(ch)
|
||||||
vline.append('-' * col_width[col_pos])
|
vline.append('-' * col_width[col_pos])
|
||||||
col_pos += 1
|
col_pos += 1
|
||||||
vline = delemeter.join(vline)
|
vline = line_delemeter.join(vline)
|
||||||
table_to_draw = []
|
table_to_draw = []
|
||||||
row_pos = 0
|
row_pos = 0
|
||||||
for ch in rowsty:
|
for ch in rowsty:
|
||||||
@ -253,7 +254,7 @@ def draw_table(table, rowsty=None, colsty=None, colsz = None):
|
|||||||
elif ch in ['c', 'r', 'l']:
|
elif ch in ['c', 'r', 'l']:
|
||||||
cols_to_drawn.append(row[col_pos])
|
cols_to_drawn.append(row[col_pos])
|
||||||
col_pos += 1
|
col_pos += 1
|
||||||
strings.append(delemeter.join(cols_to_drawn))
|
strings.append(content_delemeter.join(cols_to_drawn))
|
||||||
return '\n'.join(strings)
|
return '\n'.join(strings)
|
||||||
|
|
||||||
class GPUStat():
|
class GPUStat():
|
||||||
@ -298,7 +299,7 @@ class GPUStat():
|
|||||||
gpu['id'] = i
|
gpu['id'] = i
|
||||||
self.gpus.append(gpu)
|
self.gpus.append(gpu)
|
||||||
|
|
||||||
def show(self, enabled_cols = ['ID', 'Fan', 'Temp', 'Pwr', 'Freq', 'Util', 'Vmem', 'Users'], colsty=None, colsz=None, show_command=True):
|
def show(self, enabled_cols = ['ID', 'Fan', 'Temp', 'Pwr', 'Freq', 'Util', 'Vmem', 'Users'], colsty=None, colsz=None, show_command=True, vertical=False):
|
||||||
self.parse()
|
self.parse()
|
||||||
gpu_infos = []
|
gpu_infos = []
|
||||||
# stats = {
|
# stats = {
|
||||||
@ -329,7 +330,10 @@ class GPUStat():
|
|||||||
if user not in users_process:
|
if user not in users_process:
|
||||||
users_process[user] = []
|
users_process[user] = []
|
||||||
users_process[user].append(pid)
|
users_process[user].append(pid)
|
||||||
process_info = ','.join(process_fmt.format(user=user, pids = '|'.join(users_process[user])) for user in users_process)
|
delemeter = ','
|
||||||
|
if vertical:
|
||||||
|
delemeter = '\n'
|
||||||
|
process_info = delemeter.join(process_fmt.format(user=user, pids = '|'.join(users_process[user])) for user in users_process)
|
||||||
info_gpu = {
|
info_gpu = {
|
||||||
'ID': '{0}'.format(str(gpu['id'])),
|
'ID': '{0}'.format(str(gpu['id'])),
|
||||||
'Fan': '{0} %'.format(gpu['fan_speed'].split(' ')[0].strip()),
|
'Fan': '{0} %'.format(gpu['fan_speed'].split(' ')[0].strip()),
|
||||||
@ -359,23 +363,26 @@ class GPUStat():
|
|||||||
for info in gpu_infos:
|
for info in gpu_infos:
|
||||||
this_row = [info[key] for key in enabled_cols]
|
this_row = [info[key] for key in enabled_cols]
|
||||||
info_table.append(this_row)
|
info_table.append(this_row)
|
||||||
info = draw_table(info_table, rowsty='|c|{0}|'.format('c'*(len(info_table)-1)), colsty=colsty, colsz=colsz)
|
info = draw_table(info_table, rowsty='|c|{0}|'.format('c'*(len(info_table)-1)), colsty=colsty, colsz=colsz) + '\n'
|
||||||
if show_command:
|
if show_command:
|
||||||
procs = {}
|
procs = {}
|
||||||
for gpu in self.gpus:
|
for gpu in self.gpus:
|
||||||
for proc in gpu['processes']:
|
for proc in gpu['processes']:
|
||||||
pid = proc['pid']
|
pid = proc['pid']
|
||||||
proc['gpu'] = [str(gpu['id'])]
|
proc['gpu'] = [str(gpu['id'])]
|
||||||
|
if type(proc['vmem']) is str:
|
||||||
|
proc['vmem'] = int(proc['vmem'].split(' ')[0])
|
||||||
if pid not in procs:
|
if pid not in procs:
|
||||||
procs[pid] = proc
|
procs[pid] = proc
|
||||||
else:
|
else:
|
||||||
procs[pid]['gpu'].append(str(gpu['id']))
|
procs[pid]['gpu'].append(str(gpu['id']))
|
||||||
|
procs[pid]['vmem'] += proc['vmem']
|
||||||
proc_fmt = '[{pid}|{gpus}] {user}({vmem} MiB) {cmd}'
|
proc_fmt = '[{pid}|{gpus}] {user}({vmem} MiB) {cmd}'
|
||||||
proc_strs = []
|
proc_strs = []
|
||||||
for pid in procs:
|
for pid in procs:
|
||||||
this_proc_str = proc_fmt.format(
|
this_proc_str = proc_fmt.format(
|
||||||
user = procs[pid]['user'],
|
user = procs[pid]['user'],
|
||||||
vmem = procs[pid]['vmem'].split(' ')[0],
|
vmem = procs[pid]['vmem'],
|
||||||
pid = procs[pid]['pid'].rjust(5),
|
pid = procs[pid]['pid'].rjust(5),
|
||||||
cmd = procs[pid]['command'],
|
cmd = procs[pid]['command'],
|
||||||
gpus = ','.join(procs[pid]['gpu'])
|
gpus = ','.join(procs[pid]['gpu'])
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user