Add test for op_metrics_db_utils IdleTimeRatio
PiperOrigin-RevId: 316997793 Change-Id: I0b89e697d661b2ea1fb95e7a6d51800b407617d0
This commit is contained in:
parent
1f05cc5973
commit
2a6d9a1e81
@ -77,6 +77,17 @@ cc_library(
|
||||
],
|
||||
)
|
||||
|
||||
tf_cc_test(
|
||||
name = "op_metrics_db_utils_test",
|
||||
srcs = ["op_metrics_db_utils_test.cc"],
|
||||
deps = [
|
||||
":op_metrics_db_utils",
|
||||
"//tensorflow/core:test",
|
||||
"//tensorflow/core:test_main",
|
||||
"//tensorflow/core/profiler/protobuf:op_metrics_proto_cc",
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "op_utils",
|
||||
srcs = ["op_utils.cc"],
|
||||
|
46
tensorflow/core/profiler/utils/op_metrics_db_utils_test.cc
Normal file
46
tensorflow/core/profiler/utils/op_metrics_db_utils_test.cc
Normal file
@ -0,0 +1,46 @@
|
||||
/* Copyright 2020 The TensorFlow Authors. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==============================================================================*/
|
||||
|
||||
#include "tensorflow/core/profiler/utils/op_metrics_db_utils.h"
|
||||
|
||||
#include "tensorflow/core/platform/test.h"
|
||||
#include "tensorflow/core/profiler/protobuf/op_metrics.pb.h"
|
||||
|
||||
namespace tensorflow {
|
||||
namespace profiler {
|
||||
namespace {
|
||||
|
||||
constexpr double kMaxError = 1E-10;
|
||||
|
||||
TEST(OpMetricsDbTest, IdleTimeRatio) {
|
||||
OpMetricsDb metrics_db_0;
|
||||
metrics_db_0.set_total_time_ps(100000000);
|
||||
metrics_db_0.set_total_op_time_ps(60000000);
|
||||
EXPECT_NEAR(0.4, IdleTimeRatio(metrics_db_0), kMaxError);
|
||||
|
||||
OpMetricsDb metrics_db_1;
|
||||
metrics_db_1.set_total_time_ps(200000000);
|
||||
metrics_db_1.set_total_op_time_ps(150000000);
|
||||
EXPECT_NEAR(0.25, IdleTimeRatio(metrics_db_1), kMaxError);
|
||||
|
||||
OpMetricsDb metrics_db_2;
|
||||
metrics_db_1.set_total_time_ps(0);
|
||||
metrics_db_1.set_total_op_time_ps(0);
|
||||
EXPECT_NEAR(1.0, IdleTimeRatio(metrics_db_2), kMaxError);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace profiler
|
||||
} // namespace tensorflow
|
Loading…
Reference in New Issue
Block a user