16 #ifndef TENSORFLOW_SERVING_SERVABLES_TENSORFLOW_UTIL_H_
17 #define TENSORFLOW_SERVING_SERVABLES_TENSORFLOW_UTIL_H_
19 #include "absl/types/optional.h"
20 #include "tensorflow/core/framework/tensor.h"
21 #include "tensorflow/core/lib/core/status.h"
22 #include "tensorflow/core/lib/monitoring/counter.h"
23 #include "tensorflow/core/lib/monitoring/sampler.h"
24 #include "tensorflow/core/platform/threadpool_options.h"
25 #include "tensorflow/core/public/session.h"
26 #include "tensorflow_serving/apis/input.pb.h"
27 #include "tensorflow_serving/apis/model.pb.h"
28 #include "tensorflow_serving/resources/resources.pb.h"
29 #include "tensorflow_serving/util/file_probing_env.h"
31 namespace tensorflow {
37 monitoring::Sampler<1>* GetExampleCounts();
39 monitoring::Counter<1>* GetExampleCountTotal();
44 void RecordModelRequestCount(
const string& model_name,
const Status& status);
52 void SetSignatureMethodNameCheckFeature(
bool v);
55 bool GetSignatureMethodNameCheckFeature();
59 void RecordRequestExampleCount(
const string& model_name,
size_t count);
74 Status InputToSerializedExampleTensor(
const Input& input, Tensor* examples);
78 Status PerformOneShotTensorComputation(
79 const RunOptions& run_options,
const Input& input,
80 const string& input_tensor_name,
81 const std::vector<string>& output_tensor_names, Session* session,
82 std::vector<Tensor>* outputs,
int* num_input_examples,
83 const thread::ThreadPoolOptions& thread_pool_options =
84 thread::ThreadPoolOptions(),
85 int64_t* runtime_latency =
nullptr);
89 Status PerformOneShotTensorComputation(
90 const RunOptions& run_options,
const Input& input,
91 const std::set<string>& input_tensor_names,
92 const std::vector<string>& output_tensor_names, Session* session,
93 std::vector<Tensor>* outputs,
int* num_input_examples,
94 const thread::ThreadPoolOptions& thread_pool_options =
95 thread::ThreadPoolOptions());
101 void MakeModelSpec(
const string& model_name,
102 const absl::optional<string>& signature_name,
103 const absl::optional<int64_t>& version,
104 ModelSpec* model_spec);
107 Status GetModelDiskSize(
const string& path, FileProbingEnv* env,
108 uint64_t* total_file_size);
113 Status EstimateResourceFromPathUsingDiskState(
const string& path,
115 ResourceAllocation* estimate);
118 void RecordRuntimeLatency(
const string& model_name,
const string& api,
119 const string& runtime, int64_t latency_usec);
122 void RecordRequestLatency(
const string& model_name,
const string& api,
123 const string& entrypoint, int64_t latency_usec);
126 template <
typename T>
127 std::set<string> GetMapKeys(
const T& map) {
128 std::set<string> keys;
129 for (
const auto& it : map) {
130 keys.insert(it.first);
136 std::set<string> SetDifference(std::set<string> set_a, std::set<string> set_b);
139 bool IsTfrtErrorLoggingEnabled();