1 /*
2  * Copyright 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "mmc/metrics/mmc_rtt_logger.h"
18 
19 #include <algorithm>
20 #include <cmath>
21 #include <string>
22 
23 #include "stack/include/stack_metrics_logging.h"
24 
25 namespace mmc {
26 
MmcRttLogger(int codec_type)27 MmcRttLogger::MmcRttLogger(int codec_type)
28     : codec_type_(codec_type), num_requests_(0), rtt_sum_(0), maximum_rtt_(0) {}
29 
~MmcRttLogger()30 MmcRttLogger::~MmcRttLogger() {}
31 
RecordRtt(int64_t elapsed_time)32 void MmcRttLogger::RecordRtt(int64_t elapsed_time) {
33   if (elapsed_time <= 0) return;
34   num_requests_ += 1;
35   rtt_sum_ += elapsed_time;
36   maximum_rtt_ = std::max(maximum_rtt_, elapsed_time);
37   return;
38 }
39 
UploadTranscodeRttStatics()40 void MmcRttLogger::UploadTranscodeRttStatics() {
41   if (num_requests_ == 0) return;
42   log_mmc_transcode_rtt_stats(maximum_rtt_, rtt_sum_ / num_requests_,
43                               num_requests_, codec_type_);
44   num_requests_ = 0;
45   rtt_sum_ = 0;
46   maximum_rtt_ = 0;
47   return;
48 }
49 
50 }  // namespace mmc
51