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) {
34     return;
35   }
36   num_requests_ += 1;
37   rtt_sum_ += elapsed_time;
38   maximum_rtt_ = std::max(maximum_rtt_, elapsed_time);
39   return;
40 }
41 
UploadTranscodeRttStatics()42 void MmcRttLogger::UploadTranscodeRttStatics() {
43   if (num_requests_ == 0) {
44     return;
45   }
46   log_mmc_transcode_rtt_stats(maximum_rtt_, rtt_sum_ / num_requests_, num_requests_, codec_type_);
47   num_requests_ = 0;
48   rtt_sum_ = 0;
49   maximum_rtt_ = 0;
50   return;
51 }
52 
53 }  // namespace mmc
54