Runs cProfile on a function.
(self)
| 82 | return base_profiler.run_in_separate_process(self._profile_module) |
| 83 | |
| 84 | def profile_function(self): |
| 85 | """Runs cProfile on a function.""" |
| 86 | prof = cProfile.Profile() |
| 87 | prof.enable() |
| 88 | result = self._run_object(*self._run_args, **self._run_kwargs) |
| 89 | prof.disable() |
| 90 | prof_stats = pstats.Stats(prof) |
| 91 | prof_stats.calc_callees() |
| 92 | return { |
| 93 | 'objectName': self._object_name, |
| 94 | 'callStats': self._transform_stats(prof_stats), |
| 95 | 'totalTime': prof_stats.total_tt, |
| 96 | 'primitiveCalls': prof_stats.prim_calls, |
| 97 | 'totalCalls': prof_stats.total_calls, |
| 98 | 'result': result, |
| 99 | 'timestamp': int(time.time()) |
| 100 | } |