MCPcopy Create free account
hub / github.com/ActiveState/code / Function

Class Function

recipes/Python/578138_gprof2dotpy/recipe-578138.py:176–233  ·  view source on GitHub ↗

A function.

Source from the content-addressed store, hash-verified

174
175
176class Function(Object):
177 """A function."""
178
179 def __init__(self, id, name):
180 Object.__init__(self)
181 self.id = id
182 self.name = name
183 self.module = None
184 self.process = None
185 self.calls = {}
186 self.called = None
187 self.weight = None
188 self.cycle = None
189
190 def add_call(self, call):
191 if call.callee_id in self.calls:
192 sys.stderr.write('warning: overwriting call from function %s to %s\n' % (str(self.id), str(call.callee_id)))
193 self.calls[call.callee_id] = call
194
195 def get_call(self, callee_id):
196 if not callee_id in self.calls:
197 call = Call(callee_id)
198 call[SAMPLES] = 0
199 call[SAMPLES2] = 0
200 call[CALLS] = 0
201 self.calls[callee_id] = call
202 return self.calls[callee_id]
203
204 _parenthesis_re = re.compile(r'\([^()]*\)')
205 _angles_re = re.compile(r'<[^<>]*>')
206 _const_re = re.compile(r'\s+const$')
207
208 def stripped_name(self):
209 """Remove extraneous information from C++ demangled function names."""
210
211 name = self.name
212
213 # Strip function parameters from name by recursively removing paired parenthesis
214 while True:
215 name, n = self._parenthesis_re.subn('', name)
216 if not n:
217 break
218
219 # Strip const qualifier
220 name = self._const_re.sub('', name)
221
222 # Strip template parameters from name by recursively removing paired angles
223 while True:
224 name, n = self._angles_re.subn('', name)
225 if not n:
226 break
227
228 return name
229
230 # TODO: write utility functions
231
232 def __repr__(self):
233 return self.name

Callers 11

parseMethod · 0.70
make_functionMethod · 0.70
parse_callMethod · 0.70
parseMethod · 0.70
parseMethod · 0.70
build_profileMethod · 0.70
parseMethod · 0.70
get_functionMethod · 0.70
parse_symbolsMethod · 0.70
build_functionMethod · 0.70
get_functionMethod · 0.70

Calls 1

compileMethod · 0.45

Tested by

no test coverage detected