Overwrites the session.run().
(self,
fetches,
feed_dict=None,
options=None,
run_metadata=None)
| 43 | |
| 44 | |
| 45 | def _profiled_run(self, |
| 46 | fetches, |
| 47 | feed_dict=None, |
| 48 | options=None, |
| 49 | run_metadata=None): |
| 50 | """Overwrites the session.run().""" |
| 51 | # pylint: disable=protected-access |
| 52 | # Count the session steps. |
| 53 | with self.profile_context._new_step() as state: |
| 54 | step, locked = state |
| 55 | # Fast path if no need for profiling. |
| 56 | if locked and not self.profile_context._is_fast_path(step): |
| 57 | # Maybe trace this step. |
| 58 | if self.profile_context._should_trace(step, self.graph, fetches): |
| 59 | if self.profile_context._debug: |
| 60 | sys.stderr.write('debug: tracing step: %d\n' % step) |
| 61 | # Enable tracing, perform auto profiling or auto dump. |
| 62 | if not run_metadata: |
| 63 | run_metadata = config_pb2.RunMetadata() |
| 64 | |
| 65 | if not options: |
| 66 | options = config_pb2.RunOptions( |
| 67 | trace_level=config_pb2.RunOptions.FULL_TRACE) |
| 68 | old_trace_level = options.trace_level |
| 69 | else: |
| 70 | old_trace_level = options.trace_level |
| 71 | options.trace_level = config_pb2.RunOptions.FULL_TRACE |
| 72 | |
| 73 | ret = self._profiler_run_internal( |
| 74 | fetches, feed_dict, options, run_metadata) |
| 75 | if self.profile_context._debug: |
| 76 | self.profile_context._dump_file(run_metadata, 'run_meta_%d' % step) |
| 77 | |
| 78 | self.profile_context.profiler._graph = self.graph |
| 79 | self.profile_context.profiler.add_step(step, run_metadata) |
| 80 | options.trace_level = old_trace_level |
| 81 | else: |
| 82 | ret = self._profiler_run_internal(fetches, feed_dict, options) |
| 83 | |
| 84 | # Maybe dump profile. |
| 85 | self.profile_context._maybe_dump(step) |
| 86 | |
| 87 | # Maybe profile: |
| 88 | to_profiles = self.profile_context._profile_candidates() |
| 89 | for to_prof in to_profiles: |
| 90 | cmd, opts, _ = to_prof |
| 91 | saved_views = self.profile_context._views.setdefault(cmd, {}) |
| 92 | if self.profile_context._debug: |
| 93 | sys.stderr.write('debug: profiling %s step: %d\n' % (cmd, step)) |
| 94 | if cmd == 'graph': |
| 95 | saved_views[step] = self.profile_context.profiler.profile_graph(opts) |
| 96 | elif cmd == 'scope': |
| 97 | saved_views[step] = self.profile_context.profiler.profile_name_scope( |
| 98 | opts) |
| 99 | elif cmd == 'op': |
| 100 | saved_views[step] = self.profile_context.profiler.profile_operations( |
| 101 | opts) |
| 102 | elif cmd == 'code': |
nothing calls this directly
no test coverage detected