-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddmevent.py
More file actions
163 lines (144 loc) · 6.46 KB
/
addmevent.py
File metadata and controls
163 lines (144 loc) · 6.46 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
"import requeired packages and class"
import urllib.request as urllib2
import matplotlib.pyplot as plt
from bs4 import BeautifulSoup
import pandas as pd
import xlsxwriter
from openpyxl.reader.excel import load_workbook
from openpyxl.utils.dataframe import dataframe_to_rows
import openpyxl
"This class to extract ADDM and Foreground wait event data and visualize it and store it in excel"
class AddmEvent:
addmDF = pd.DataFrame()
Foredf = pd.DataFrame()
lenCols=0
def __init__ (self):
"Constructor"
def drawTosheet(sheetName,pos, png):
book = load_workbook('output.xlsx')
newSheet=book.create_sheet(sheetName)
if AddmEvent.lenCols != 0:
newSheet.append(["ADDM DataFrame"])
for r in dataframe_to_rows(AddmEvent.addmDF, index=False,header=True):
newSheet.append(r)
else:
newSheet.append(["No ADDM DataFrame Found for this AWR report"])
newSheet.append(["Top 10 Foreground Events by Total Wait Time"])
for r in dataframe_to_rows(AddmEvent.Foredf, index=False,header=True):
newSheet.append(r)
count=0
for fig in png:
for val in range(count,len(pos)):
position=pos[val]
count=count+1
newSheet.add_image( openpyxl.drawing.image.Image(fig),position)
break
book.save("output.xlsx")
def Addm(self,soup):
print ("\nExtracting ADDM and Foreground wait event details\n")
cols = []
rows=[]
addmTable = soup.find('table', summary='This table displays top ADDM findings by average active sessions')
if addmTable is None:
AddmEvent.lenCols=0
else:
for row in addmTable.find_all("tr"):
cells = row.find_all('th')
for val in cells:
cols.append (val.find(text = True))
AddmEvent.lenCols = int (len(cols))
count=0
for row in addmTable.find_all("tr"):
if count < 7:
cells = row.find_all('td')
for val in cells:
rows.append (val.find(text=True))
count=count+1
x = [0, 6, 12, 18, 24]
y = [6, 12, 18,24, 30]
AddmEvent.addmDF = pd.DataFrame(cols)
length=len(rows)
count=1
lengthRows = int(length/6)
for i, j in zip(x, y):
AddmEvent.addmDF[count] = rows[i:j]
count = count+1
if lengthRows < count:
break
AddmEvent.addmDF = AddmEvent.addmDF.transpose()
AddmEvent.addmDF.columns=cols
AddmEvent.addmDF = AddmEvent.addmDF.iloc[1:]
AddmEvent.addmDF = AddmEvent.addmDF.sort_values('Percent active sessions of finding',ascending =False)
plt.figure(figsize=(5, 3))
plt.bar(AddmEvent.addmDF['Finding Name'],AddmEvent.addmDF['Percent active sessions of finding'])
plt.title('ADDM Report Summary', size=15)
plt.xlabel('Events', size=5)
plt.ylabel('Percent active sessions', size=5)
plt.xticks(rotation= 10,size=5)
plt.yticks(size=5)
plt.savefig('addmbar.png')
plt.figure(figsize=(7, 4))
plt.title('ADDM Report Summary')
colors = ['r', 'g','b','c','m']
plt.pie(AddmEvent.addmDF['Percent active sessions of finding'], labels=AddmEvent.addmDF['Finding Name'], colors=colors, autopct='%.1f%%',shadow=True, startangle=90)
plt.savefig('addmpie.png')
"Call foreground wait event function"
ForeTable = soup.find('table', summary='This table displays top 10 wait events by total wait time')
AddmEvent.foreevent(ForeTable)
"Call Image to Excel function"
if AddmEvent.lenCols != 0:
AddmEvent.drawTosheet('ADDM_ForeWait',["I1","K5","M10"],["addmpie.png","addmbar.png","fore.png"])
else:
AddmEvent.drawTosheet('ADDM_ForeWait',["I1"],["fore.png"])
def foreevent(table):
cols = []
for row in table.find_all("tr"):
cells = row.find_all('th')
for val in cells:
cols.append (val.find(text = True))
A=[]
B=[]
C=[]
D=[]
E=[]
F=[]
for row in table.findAll("tr"):
count=0
cells = row.find_all('td')
for val in cells:
if count == 0:
A.append (val.find(text=True))
elif count == 1:
B.append (val.find(text=True))
elif count == 2:
C.append (val.find(text=True))
elif count == 3:
D.append (val.find(text=True))
elif count == 4:
E.append (val.find(text=True))
elif count == 5:
F.append (val.find(text=True))
count= count+1
AddmEvent.Foredf['Event']=A
AddmEvent.Foredf['Waits']=B
AddmEvent.Foredf['Total Wait Time (sec)']=C
AddmEvent.Foredf['Avg Wait']=D
AddmEvent.Foredf['% DB time']=E
AddmEvent.Foredf['Wait Class']=F
AddmEvent.Foredf.rename (columns = lambda x: x.strip().replace(' ','_'),inplace= True)
AddmEvent.Foredf.rename (columns = lambda x: x.replace('__','_'),inplace= True)
AddmEvent.Foredf.rename (columns = lambda x: x.replace('__','_'),inplace= True)
AddmEvent.Foredf['Total_Wait_Time_(sec)'] = AddmEvent.Foredf['Total_Wait_Time_(sec)'].apply(lambda x: (float(x.replace('K', '')) * 1000) if x.find('K') != -1 else (x))
AddmEvent.Foredf['%_DB_time'] = AddmEvent.Foredf['%_DB_time'].astype('float')
AddmEvent.Foredf['Total_Wait_Time_(sec)'] = AddmEvent.Foredf['Total_Wait_Time_(sec)'].astype('float')
AddmEvent.Foredf = AddmEvent.Foredf.sort_values('Total_Wait_Time_(sec)',ascending=False)
plt.figure(figsize=(5, 3))
plt.plot(AddmEvent.Foredf['Event'],AddmEvent.Foredf['Total_Wait_Time_(sec)'])
plt.plot(AddmEvent.Foredf['Event'],AddmEvent.Foredf['%_DB_time'])
plt.legend(['Total Wait Time(Sec)','DB time in %'], prop={'size': 8})
plt.title('Top 10 Foreground Events', size=15)
plt.xlabel('Events', size=5)
plt.ylabel('Percent of DB Time and Wait event (sec)', size=5)
plt.xticks(rotation= 10,size=5)
plt.yticks(size=5)
plt.savefig('fore.png')