1 /* Copyright 2021 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 16 #include "tensorflow/compiler/xla/pjrt/metrics.h" 17 18 #include "absl/strings/str_cat.h" 19 #include "tensorflow/core/lib/monitoring/counter.h" 20 21 namespace xla { 22 namespace { 23 24 auto* pjrt_executable_executions = tensorflow::monitoring::Counter<0>::New( 25 "/jax/pjrt/pjrt_executable_executions", 26 "The number of PjRtExecutable::ExecuteHelper calls."); 27 28 auto* pjrt_executable_execution_time_usecs = 29 tensorflow::monitoring::Counter<0>::New( 30 "/jax/pjrt/pjrt_executable_execution_time_usecs", 31 "The total time spent on PjRtExecutable::ExecuteHelper in " 32 "microseconds."); 33 34 } // namespace 35 ReportExecutableEnqueueTime(const uint64_t running_time_usecs)36void ReportExecutableEnqueueTime(const uint64_t running_time_usecs) { 37 if (running_time_usecs > 0) { 38 static auto* pjrt_executable_executions_cell = 39 pjrt_executable_executions->GetCell(); 40 static auto* pjrt_executable_execution_time_usecs_cell = 41 pjrt_executable_execution_time_usecs->GetCell(); 42 pjrt_executable_executions_cell->IncrementBy(1); 43 pjrt_executable_execution_time_usecs_cell->IncrementBy(running_time_usecs); 44 } 45 } 46 47 } // namespace xla 48