MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / profile

Function profile

tensorflow/python/profiler/pprof_profiler.py:405–445  ·  view source on GitHub ↗

Generate profiles in pprof format. See https://github.com/google/pprof/blob/master/proto/profile.proto for pprof proto format. Args: graph: A `Graph` object. run_metadata: A `RunMetadata` proto. output_dir: (string) Directory to output pprof profile to. Profile files for ea

(graph, run_metadata, output_dir=None)

Source from the content-addressed store, hash-verified

403
404
405def profile(graph, run_metadata, output_dir=None):
406 """Generate profiles in pprof format.
407
408 See https://github.com/google/pprof/blob/master/proto/profile.proto
409 for pprof proto format.
410
411 Args:
412 graph: A `Graph` object.
413 run_metadata: A `RunMetadata` proto.
414 output_dir: (string) Directory to output pprof profile to.
415 Profile files for each device will be stored in compressed
416 serialized proto format. If output_dir is None, profile protos
417 will be printed to stdout instead.
418
419 Returns:
420 List of output files created by this profile call.
421 (Note: this list will be empty if output_dir is None)
422 """
423 profiles = get_profiles(graph, run_metadata)
424 output_file_template = None
425 if output_dir:
426 if not os.path.isdir(output_dir):
427 os.makedirs(output_dir)
428 time_suffix = time.strftime('%Y%m%d%H%M%S')
429 output_file_template = os.path.join(
430 output_dir, '%s_' + time_suffix + '.pb.gz')
431
432 profile_files = []
433 for device, pprof_proto in profiles.items():
434 if output_file_template is None:
435 print('No output directory specified, printing to stdout instead.')
436 print(pprof_proto)
437 else:
438 device_name = str(device).strip('/').translate(
439 maketrans('/:', '__'))
440 profile_file = output_file_template % device_name
441 profile_files.append(profile_file)
442 with gzip.open(profile_file, 'w') as output_file:
443 print('Writing profile to %s...' % profile_file)
444 output_file.write(pprof_proto.SerializeToString())
445 return profile_files

Callers

nothing calls this directly

Calls 6

get_profilesFunction · 0.85
stripMethod · 0.80
joinMethod · 0.45
appendMethod · 0.45
writeMethod · 0.45
SerializeToStringMethod · 0.45

Tested by

no test coverage detected