def testTfprofFile(self): tfprof_file = os.path.join(self.get_temp_dir(), 'testTfprofFile_tfproffile') params = test_util.get_params('testTfprofFile')._replace( tfprof_file=tfprof_file) self._train_and_eval_local(params, skip='eval_and_train_from_checkpoint') self.assertGreater(os.stat(tfprof_file).st_size, 0) with open(tfprof_file, 'rb') as f: profile_proto = tfprof_log_pb2.ProfileProto() # The following statement should not raise an exception. profile_proto.ParseFromString(f.read())
def test_profile(self): profiler.start() three = constant_op.constant(3) five = constant_op.constant(5) product = three * five self.assertAllEqual(15, product) profile_result = profiler.stop() profile_pb = tfprof_log_pb2.ProfileProto() profile_pb.ParseFromString(profile_result) profile_pb_str = '%s' % profile_pb self.assertTrue('Mul' in profile_pb_str)
def testEager(self): ops.reset_default_graph() with context.eager_mode(): outfile = os.path.join(test.get_temp_dir(), 'dump') opts = builder( builder.time_and_memory()).with_file_output(outfile).build() context.enable_run_metadata() lib.BuildSmallModel() profiler = model_analyzer.Profiler() profiler.add_step(0, context.export_run_metadata()) context.disable_run_metadata() profiler.profile_operations(opts) with gfile.Open(outfile, 'r') as f: out_str = f.read() self.assertTrue('Conv2D' in out_str) self.assertTrue('VarHandleOp' in out_str) with gfile.Open('/tmp/eager_profile', 'wb') as f: profile_pb = tfprof_log_pb2.ProfileProto() profile_pb.ParseFromString(profiler.serialize_to_string()) profile_pb_str = '%s' % profile_pb self.assertTrue('Conv2D' in profile_pb_str) self.assertTrue('VarHandleOp' in profile_pb_str)