Skip to content

Commit 11a4569

Browse files
author
suiy
committed
add graph.py & parser.py
1 parent bd9ec99 commit 11a4569

File tree

6 files changed

+147
-3
lines changed

6 files changed

+147
-3
lines changed

etc/clouds.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ cloud_port = 8444
44
image_id = automaton.gz
55
cloud_type = nimbus
66
availability_zone = us-east-1
7-
instance_type = m1.xlarge
7+
instance_type = m1.large
88
instance_cores = 1
99
access_id = $NIMBUS_IAAS_ACCESS_KEY
1010
secret_key = $NIMBUS_IAAS_SECRET_KEY

etc/global.conf

-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ log_local_path = ./var/log_files
88
ssh_username = root
99
ssh_timeout = 120
1010
graph_path = ./var/graphs
11-
instance_types = m1.small,m1.large,m1.xlarge

graphing/graphing.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import pylab as plt
2+
from parser import Parser
3+
from lib.util import read_path
4+
5+
class Graph(object):
6+
def __init__(self,config):
7+
self.config = config
8+
self.parser = Parser(self.config)
9+
self.graph_path = self.config.globals.graph_path
10+
self.attributes = list()
11+
self.attributes = self.parser.instance_types
12+
13+
def generate_graph(self):
14+
raw_data = self.parser.get_mean()
15+
for item in raw_data:
16+
data=list()
17+
for n in range(len(self.attributes)):
18+
data.append(item[n+1])
19+
figure_name = '%s/%s.png' % (self.graph_path,item[0])
20+
figure = bar_graph(item[0],self.attributes,data,figure_name)
21+
22+
23+
def bar_graph(title,x_value,y_value,path):
24+
fig = plt.figure()
25+
ax = fig.add_subplot(1,1,1)
26+
x = range(len(y_value))
27+
28+
rects = ax.bar(x, y_value, facecolor='#777777', edgecolor='black',align='center',yerr=0.1,width=0.5)
29+
ax.set_title(title)
30+
ax.set_xticks(x)
31+
ax.set_xticklabels(x_value)
32+
for rect in rects:
33+
height = rect.get_height()
34+
plt.text(rect.get_x()+rect.get_width()/4, 1.01*height, '%s' % float(height))
35+
#plt.show()
36+
fig.savefig(path)
37+
38+

graphing/parser.py

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import os
2+
import sys
3+
import random
4+
from lib.util import read_path
5+
6+
class Tree(object):
7+
def __init__(self):
8+
self.name = None
9+
self.attributes = list()
10+
11+
class Parser(object):
12+
def __init__(self,config):
13+
self.data = list()
14+
self.config = config
15+
self.local_path = self.config.globals.log_local_path
16+
self.instance_types = list()
17+
type_list(self.local_path,self.instance_types)
18+
19+
20+
def read_dir(self,root_dir):
21+
for line in os.listdir(root_dir):
22+
path = os.path.join(root_dir, line)
23+
if os.path.isdir(path):
24+
self.read_dir(path)
25+
elif os.path.basename(path)=='.DS_Store':
26+
continue
27+
else:
28+
inputs = self.insert_data(path)
29+
30+
def insert_data(self,path):
31+
filelist=list()
32+
pathlist=list()
33+
#read_file(path)
34+
pathlist = splitpath(path, 20)
35+
filename = os.path.basename(path)
36+
filelist = filename.split('_')
37+
if len(self.data) != 0:
38+
for item in self.data:
39+
if item.name==pathlist[3]:
40+
for n in range(len(self.instance_types)):
41+
if filelist[2]==self.instance_types[n]:
42+
item.attributes[n].append(read_file(path))
43+
return
44+
else:
45+
continue
46+
tree = Tree()
47+
for n in range(len(self.instance_types)):
48+
tree.attributes.append(list())
49+
if filelist[2]==self.instance_types[n]:
50+
tree.attributes[n].append(read_file(path))
51+
tree.name = pathlist[3]
52+
self.data.append(tree)
53+
54+
def get_mean(self):
55+
self.read_dir(self.local_path)
56+
li = list()
57+
for item in self.data:
58+
l = list()
59+
l.append(item.name)
60+
for attribute in item.attributes:
61+
s = 0
62+
if len(attribute)==0:
63+
s=0
64+
else:
65+
for n in attribute:
66+
s+=n
67+
s = s/float(len(attribute))
68+
l.append(s)
69+
li.append(l)
70+
return li
71+
72+
def print_tree(self):
73+
for item in self.data:
74+
print item.name
75+
for n in self.attributes:
76+
print n
77+
78+
def splitpath(path, maxdepth=20):
79+
( head, tail ) = os.path.split(path)
80+
return splitpath(head, maxdepth - 1) + [ tail ] \
81+
if maxdepth and head and head != path \
82+
else [ head or tail ]
83+
84+
def read_file(filename):
85+
lnlist = list()
86+
with open(filename, 'r') as handle:
87+
for ln in handle:
88+
if 'Total time for running BioPerf is' in ln:
89+
lnlist=ln.split(' ')
90+
return int(lnlist[6])
91+
return 0
92+
93+
def type_list(root_dir,instance_type):
94+
for line in os.listdir(root_dir):
95+
path = os.path.join(root_dir, line)
96+
if os.path.isdir(path):
97+
type_list(path,instance_type)
98+
elif os.path.basename(path)=='.DS_Store':
99+
continue
100+
else:
101+
filelist=list()
102+
filename = os.path.basename(path)
103+
filelist = filename.split('_')
104+
if filelist[2] in instance_type:
105+
continue
106+
else:
107+
instance_type.append(filelist[2])
108+

lib/config.py

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ def __init__(self, config):
1414
self.ssh_username = default_dict['ssh_username']
1515
self.ssh_timeout = default_dict['ssh_timeout']
1616
self.graph_path = default_dict['graph_path']
17-
self.instance_types = default_dict['instance_types']
1817

1918
class CloudsConfig(object):
2019
""" CloudsConfig class retrieves information from the file that specifies global parameters """

self.db

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)