Commit cae10365 authored by Julius Metz's avatar Julius Metz

Initial commit

parents
venv
__pycache__
\ No newline at end of file
import plotly.io as pio
def cpu_plot(values, title=None):
plot = {
'data': [],
'layout': {
'showlegend': False,
'title': {
'text': title
},
},
}
for cmd, cmd_data in values.items():
plot['data'].append(
{
'type': 'scatter',
'mode': 'markers',
'x': cmd_data.get('Time', []),
'y': cmd_data.get('CPU', []),
'name': cmd,
}
)
pio.show(plot)
\ No newline at end of file
import subprocess
from pathlib import Path
import time
import click
import plots_generators
CONFIG = {
'cpu_plot':{
'title': 'CPU load',
}
}
def parse_file(path, collectl):
process = subprocess.run([collectl, '-P', '-p', path, '-sZ'], capture_output=True)
output = process.stdout.decode().splitlines()
head = output.pop(0).split(' ')
head[0] = head[0][1:]
entrys_data = {}
for entry in output:
splited_entry = entry.split(' ', len(head))
cmd = splited_entry[-1]
if not cmd in entrys_data:
entrys_data[cmd] = {head_elem : [] for head_elem in head[:-1]}
for i, head_elem in enumerate(head[:-1]):
entrys_data[cmd][head_elem].append(splited_entry[i])
return entrys_data
@click.command()
@click.option('--file', '-f', required=True)
@click.option('--collectl', '-c', required=False, default='collectl')
def main(file, collectl):
path = Path(file)
if path.exists():
data = parse_file(path, collectl)
for generator, settings in CONFIG.items():
getattr(plots_generators, generator)(data, **settings)
if __name__ == '__main__':
main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment