|
| 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 | + |
0 commit comments