MCPcopy
hub / github.com/nvdv/vprof / profile_function

Method profile_function

vprof/code_heatmap.py:219–245  ·  view source on GitHub ↗

Calculates heatmap for a function.

(self)

Source from the content-addressed store, hash-verified

217 return base_profiler.run_in_separate_process(self._profile_module)
218
219 def profile_function(self):
220 """Calculates heatmap for a function."""
221 with _CodeHeatmapCalculator() as prof:
222 result = self._run_object(*self._run_args, **self._run_kwargs)
223 code_lines, start_line = inspect.getsourcelines(self._run_object)
224
225 source_lines = []
226 for line in code_lines:
227 source_lines.append(('line', start_line, line))
228 start_line += 1
229
230 filename = os.path.abspath(inspect.getsourcefile(self._run_object))
231 heatmap = prof.heatmap[filename]
232 run_time = sum(time for time in heatmap.values())
233 return {
234 'objectName': self._object_name,
235 'runTime': run_time,
236 'result': result,
237 'timestamp': int(time.time()),
238 'heatmaps': [{
239 'name': self._object_name,
240 'heatmap': heatmap,
241 'executionCount': prof.execution_count[filename],
242 'srcCode': source_lines,
243 'runTime': run_time
244 }]
245 }

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected