-
Notifications
You must be signed in to change notification settings - Fork 1
/
chart.py
105 lines (88 loc) · 3.05 KB
/
chart.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env python3
import argparse
import logging
import psutil
from datetime import datetime
import pandas as pd
import time
import os
import plotly.express as px
import plotly.graph_objects as go
import plotly.offline as py
import scenarios.common
import logging.config
chartlabels = {
'mpc': 'Measuring Point',
'cpu': 'CPU Usage in %',
'disk_io': 'Disk I/O in MB',
'mem': 'Memory Usage in MB',
'name': 'Log Processor',
'subset': 'Sub Scenario'
}
def createcharts(csvfile, desc=None, export_to_disk=False):
logging.info('create the chart :')
logging.info(f'csvfile: {csvfile}:')
logging.info(f'desc name:{desc.get_name} subtitle:{desc.get_subtitle} - prefis:{desc.get_file_prefix}')
logging.info(f'export to disk :{export_to_disk}')
if(not os.path.exists(csvfile) ):
logging.error(f'File not found: {csvfile}')
return
try:
figs = []
# read the data
df = pd.read_csv(csvfile, sep=';')
# plotly does not support a subtitle but html is a workaround
title = desc.get_name()
subtitle = desc.get_subtitle()
prefix = desc.get_file_prefix()
if(prefix is None):
prefix = ''
else:
prefix = prefix + '_'
if( not subtitle is None ):
title += '<br><sup>' + subtitle + '</sup>'
metric_unit = desc.get_metric_unit()
if(metric_unit is None):
# cpu
fig = px.line(df, x='mpc', y='cpu', color = 'name',
title='CPU Usage: ' + title,
labels=chartlabels
)
figs.append(fig)
if( export_to_disk ):
fig.write_image(os.path.join(os.path.dirname(csvfile) , prefix+'cpu.png'))
# disk
fig = px.line(df, x='mpc', y='disk_io', color = 'name',
title='Disk I/O: ' + title,
labels=chartlabels
)
figs.append(fig)
if( export_to_disk ):
fig.write_image(os.path.join(os.path.dirname(csvfile) , prefix+'disk.png'))
# memory
fig = px.line(df, x='mpc', y='mem', color = 'name',
title='Memory Usage: ' + title,
labels=chartlabels
)
figs.append(fig)
if( export_to_disk ):
fig.write_image(os.path.join(os.path.dirname(csvfile),prefix+'memory.png'))
else:
# metric output
chartlabels['metric'] = metric_unit
fig = px.bar(df, x='subset', y='metric', color = 'name',
title=title,
labels=chartlabels,
barmode="group"
)
figs.append(fig)
if('input' in csvfile):
prefix = 'input_'
else:
prefix = 'output_'
if( export_to_disk ):
fig.write_image(os.path.join(os.path.dirname(csvfile) , prefix+'metric.png'))
return figs
except KeyboardInterrupt: # pragma: no cover
logging.error(KeyboardInterrupt)
pass