serialize tensorflow::monitoring::Percentiles to xplane.

PiperOrigin-RevId: 307948962
Change-Id: Ie1599d1d2961bca57b38fd5c1656c6b62e12c72c
This commit is contained in:
A. Unique TensorFlower 2020-04-22 18:36:30 -07:00 committed by TensorFlower Gardener
parent 31bd69ec2c
commit e88882f6d5
4 changed files with 60 additions and 2 deletions
tensorflow/core/profiler

View File

@ -112,3 +112,10 @@ tf_proto_library(
cc_api_version = 2,
visibility = [":friends"],
)
tf_proto_library(
name = "tfstreamz_proto",
srcs = ["tfstreamz.proto"],
cc_api_version = 2,
visibility = [":friends"],
)

View File

@ -0,0 +1,33 @@
// This proto describes the format of the output profile file from
// the TF-stats tool.
syntax = "proto3";
package tensorflow.profiler.tfstreamz;
// A proxy proto to serialize tensorflow::monitoring::Percentiles
enum UnitOfMeasure {
NUMBER = 0;
TIME = 1;
BYTES = 2;
}
message PercentilePoint {
// In the [0, 100] range.
double percentile = 1;
double value = 2;
}
message Percentiles {
UnitOfMeasure unit_of_measure = 1;
uint64 start_nstime = 2;
uint64 end_nstime = 3;
double min_value = 4;
double max_value = 5;
double mean = 6;
double stddev = 7;
uint64 num_samples = 8;
uint64 total_samples = 9;
double accumulator = 10;
repeated PercentilePoint points = 11;
}

View File

@ -334,6 +334,7 @@ cc_library(
":xplane_builder",
"//tensorflow/core:lib",
"//tensorflow/core:lib_internal",
"//tensorflow/core/profiler/protobuf:tfstreamz_proto_cc",
"//tensorflow/core/profiler/protobuf:xplane_proto_cc",
"@com_google_absl//absl/memory",
"@com_google_absl//absl/strings",

View File

@ -26,6 +26,7 @@ limitations under the License.
#include "tensorflow/core/lib/monitoring/collected_metrics.h"
#include "tensorflow/core/lib/monitoring/collection_registry.h"
#include "tensorflow/core/platform/errors.h"
#include "tensorflow/core/profiler/protobuf/tfstreamz.pb.h"
namespace tensorflow {
namespace profiler {
@ -44,7 +45,24 @@ string ConstructXStatName(const string& name, const monitoring::Point& point) {
}
string SerializePercentile(const monitoring::Percentiles& percentiles) {
return "";
tfstreamz::Percentiles output;
output.set_unit_of_measure(
static_cast<tfstreamz::UnitOfMeasure>(percentiles.unit_of_measure));
output.set_start_nstime(percentiles.start_nstime);
output.set_end_nstime(percentiles.end_nstime);
output.set_min_value(percentiles.min_value);
output.set_max_value(percentiles.max_value);
output.set_mean(percentiles.mean);
output.set_stddev(percentiles.stddev);
output.set_num_samples(percentiles.num_samples);
output.set_total_samples(percentiles.total_samples);
output.set_accumulator(percentiles.accumulator);
for (const auto& pp : percentiles.points) {
auto* percentile_point = output.add_points();
percentile_point->set_percentile(pp.percentile);
percentile_point->set_value(pp.value);
}
return output.SerializeAsString();
}
} // namespace
@ -90,7 +108,6 @@ Status SerializeToXPlane(const std::vector<TfStreamzSnapshot>& snapshots,
/*is_bytes=*/true);
break;
case monitoring::ValueType::kPercentiles:
// TODO(jiesun): define a proto to hold monitoring::Percentiles.
xevent.AddStatValue(*metadata,
SerializePercentile(point->percentiles_value),
/*is_bytes=*/true);