51 """The routine that kicks off processing a ref file"""
52
56 object_types = {}
57 objects = {}
58 filename = options.filepath
59
60 with open(filename, 'r') as ref_file:
61 for line in ref_file:
62 if 'constructor' not in line and 'destructor' not in line:
63 continue
64
65
66
67 tokens = line.strip().split(',', 7)
68 addr = tokens[0]
69 state = tokens[6]
70 if 'constructor' in state:
71 split_state = state.split("**")
72 if len(split_state) < 4:
73 print("File does not contain object size information", file=sys.stderr)
74 sys.exit(1)
75
76 obj_type = '%s:%s:%s' % (tokens[3], tokens[4], tokens[5])
77 if obj_type not in object_types:
78 object_types[obj_type] = {
79 'used': 0,
80 'unused': 0,
81 'none': 0
82 }
83 overhead = int(split_state[2])
84 user_data = int(split_state[3])
85 obj = objects[addr] = {
86 'overhead': overhead,
87 'user_data': user_data,
88 'obj_type': obj_type
89 }
90
91 direction = 1
92 else:
93 if addr not in objects:
94
95 continue
96 obj = objects[addr]
97 del objects[addr]
98 direction = -1
99 obj_type = obj['obj_type']
100 if '**lock-state:unused**' in state:
101 object_types[obj_type]['unused'] += 1
102 elif '**lock-state:used**' in state:
103 object_types[obj_type]['used'] += 1
104
105
106 update_stats(current, peak, total,
'count', direction, 1)
107 update_stats(current, peak, total,
'overhead', direction, obj[
'overhead'])
108 update_stats(current, peak, total,
'user_data', direction, obj[
'user_data'])
109 update_stats(current, peak, total,
'totalmem', direction, obj[
'overhead'] + obj[
'user_data'])
110
111 print("Total usage statistics:")
112 print("%20s: %d" % ("Count", total['count']))
113 print("%20s: %d" % ("Total Memory (k)", total['totalmem'] / 1024))
114 print("%20s: %d (%.2f%%)" % ("Overhead (k)", total['overhead'] / 1024, total['overhead'] * 100.0 / total['totalmem']))
115 print("%20s: %d" % ("User Data (k)", total['user_data'] / 1024))
116 print("")
117 print("Peak usage statistics:")
118 print("%20s: %d" % ("Count", peak['count']))
119 print("%20s: %d" % ("Total Memory (k)", peak['totalmem'] / 1024))
120 print("%20s: %d (%.2f%%)" % ("Overhead (k)", peak['overhead'] / 1024, peak['overhead'] * 100.0 / peak['totalmem']))
121 print("%20s: %d" % ("User Data (k)", peak['user_data'] / 1024))
122 print("")
123
124 lockbyobj = {'used': 0, 'total': 0}
125 lockbytype = {'used': 0, 'total': 0}
126 for (allocator, info) in object_types.items():
127 lockbyobj['used'] += info['used']
128 lockbyobj['total'] += info['used'] + info['unused']
129
130 if info['used'] != 0:
131 lockbytype['used'] += 1
132 elif info['unused'] == 0:
133
134 continue
135 lockbytype['total'] += 1
136
137 print("Lock usage statistics:")
138 print("%20s: %d of %d used (%.2f%%)" % (
139 "By object",
140 lockbyobj['used'],
141 lockbyobj['total'],
142 lockbyobj['used'] * 100.0 / lockbyobj['total']))
143 print("%20s: %d of %d used (%.2f%%)" % (
144 "By type",
145 lockbytype['used'],
146 lockbytype['total'],
147 lockbytype['used'] * 100.0 / lockbytype['total']))
148
149
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
static int update_stats(struct spandsp_pvt *p, int completion_code)