Generates pprof profiles. Returns: Dictionary mapping from device name to proto in `profile_pb2.Profile` format.
(self)
| 272 | self._locations = Locations(self._functions) |
| 273 | |
| 274 | def profile(self): |
| 275 | """Generates pprof profiles. |
| 276 | |
| 277 | Returns: |
| 278 | Dictionary mapping from device name to proto in `profile_pb2.Profile` |
| 279 | format. |
| 280 | """ |
| 281 | profiles = {} |
| 282 | data_generator_func = self._get_profile_data_generator() |
| 283 | for device_index, device_stats in enumerate( |
| 284 | self._run_metadata.step_stats.dev_stats): |
| 285 | # Create profile |
| 286 | pprof_proto = self._get_pprof_proto(data_generator_func(device_stats)) |
| 287 | if not pprof_proto.sample: |
| 288 | print( |
| 289 | 'Not enough data to create profile for device %s. Did you pass ' |
| 290 | 'RunMetadata to session.run call?' % device_stats.device) |
| 291 | continue |
| 292 | # Add device name comment |
| 293 | device_count = len(self._run_metadata.step_stats.dev_stats) |
| 294 | device_description = ( |
| 295 | 'Device %d of %d: %s' % |
| 296 | (device_index + 1, device_count, device_stats.device)) |
| 297 | device_description_str_index = self._string_table.next_index() |
| 298 | pprof_proto.string_table.append(device_description) |
| 299 | pprof_proto.comment.append(device_description_str_index) |
| 300 | profiles[device_stats.device] = pprof_proto |
| 301 | return profiles |
| 302 | |
| 303 | def _get_pprof_proto(self, profile_datum_generator): |
| 304 | """Returns profile data in pprof proto format. |