forked from fflooos/mobile-stats-file-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiv_class.py
133 lines (118 loc) · 4.97 KB
/
iv_class.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
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
#Class definitions
#Generic Script exception
import re
class ParserErrors(Exception):
def __init__(self, message='Generic Error during script execution'):
super(ParserErrors, self).__init__(message)
self.message = message
class ClassErrors(ReferenceError):
def __init__(self, message='Error : Not a class object'):
super(ReferenceError, self).__init__(message)
self.message = message
class ConfigParseError (Exception):
def __init__(self, message='Error : Configuration parsing'):
super(ParserErrors, self).__init__(message)
self.message = message
class CounterGroup:
def __init__(self,stat_type):
self.stat_type = stat_type
self.counterNames = []
self.instances = []
class Instance:
def __init__(self,name):
self.name = name
self.propertyList = {}
# List of list of counter ordered by timestamp ex => counterList[20150402][success]->30
self.counterList = {}
# List of instantiated proxies for this instance
self.proxyList = {}
def add_counter(self, timestamp, counters):
if (not timestamp in self.counterList ) :
#print("INFO : Timestamp ", timestamp, " already exist for object ", self.name)
self.counterList[timestamp] = {}
for counter in counters:
if (counter in self.counterList[timestamp]) :
#if ( debug ) : print("DEBUG - overwriting existing counter", counter," for instance", self.name)
match = re.search( "([0-9]+)", counters[counter])
if ( match ) :
self.counterList[timestamp][counter] = counters[counter]
#print("DEBUG - Previous ", self.counterList[timestamp][counter], "New Value ", counters[counter])
else :
self.counterList[timestamp][counter] = counters[counter]
def del_counter(self, timestamp, counter):
del self.counterList[timestamp][counter]
def add_property(self, tag, prop):
self.propertyList[tag] = prop
def del_property(self, tag):
del self.propertyList[tag]
# Add proxy instance in proxyList
def add_proxy(self, tag, proxy):
self.proxyList[tag] = proxy
def del_proxy(self, tag):
del self.proxyList[tag]
# Return proxy instance
def get_proxy(self, tag) :
try : return self.proxyList[tag]
except KeyError : print("ERROR - Failed to retrieve proxy : ", tag, "for instance : ", self.name)
def get_counter(self) :
return self.counterList
def show_property(self, prop="ALL"):
if prop == "ALL":
#print(self.name)
print("\t Property of:", self.name, " : ")
for i in self.propertyList:
print( "\t => ", i, self.propertyList.get(i) )
else :
find_counter(prop)
def show_proxy(self, proxy="ALL") :
if proxy == "ALL":
print("\t Proxy of ", self.name, " :")
for _proxy in sorted(self.proxyList.keys() ):
print( "\t=>", _proxy )
else :
if ( proxy in proxyList ) : print( self.proxyList[proxy].name)
def show_counter(self, counter="ALL") :
if counter == "ALL" :
for ts in self.counterList :
print ("Timestamp" , ts)
for k in self.counterList[ts] :
print("\t",k, "->", self.counterList[ts][k])
# Inherit from Instance class
class Proxy(Instance):
def __init__(self,name,basic):
super(Proxy, self).__init__(name)
self.basic = basic
class Wrapper():
def __init__(self, kind):
self.instanceList = {}
self.instanceCount = 0
self.kind = kind
def length(self):
return len(self.instanceList)
def add_instance(self, tag ,instance):
self.instanceList[tag] = instance
self.instanceCount += 1
def del_instance(self, tag):
del self.instanceList[tag]
self.instanceCount -= 1
def get_instance(self, tag):
return self.instanceList[tag]
def show(self, tag="ALL"):
if tag == "ALL":
for i in self.instanceList:
print(self.instanceList.get(i).name)
print(self.instanceList.get(i).show_property() )
print(self.instanceList.get(i).show_proxy())
print(self.instanceList.get(i).show_counter())
else :
if ( tag in self.instanceList ) :
print( self.instanceList[tag].show_property() )
print( self.instanceList[tag].show_proxy() )
print( self.instanceList[tag].show_counter() )
def brief(self) :
print("Total number of instance :", self.instanceCount)
self.proxyCount = 0
self.counterCount = 0
for i in self.instanceList:
self.proxyCount += len(self.instanceList.get(i).proxyList)
print("Total number of proxies : ", self.proxyCount)