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

Method parse

recipes/Python/578138_gprof2dotpy/recipe-578138.py:1677–1728  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1675 self.samples = {}
1676
1677 def parse(self):
1678 # read lookahead
1679 self.readline()
1680
1681 while not self.lookahead().startswith('------'): self.consume()
1682 while not self.lookahead().startswith('TRACE '): self.consume()
1683
1684 self.parse_traces()
1685
1686 while not self.lookahead().startswith('CPU'):
1687 self.consume()
1688
1689 self.parse_samples()
1690
1691 # populate the profile
1692 profile = Profile()
1693 profile[SAMPLES] = 0
1694
1695 functions = {}
1696
1697 # build up callgraph
1698 for id, trace in self.traces.items():
1699 if not id in self.samples: continue
1700 mtime = self.samples[id][0]
1701 last = None
1702
1703 for func, file, line in trace:
1704 if not func in functions:
1705 function = Function(func, func)
1706 function[SAMPLES] = 0
1707 profile.add_function(function)
1708 functions[func] = function
1709
1710 function = functions[func]
1711 # allocate time to the deepest method in the trace
1712 if not last:
1713 function[SAMPLES] += mtime
1714 profile[SAMPLES] += mtime
1715 else:
1716 c = function.get_call(last)
1717 c[SAMPLES2] += mtime
1718
1719 last = func
1720
1721 # compute derived data
1722 profile.validate()
1723 profile.find_cycles()
1724 profile.ratio(TIME_RATIO, SAMPLES)
1725 profile.call_ratios(SAMPLES2)
1726 profile.integrate(TOTAL_TIME_RATIO, TIME_RATIO)
1727
1728 return profile
1729
1730 def parse_traces(self):
1731 while self.lookahead().startswith('TRACE '):

Callers

nothing calls this directly

Calls 15

parse_tracesMethod · 0.95
parse_samplesMethod · 0.95
add_functionMethod · 0.95
get_callMethod · 0.95
validateMethod · 0.95
find_cyclesMethod · 0.95
ratioMethod · 0.95
call_ratiosMethod · 0.95
integrateMethod · 0.95
startswithMethod · 0.80
lookaheadMethod · 0.80
ProfileClass · 0.70

Tested by

no test coverage detected